help-octave
[Top][All Lists]
Advanced

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

Re: eig() function


From: Marvin Vis
Subject: Re: eig() function
Date: Thu, 9 Oct 97 09:12:50 MDT

>         function [v,d] = eigsort (x)
>                 length  = is_square (x);
>                 if !(length)
>                         error ('Input argument is not a square matrix!\n');
>                 end;
>  
>                 [v,d]   = eig (x);
>                 [dd,ix] = sort (-diag (d));
>                 for i=1:length
>                         d(i,i)  = - dd(i);
>                 end;
>                 v       = v(:,ix)
>         endfunction
>  
> If sorting the eigenvalues and their corresponding eigenvectors in the
> eig() function is not complicated and can speed up the process, wouldn't
> it be better to add the sorting algorithm as an additional OPT feature in
> the eig function instead of the above macros?

Try using the flipud() and fliplr() functions on your v,d matrices above...

        function [v,d] = eigd (x)
           [v,d]   = eig (x);
           v = fliplr(v);
           d = flipud(fliplr(d));  % or use:  d = diag(flipud(diag(d)))
                                   % ...whichever is faster
        end

My personal vote is to not load any of the built-in linear algebra package
subroutines.

The initial eigsort() function above will also sort the eigenvalues in 
decending order *including* sign, meaning that my suggestion above is only 
the same as the initial eigsort() routine if all of the eigenvalues are
positive reals....furthermore, I think the sort() routine disregards the
imaginary portion of the eigenvalue, whereas the sort in the eig()
function is based on the abs() of the eigenvalues.  There would be a
convention to define here if we were to modify eig().

M.



reply via email to

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