Path: news.mathworks.com!not-for-mail
From: "Steven Lord" <slord@mathworks.com>
Newsgroups: comp.soft-sys.matlab
Subject: Re: unsorted eigenvalues
Date: Fri, 28 Sep 2007 09:41:56 -0400
Organization: The MathWorks, Inc.
Lines: 66
Message-ID: <fdj0b4$ogm$1@fred.mathworks.com>
References: <fdhvq6$hok$1@fred.mathworks.com>
Reply-To: "Steven Lord" <slord@mathworks.com>
NNTP-Posting-Host: lords.dhcp.mathworks.com
X-Trace: fred.mathworks.com 1190986916 25110 144.212.105.187 (28 Sep 2007 13:41:56 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Fri, 28 Sep 2007 13:41:56 +0000 (UTC)
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2900.3138
X-RFC2646: Format=Flowed; Original
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.3138
Xref: news.mathworks.com comp.soft-sys.matlab:430594




"Robert Sparr" <robertdotsparr@NOSPAMsri.com> wrote in message 
news:fdhvq6$hok$1@fred.mathworks.com...
> I'm doing eigendecomposition-based spectral analysis, and I
> am looking for a way to recover the eigenvalues of a matrix
> (positive semidefinite Hermitian, in my case) without having
> them sorted for me.
>
> I've seen this topic come up in other threads (such as
> "Sorted Eigenvalues & Eigenvectors?" of April 2004 and
> "non-sorting SVD" of May 2007), but the answers there
> haven't settled my problem.
>
> In my experience, eig() always returns the eigenvalues
> sorted in ascending order, despite statements to the
> contrary in previous threads.  (Perhaps this changed with a
> recent version?)

I think you may have misunderstood what was said in those previous threads. 
We don't guarantee that the eigenvalues are returned in sorted order.  We 
also don't guarantee that the eigenvalues are not returned in sorted order. 
We just return them from EIG in the order that the LAPACK routine that 
calculates them returns them to EIG.  If you want to guarantee that they are 
sorted, sort them using SORT.

> I am aware that the eigenvectors have been sorted so that
> eigenvector index i corresponds to eigenvalue index i, and I
> know how to reconstruct the signal with the sorted output
> given by eig(), but that is not sufficient.  I also need to
> know the indexes that the significant eigenvalues had before
> they were sorted.

I don't understand what you're asking for.  If I calculate the eigenvalues 
of magic(4):

[V, D] = eig(magic(4));
eigenvalues = diag(D)

eigenvalues =

                        34
          8.94427190999916
         -8.94427190999915
     9.41628944095001e-016

what are the "indexes [sic] that the significant eigenvalues had before they 
were sorted"?  What ordering are you looking for, and how would MATLAB 
determine this ordering from the matrix?

If you're thinking about some sort of ordering of the eigenvalues to 
correspond to the eigenvectors, just use the 2 output form of EIG.  The kth 
column of V above is the eigenvector corresponding to the kth eigenvalue in 
D, D(k, k).

If you want the eigenvalues in some pseudorandom order, use RANDPERM to 
permute them.  Note that one of the permutations will order the eigenvalues 
in ascending order and one will order them in descending order.  You can use 
ISSORTED to test for these cases and use RANDPERM again to permute them.

*snip*

-- 
Steve Lord
slord@mathworks.com