Re: Sorting eigenvectors by eigenvalue
- To: mathgroup at smc.vnet.net
- Subject: [mg2061] Re: [mg2054] Sorting eigenvectors by eigenvalue
- From: brucec (Bruce Carpenter)
- Date: Sat, 23 Sep 1995 20:34:01 -0400
> I'm trying to use Sort to sort eigenvectors by eigenvalue. The eignevectors >are in a list of lists called vecs, and the eigenvalues in vals after the >following function call on matrix aa: > > {vals,vecs}=Eigensystem[aa] > > Then I want to define an ordering function p so I can use Sort[vecs,p]. >I tried the following: > > p[vecs[[i_]],vecs[[j_]]]:=Greater[Abs[vals[[i]],Abs[vals[[j]]]] > > Mathematica wont parse vecs[[i_]] saying that i is neither an integer nor >a list of integers. How can I accomplish what I want to do? >______________________________________________________________________________ >| | >| When endeavoring to explain human behaviour, | >| never discount the possibility of stupidity. | >| | >| Never ascribe to malfeasance | >| that which can be explained as stupidity. | >| | >| Bill Campbell | >`----------------------------------------------------------------------------' It is easier to do the sorting while the output from Eigensystem is intact: In[1]:= aa = Array[Random[]&,{3,3}] Out[1]= {{0.0712802, 0.413021, 0.774565}, {0.807317, 0.491799, 0.173613}, {0.369134, 0.331948, 0.661642}} In[2]:= Eigensystem[aa] Out[2]= {{1.3641, -0.359698, 0.220318}, {{0.540551, 0.614622, 0.574495}, {-0.729275, 0.682954, 0.0416072}, {0.181478, -0.852815, 0.489665}}} In[3]:= Transpose[%] Out[3]= {{1.3641, {0.540551, 0.614622, 0.574495}}, {-0.359698, {-0.729275, 0.682954, 0.0416072}}, {0.220318, {0.181478, -0.852815, 0.489665}}} In[4]:= Sort[%, (Abs[#1[[1]]]<=Abs[#2[[1]]])&] Out[4]= {{0.220318, {0.181478, -0.852815, 0.489665}}, {-0.359698, {-0.729275, 0.682954, 0.0416072}}, {1.3641, {0.540551, 0.614622, 0.574495}}} In[5]:= Transpose[%] Out[5]= {{0.220318, -0.359698, 1.3641}, {{0.181478, -0.852815, 0.489665}, {-0.729275, 0.682954, 0.0416072}, {0.540551, 0.614622, 0.574495}}} Bruce Carpenter Wolfram Research, Inc.