# Sort eigenvectors by eigenvalue and assign to variables

I have the following question:

Let T = {{0, 0, 2}, {0, 0, 0}, {2, 0, 3}}, I know that its eigenvalues, in a decreasing order, are 4, 0 and -1. Mathematica displays eigenvalues and shows the corresponding eigenvectors, in order of the eigenvalue’s decreasing absolute value.

I would like to assign to a vector n1 the eigenvector of T corresponding to the maximum eigenvalues, to n2 the eigenvector related to the intermediate eigenvalues, and to n3 the eigenvector related to the minimum eigenvalue.

How can I do this?

Sort the eigenvalues and the eigenvectors jointly:

T = {{0, 0, 2}, {0, 0, 0}, {2, 0, 3}};
Transpose[ReverseSort[Transpose[Eigensystem[T]]]]
(*    {{4, 0, -1}, {{1, 0, 2}, {0, 1, 0}, {-2, 0, 1}}}    *)


Assign to the desired variables:

{eval, {n1, n2, n3}} = Transpose[ReverseSort[Transpose[Eigensystem[T]]]]
(*    {{4, 0, -1}, {{1, 0, 2}, {0, 1, 0}, {-2, 0, 1}}}    *)


### Update with eigenvector normalization

Assign the eigenvalues and eigenvectors to separate variables:

{eval, evec} = Transpose[ReverseSort[Transpose[Eigensystem[T]]]]
(*    {{4, 0, -1}, {{1, 0, 2}, {0, 1, 0}, {-2, 0, 1}}}    *)


Assign variables to the normalized eigenvectors:

{n1, n2, n3} = Normalize /@ evec
(*    {{1/Sqrt[5], 0, 2/Sqrt[5]},
{0, 1, 0},
{-2/Sqrt[5], 0, 1/Sqrt[5]}}    *)

• ReverseSort is not a valid command for Mathematica 11 Commented Dec 5, 2020 at 15:54
• Then use Reverse[Sort[...]] instead: Transpose[Reverse[Sort[Transpose[Eigensystem[T]]]]]. Or just use Sort and reverse the order of the assignments to {eval, {n3, n2, n1}}. Commented Dec 5, 2020 at 15:55
• Thanks Roman! I was trying with a cumbersome nested If conditions... Morevoer, is it possible to insert in this line the normalization of such vectors? Commented Dec 5, 2020 at 15:59
• Yes, see update Commented Dec 5, 2020 at 16:41