Generate Three (or More) Correlated Random Vectors In Matlab

  • June 2020
  • PDF

This document was uploaded by user and they confirmed that they have the permission to share it. If you are author or own the copyright of this book, please report to us by using this DMCA report form. Report DMCA


Overview

Download & View Generate Three (or More) Correlated Random Vectors In Matlab as PDF for free.

More details

  • Words: 93
  • Pages: 1
% Courtesey of: User "Bruno Luong" (from MATLAB Newsgroup) % By Hammad Munawar (hammadmunawar.weebly.com),IAA,Islamabad, Pakistan % % Generate three correlated normally distributed random vectors (x,y,z) % % SD(x)=10,mean(x)=100 % SD(y)=10,mean(y)=100 % SD(z)=2.5,mean(z)=100 % corr(x,z)=0 % corr(x,y)=-0.5 % corr(y,z)=-0.5 % sd_x=10;%standard deviation sd_y=10;%standard deviation sd_z=2.5;%standard deviation mean_x=100;%mean mean_y=100;%mean mean_z=100;%mean n = 100;%lenght of vectors % % Variance matrix % S = diag([sd_x sd_y sd_z].^2); S(1,2)=-0.5*sqrt(S(1,1)*S(2,2)); S(2,3)=-0.5*sqrt(S(2,2)*S(3,3)); S(3,2)=S(2,3); S(2,1)=S(1,2); % L=chol(S);%cholesky factorization M=[mean_x;mean_y;mean_z]; %means vector % U=bsxfun(@plus,M,L.'*randn(3,n));%generate correlated random numbers U=U'; % x=U(:,1);%form vector y=U(:,2);%form vector z=U(:,3);%form vector % corr(x,y)%verify correlation corr(x,z)%verify correlation corr(y,z)%verify correlation

Related Documents