Path: news.mathworks.com!not-for-mail
From: "Willem Geert " <wgphaff@gmail.com>
Newsgroups: comp.soft-sys.matlab
Subject: order of eigenvalues
Date: Fri, 1 Feb 2008 13:18:02 +0000 (UTC)
Organization: The MathWorks, Inc.
Lines: 49
Message-ID: <fnv66a$cjt$1@fred.mathworks.com>
Reply-To: "Willem Geert " <wgphaff@gmail.com>
NNTP-Posting-Host: webapp-02-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1201871882 12925 172.30.248.37 (1 Feb 2008 13:18:02 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Fri, 1 Feb 2008 13:18:02 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 524933
Xref: news.mathworks.com comp.soft-sys.matlab:448750


Hi All,

I'm working on a problem that requires me to trace the 
eigenvalues of the gain matrix of a linearization of a non-
linear ODE. However, the eig() function is causing some 
problems.

Say we have the gain matrix in two points of time close 
together : t_1 and t_2. For t_2 the gain matrix would be 
slightly different from the gain matrix at t_1, eigenvalues 
would also be slightly different. Unfortunately, eig() will 
sometimes return the eigenvalues at two points in time 
close together in a completely different order. For 
instance, if the eigenvalues at t_1 were [1; -1+i;-1-i], 
then, sometimes, the eigenvalues for t_2 are returned as [-
1.01+.99i; -1.01-.99i; -.99; ]. This makes a comparison 
between the eigenvalues at two points in time very 
difficult.

There is no natural order to the eigenvalues since they are 
complex, so sorting doesn't work. Especially in higher 
order systems this is futile. For now I've created a 
workaround that sorts the eigenvalues at t_2 based on the 
difference with the eigenvalues at t_1:
    
    [evOldmg, evNewmg] = meshgrid(evOld, evNew);
    the_diff        = abs(evOldmg - evNewmg);
    % second return value of min function is location,
    %  which can be used for permutation.
    [minims, perm]  = min(the_diff, [], 1);

    % permute
    evperm = evNew(perm);

This, however, is a bit of a hack and still fails 
sometimes. So does an equivalent method of sorting based on 
the eigenvectors.

Does anyone know of a method of calculating the eigenvalues 
that does not have the order problem? Or, perhaps a better 
solution than my temporary workaround?

Regards,

Willem Geert

PS. I've sifted through news-group posts and google, but 
could not find a solution to this problem. If I've missed a 
previously posted solution, please point me to it.