4
$\begingroup$

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?

$\endgroup$

1 Answer 1

4
$\begingroup$

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]}}    *)
$\endgroup$
4
  • $\begingroup$ ReverseSort is not a valid command for Mathematica 11 $\endgroup$
    – Gae P
    Dec 5, 2020 at 15:54
  • 1
    $\begingroup$ 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}}. $\endgroup$
    – Roman
    Dec 5, 2020 at 15:55
  • $\begingroup$ 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? $\endgroup$
    – Gae P
    Dec 5, 2020 at 15:59
  • 1
    $\begingroup$ Yes, see update $\endgroup$
    – Roman
    Dec 5, 2020 at 16:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.