Home > General-Functions > Statistics > rand_gauss.m

rand_gauss

PURPOSE ^

% random numbers following a multivariate Gaussian with

SYNOPSIS ^

function ret = rand_gauss(mu, C, n)

DESCRIPTION ^

% random numbers following a multivariate Gaussian  with
 mean vector mu and covariance matrix C, considering correlations and
 potential singularities in C

 ret = rand_gauss(mu, C, n)
 
 mu  = double dx1, mean vector of dimension d
 C   = double dxd, covariance matrix
 n   = int, number of samples to generate
 ret = double dxn, n samples of Gaussian(Mu,C)

 author: Richard Steffen

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 %% random numbers following a multivariate Gaussian  with
0002 % mean vector mu and covariance matrix C, considering correlations and
0003 % potential singularities in C
0004 %
0005 % ret = rand_gauss(mu, C, n)
0006 %
0007 % mu  = double dx1, mean vector of dimension d
0008 % C   = double dxd, covariance matrix
0009 % n   = int, number of samples to generate
0010 % ret = double dxn, n samples of Gaussian(Mu,C)
0011 %
0012 % author: Richard Steffen
0013 
0014 function ret = rand_gauss(mu, C, n)
0015     
0016 % Zerlegung in eigenvectoren und Eigenwerte
0017 [R,S] = eig(full(C));   
0018 % Eigenvektoren skalieren mit Eigenwerten
0019 A = R .* repmat(sqrt(abs(diag(S)))',length(S),1);
0020 ret = repmat(mu,1,n) + A*randn(length(mu),n);
0021

Generated on Sat 21-Jul-2018 20:56:10 by m2html © 2005