MathGroup Archive 1997

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Sorting Eigenvalues/EigenVectors

  • To: mathgroup at smc.vnet.net
  • Subject: [mg8214] Re: Sorting Eigenvalues/EigenVectors
  • From: "Tom Chwastyk" <chwastyk at nrl.navy.mil>
  • Date: Tue, 19 Aug 1997 21:11:52 -0400
  • Organization: US Naval Research Laboratory
  • Sender: owner-wri-mathgroup at wolfram.com

Joseph C. Slater <jslater at cs.wright.edu> wrote in article
<5sopua$gc6 at smc.vnet.net>...
> 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. 

One easy way is to transpose the eigensystem from 

{{val1,val2,...},{vec1,vec2...}} 

to 

{{val1,vec1},{val2,vec2},...}

, sort the transpose, then transpose back. The sort goes by first
differences - it doesn't even look at the vectors unless the eigenvalues
are exactly equal, and then it goes by first differences in the vectors. 

Remember, if your eigenvalues are complex, the default sort is not by
complex magnitude but by first differences on the real and then complex
parts. You can add an order function to Sort to change that if you like.

This same problem bothered me when I first came to MMa from APL; I wanted
to get a permutation vector like that resulting from the APL primitives
grade up or grade down, then subscript the parts of the eigensystem result
by that permutation vector to get a sorted eigensystem result. It took a
while to just relax and do it the way it's more natural in MMa.

The example below generates a random positive semidefinite matrix, then
changes two of the eigenvalues to be equal, just to demonstrate that the
sorting works as described for the real case...

x=Table[Random[Real,{-1,1}],{10},{6}];
xx=Transpose[x].x;
es=Eigensystem[xx];es[[1,{1,2}]]=1.5;
Table[es[[1,i]],es[[2,i,{1,2}]],{i,6}]
ses=Transpose[Sort[Transpose[es]]];
Table[ses[[1,i]],ses[[2,i,{1,2}]],{i,6}]

-- 
Tom Chwastyk ["Fosdick". Polish: CH='H, W=F (here),
A=AH, Y=I. Soften strict 'HFAH-stik.... :-) ]
Naval Research Laboratory Code 6383
Wash. DC 20375-5343    (202) 767 2567





  • Prev by Date: Re: Saving graphics in Mma 3.0.1
  • Next by Date: Re: Converting Excel table to Mathematica matrix.
  • Previous by thread: Re: Sorting Eigenvalues/EigenVectors
  • Next by thread: Re: Sorting Eigenvalues/EigenVectors