Home > atmlab > demos > randmvar_demo.m

randmvar_demo

PURPOSE ^

SYNOPSIS ^

This is a script file.

DESCRIPTION ^

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

DOWNLOAD ^

randmvar_demo.m

SOURCE CODE ^

0001 echo on
0002 
0003 %- Random vectors with length 6 will be created.
0004 
0005 %- Two elements with normal distribution:
0006 Cm    = covmat1d_from_cfun( [1:2]', [], 'lin', [1 1;2 1] );
0007 [P,C] = randmvar_add_normal( [], [], [0 2], [1 0.5], Cm );
0008 
0009 %- Two elements with uniform distribution:
0010 Cm    = covmat1d_from_cfun( [1:2]', [], 'drc' );
0011 [P,C] = randmvar_add_uniform( P, C, [0 1;-1 1], Cm );
0012 
0013 %- Two elements with log-normal distribution:
0014 Cm    = covmat1d_from_cfun( [1:2]', [], 'exp', [1 0.6;2 0.4] );
0015 [P,C] = randmvar_add_lognormal( P, C, [0 1], [0.3 1], Cm );
0016 
0017 %- Introduce some cross-correlation between normal and and other elements
0018 Cr = repmat( 0.1:0.1:0.4, 2, 1 );
0019 C(1:2,3:6) = Cr;
0020 C(3:6,1:2) = Cr';
0021 
0022 
0023 %- Create 1e4 random vectors
0024 X = randmvar( P, C, 1e4 );
0025 
0026 %- Transpose X
0027 X = X';
0028 
0029 %- Check that basic statistic properties are obtained
0030 [ mean(X(:,1:2))',      std(X(:,1:2))';
0031   min(X(:,3:4))',       max(X(:,3:4))';
0032   mean(log(X(:,5:6)))', std(log(X(:,5:6)))' ]
0033 
0034 %- Input and obtained correlation matrix
0035 full(C)
0036 corrcoef(X)
0037 
0038 
0039 %- Histogram for first uniform element
0040 hist(X(:,3),100);
0041 
0042 
0043 echo off

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