I'm trying to find eigenvalues of a matrix with eig
.
I define the matrix with example data:
A = magic(5)
A =
17 24 1 8 15
23 5 7 14 16
4 6 13 20 22
10 12 19 21 3
11 18 25 2 9
and
D = eig(A,'matrix')
D =
65.0000 0 0 0 0
0 -21.2768 0 0 0
0 0 -13.1263 0 0
0 0 0 21.2768 0
0 0 0 0 13.1263
But if I use
C = cov(A)
and get eigenvalues from the covariance matrix, this is the result:
DC = eig(C,'matrix')
DC =
-0.0000 0 0 0 0
0 35.4072 0 0 0
0 0 44.9139 0 0
0 0 0 117.5861 0
0 0 0 0 127.0928
Why are the eigenvalues from the covariance matrix sorted in ascending order?