Difference between mvnrnd(,sigma) and randn()*chol(sigma)

9 views (last 30 days)
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

Peter Perkins
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.
  1 Comment
Florian
Florian on 30 Sep 2014
Yes, that was it. If I put rng('default') after
R = mvnrnd(zeros(100,2),sigma);
I get the same results!

Sign in to comment.

More Answers (0)

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!