How to generate the matrix $\mathbf{M}$ with $\operatorname{cov}(\mathbf{M})=\mathbf{I}$

86 Views Asked by At

How can I generate a random matrix $\mathbf{M}$ such that $\operatorname{cov}(\mathbf{M}) = \mathbf{I}$ (identity). I use matlab to generate $\mathbf{M}$.

1

There are 1 best solutions below

3
On

Hmm, I don't have matlab, but a sequence of my MatMatecode might be translatable:

n=1000    // 1000 cases
v=10      // 10 variables

data = randomn(v,n,0,2)   // generate random data of stddev 2,mean=0
                          // this shall have some random-correlation

c1=data *' / n            // covariance-matrix of the data
t1=gettrans(c1 ,"pca")'   // this mimicks SVD-decomposition; the matrix t1 is
                          // the left one of the S D V - matrices and
                          //      is orthogonal. Note: the apostroph-symbol means
                          //      transposition
data1 = t1 * data         // t1 * data gives uncorrelated data as can be seen
c2 = data1  *' / n        //   since the covariance c2 is diagonal