Home > atmlab > randomize > randmvar_normal2.m

randmvar_normal2

PURPOSE ^

RANDMVAR_NORMAL2 Random multivariate normal distributed data

SYNOPSIS ^

function X = randmvar_normal2(x,S,n)

DESCRIPTION ^

 RANDMVAR_NORMAL2  Random multivariate normal distributed data

    As *randmvar_normal2*, but using taking a covariance matrix as input
    instead of standard deviations and correlations separately.

    Creates a set of random vectors fulfilling multivariate normal
    statistics. The statistics to fulfill is defined by giving the
    mean vector and covariance matrix.

    The mean state, *x*, can be given as a scalar if all values are identical.

 FORMAT   X = randmvar_normal2( x, Sx, n )
        
 OUT   X    Random data [length(x) x n].
 IN    x    Mean vector. 
       Sx   Covariance matrix. 
       n    Number of realisations to generate.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

DOWNLOAD ^

randmvar_normal2.m

SOURCE CODE ^

0001 % RANDMVAR_NORMAL2  Random multivariate normal distributed data
0002 %
0003 %    As *randmvar_normal2*, but using taking a covariance matrix as input
0004 %    instead of standard deviations and correlations separately.
0005 %
0006 %    Creates a set of random vectors fulfilling multivariate normal
0007 %    statistics. The statistics to fulfill is defined by giving the
0008 %    mean vector and covariance matrix.
0009 %
0010 %    The mean state, *x*, can be given as a scalar if all values are identical.
0011 %
0012 % FORMAT   X = randmvar_normal2( x, Sx, n )
0013 %
0014 % OUT   X    Random data [length(x) x n].
0015 % IN    x    Mean vector.
0016 %       Sx   Covariance matrix.
0017 %       n    Number of realisations to generate.
0018 
0019 % 2007-05-22   Created by Patrick Eriksson.
0020 
0021 
0022 function X = randmvar_normal2(x,S,n)
0023 
0024 
0025 %= Check input
0026 %
0027 rqre_nargin( 3, nargin );
0028 %
0029 if ~isvector(x) 
0030   error('Input argument *x* must be a vector.');
0031 end
0032 %
0033 if dimens(S) ~= 2  |  size(S,1) ~= size(S,2) 
0034   error('Input argument *S* must be a square matrix.');
0035 end
0036 %
0037 if ~( length(x) == 1  |  length(x) == size(S,1) )
0038   error( ...
0039   'Input argument *x* must be a scalar or a vector with length matching *S*.');
0040 end
0041 %
0042 if ~isscalar(n)  |  ~iswhole(n)  |  n<1
0043   error('Input argument *n* must be a positive integer.');
0044 end
0045 
0046 
0047 if length(x) == 1
0048   x = repmat( x, size(S,1), 1 );;
0049 end
0050 
0051 X = repmat(vec2col(x),1,n) + chol(S)'*randn(length(x),n);

Generated on Mon 15-Sep-2014 13:31:28 by m2html © 2005