Sort eigenvalue matrix with eigenvector matrix

Bonk picture Bonk · Jul 5, 2011 · Viewed 9.1k times · Source

I have N eigenvalues in column vector form. Thus there are N eigenvectors corresponding to these eigenvalues, forming an eigenvector matrix.

Now, the problem I am working on requires me to sort the eigenvalues column vector in descending order. How do I sort the eigenvectors matrix in the same order as their eigenvalues in order to preserve correspondence?

Answer

acl picture acl · Jul 5, 2011

For example,

m = RandomReal[{0, 1}, {5, 5}];
{evals, evecs} = Eigensystem[m];
SortBy[Transpose[{evals, evecs}], First]

or if you want them in the same form, replace the last line by

Transpose@SortBy[Transpose[{evals, evecs}], First]

EDIT: while I used {evals,evecs}=Eigensystem[m], that's not necessary. I could just have used s=Eigensystem[m] and then used s wherever I currently have {evals,evecs}.