Difference between mvnrnd(,sigma) and randn()*chol(sigma)
Show older comments
I would like to create correlated multivariate normal random numbers. It is my understanding that this can either be done using the Statistic Toolbox function mvrnd or by using randn with a Cholesky decomposition of the covariance matrix (sigma).
rng('default')
sigma = [1 .5;0.5 1];
R = mvnrnd(zeros(100,2),sigma);
R2 = randn(100,2)*chol(sigma);
corrcoef(R)
corrcoef(R2)
However, above code gives me different random numbers (although they do exhibit the desired correlation). Why is this the case? Is their a difference between using mvnrnd() and randn()*chol()?
Best regards, Florian
Accepted Answer
More Answers (0)
Categories
Find more on Linear Algebra 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!