       Re: Sorting Eigenvalues/EigenVectors

• To: mathgroup at smc.vnet.net
• Subject: [mg8193] Re: Sorting Eigenvalues/EigenVectors
• From: Robert Knapp <rknapp>
• Date: Mon, 18 Aug 1997 23:24:42 -0400
• Organization: Wolfram Research, Inc.
• Sender: owner-wri-mathgroup at wolfram.com

```Joseph C. Slater wrote:
>
> Is there an easy way to sort the results of EigenSystem so that the
> eigenvalues are in increasing order? I can pull them out of the results and
> sort them, but the association of the eigenvalues with the eigenvectors is
> lost. I've been RTFMing for quite a while, and I still can't figure this
> out.
>
> Thanks, Joe Slater
>

You could try

Transpose[Sort[Transpose[Eigensystem[matrix]]]]

For example:

First find the eigenvalues and eigenvectors (by default they are sorted
in order of complex absolute value largest to smallest)

In:= es = Eigensystem[{{1.,2.,3.},{4.,5.,6.},{7.,8.,9.}}]
-17
Out= {{16.1168, -1.11684, -4.0926 10   },
>    {{0.231971, 0.525322, 0.818673}, {0.78583, 0.0867513, -0.612328},
>     {0.408248, -0.816497, 0.408248}}}

This pairs each of the eigenvalues with the corresponding eigenvector.

In:= tes = Transpose[es]
Out= {{16.1168, {0.231971, 0.525322, 0.818673}},
>    {-1.11684, {0.78583, 0.0867513, -0.612328}},
-17
>    {-4.0926 10   , {0.408248, -0.816497, 0.408248}}}

This sorts based on the first element of  each list (the eigenvalue)

In:= stes = Sort[tes]

Out= {{-1.11684, {0.78583, 0.0867513, -0.612328}},
-17
>    {-4.0926 10   , {0.408248, -0.816497, 0.408248}},
>    {16.1168, {0.231971, 0.525322, 0.818673}}}

This puts the sorted list back into a separate list of {eigenvalues,
eigenvectors}

In:= Transpose[stes]
-17
Out= {{-1.11684, -4.0926 10   , 16.1168},
>    {{0.78583, 0.0867513, -0.612328}, {0.408248, -0.816497, 0.408248},
>     {0.231971, 0.525322, 0.818673}}}

I'm not quite sure what you wnat to do if any of the values are complex,
but you could modify the Order function in Sort to get what you want.

Rob Knapp
Wolfram Research, Inc.

```

• Prev by Date: Trying to use Solve - temp1a.nb (1/1)
• Next by Date: Locating text in Show
• Previous by thread: Re: Sorting Eigenvalues/EigenVectors
• Next by thread: Re: Sorting Eigenvalues/EigenVectors