Calculating Covariance matrix of higher dimensions

379 Views Asked by At

I have the following matrix:

$$A = \begin{bmatrix} 1 & 2\\ 3& 4 \end{bmatrix}$$

I therefore compute the Covariance matrix using the following:

$$ \sum_{i=1}^{N} \frac{(x_{i} - u_{i})({y_{i} - u_{i}})}{N}$$

This produces the correct output for a 2x2 matrix, or, any matrix x2 e.g.

$$A = \begin{bmatrix} 1 & 2\\ 4&4 \\ 3 & 4 \\ 3 & 3 \\ \end{bmatrix}$$

On any other dimensions, e.g.

$$A = \begin{bmatrix} 1 & 2 & 3\\ 4&4 & 1 \\ 3 & 2 & 2 \\ 1 & 4 & 1 \end{bmatrix}$$

Will produce the wrong results, when comparing to those in MATLAB. In MATLAB I get:

$$A = \begin{bmatrix} 2.25 & 0.33 & -0.58 \\ 0.33 & 1.33 & -1.00 \\ -0.58 & -1.00 & 0.9167 \\ \end{bmatrix}$$

And I get the result:

$$A = \begin{bmatrix} 6.75 & 1 & -1.75 \\ 1 & 4 & -3 \\ -1.75 & -3 & 2.75 \\ \end{bmatrix}$$

I can't see where I'm going wrong. By the way when I use MATLAB, I just type: cov(A) Where A = [1 2 3; 4 4 1; 3 2 2; 1 4 1] and I'm calculating using pen and paper for now where I'm getting the wrong result.

Any help would be greatly appreciated

1

There are 1 best solutions below

7
On BEST ANSWER

don't worry!

You have the right answer! And matlab has the right answer too!

When using matlab you have to remember that it will allwas try to improve the results. If you see to your answer, you will observe that you can factorize the value $3$ of your matrix $A$.

Matlab has already done this and it is giving you the result after the factorization step has taken place, the result, the matrix $3A$ only that you don't see the $3$-value, I believe this is because matlab operates with orthonormal vectors.

You can find more info at the matlab's page.