help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Understanding eig()


From: Paul Kienzle
Subject: Re: Understanding eig()
Date: Sun, 1 Aug 2004 22:17:37 -0400


On Aug 1, 2004, at 5:47 PM, Rich Shepard wrote:

On Sun, 1 Aug 2004, Henry F. Mollet wrote:

In the real world we need real solutions but there are exceptions. I assume that GNU Octave lists the eigenvalues in the order of the absolute value
octave:3> la=diag(la)
la =

   11.72374 +  0.00000i
   -1.05925 +  5.81855i
   -1.05925 -  5.81855i
   -0.00571 +  2.32593i
   -0.00571 -  2.32593i
   -2.03018 +  0.00000i
    0.21818 +  0.82953i
    0.21818 -  0.82953i

Henry,

  Then my assumption that what octave produced as a result of the eig()
function is a list of the eigenvalues, in rank order, is correct. That's
good to know. Many thanks.

Underlying, Octave uses the routine dgeev, zgeev, zheev or dsyev
to compute the eigenvalues (depending on the type of input matrix).

I don't see any mention of rank ordering of eigenvalues on their
man pages (assuming you mean ranking by magnitude).  Indeed,
the following is a counter-example:

octave> abs(eig([4,5,0;-2,4,0;0,0,10]))
ans =

   5.0990
   5.0990
  10.0000

octave> abs(eig([4,5,0;-2,4,0;0,0,1]))
ans =

  5.0990
  5.0990
  1.0000

The only guarantee I read is that complex conjugates would
come in pairs. with the +i component first.

If you want to order the eigenvalues by decreasing magnitude, use:

        lambda = eig(A);
        [junk,idx] = sort(abs(lambda));
        lambda = lambda(flipud(idx));

If you want to order the eigenvalues and eigenvectors, use:

        [v,l] = eig(A);
        lambda = diag(l);
        [junk,idx] = sort(abs(lambda));
        v = v(:,flipud(idx));
        lambda = lambda(flipud(idx));

Since Octave uses a stable sort, this will preserve the
complex conjugate pair guarantee, by with the -i component
first since the list is reversed.

Hope that helps,

- Paul



-------------------------------------------------------------
Octave is freely available under the terms of the GNU GPL.

Octave's home on the web:  http://www.octave.org
How to fund new projects:  http://www.octave.org/funding.html
Subscription information:  http://www.octave.org/archive.html
-------------------------------------------------------------



reply via email to

[Prev in Thread] Current Thread [Next in Thread]