Why are the eigenvalues of eig() sorted in ascending order?

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?

Upvotes: 3

Views: 2048

Answers (1)

Adriaan
Adriaan

Reputation: 18187

Sorting is merely a choice of convenience. There's no such thing as a 'real' position of an eigenvector, just as (x,y) is just as valid as (y,x). Since a lot of matrix techniques work on eigenvectors in order of decreasing eigenvalue (i.e. most important first), it makes sense to structure them accordingly.

Upvotes: 4

Related Questions