I am new to using Matlab and have a question regarding the covariance function and generating random variables. I need to estimate P(X1^2 + X2^2 + X3^2 +X4^2) > 16 by generating Normal RV with a covariance and mean matrix. Thank you
2 views (last 30 days)
Show older comments
I need to estimate the P (X1^2 + X2^2 + X3^2 + X4^2) > 16 The covariance matrix and mean for the X1, X2, X3, X4 multivariate normal random variables are listed below. The code I am attempting to complete I know is incorrect -- would very much appreciate help with the code below. Thank you --
Sigma = [4.57 3.48 -1.89 3.76;
3.48 4.25 -2.45 3.18;
-1.89 -2.45 2.54 -2.11;
3.76 3.18 -2.11 3.37];
mu = [-1, 1, -.5, .5];
C=chol(Sigma);
for j=1:m
Z = randn(1,1000000)
generate Z = (z1, z2, z3, z4)
Set Y = C*Z
Set X = Y + mu
if (x1^2 + x2^2 + x3^2 + x4^2) >16;
then set s = s+1;
0 Comments
Answers (1)
Arnab Sen
on 24 Feb 2016
Hi,
The Statistics Toolbox has a function mvnrnd to generate jointly Gaussian random variables with specified means and covariance matrix:
>>N = 10; % desired number of samples of each variable
>>mu = [10; 10]; % vector of means
>>cov = [3 1; 1 3]; % covariance matrix
>>samples = mvnrnd(mu, cov, N);
If you want to do it manually, you can generate independent standard Gaussian RV's (with randn) and apply an affine transformation that will give the desired mean vector and covariance matrix. For that you need to compute the Cholesy decomposition of the latter. Note that the output of Matlab's chol function (see its documentation) needs to be (conjugate-)transposed to conform to the procedure described in the link.
The code would be:
>>N = 10; % desired number of samples of each variable
>>mu = [10; 10]; % vector of means
>>cov = [3 1; 1 3]; % covariance matrix
>>independent_samples = randn(N, size(cov,1));
>>A = chol(cov)';
>>samples = bsxfun(@plus, mu, A*independent_samples.').';
0 Comments
See Also
Categories
Find more on Random Number Generation in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!