Difference between mvnrnd(,sigma) and randn()*chol(sigma)
Afficher commentaires plus anciens
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
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Matrix Decomposition dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!