Difference between mvnrnd(,sigma) and randn()*chol(sigma)
9 views (last 30 days)
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
0 Comments
Accepted Answer
Peter Perkins
on 2 Sep 2014
Did you forget to reset the random number generator between the two calls? mvnrnd and randn draw random values from the same stream.
More Answers (0)
See Also
Categories
Find more on Matrix Decomposition 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!