home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 10 / 10.iso / l / l455 / 10.ddi / CONTROL.DI$ / ESORT.M < prev    next >
Encoding:
Text File  |  1993-03-11  |  947 b   |  39 lines

  1. function [s,ndx]=esort(p)
  2. %ESORT    Sort complex continuous eigenvalues in descending order
  3. %
  4. %    S=ESORT(P) sorts the complex eigenvalues in the vector P in
  5. %    descending order by real part.  The unstable eigenvalues will 
  6. %    appear first.
  7. %
  8. %    [S,NDX] = ESORT(P) also returns the vector NDX containing the 
  9. %    indexes used in the sort.
  10. %
  11. %    See also: DSORT and SORT.
  12.  
  13. %    Clay M. Thompson  7-12-90
  14. %    Copyright (c) 1986-93 by the Mathworks, Inc.
  15.  
  16. error(nargchk(1,1,nargin));
  17.  
  18. [m,n] = size(p);
  19. if m==1, p=p.'; [m,n] = size(p); end
  20.  
  21. [s,ndx] = sort( -real(p) );
  22. for i=1:n, s(:,i) = p(ndx(:,i),i); end
  23.  
  24. % Work around sort bug -- Remove when new sort routine is released.
  25. for i=1:n,
  26.   k=1;
  27.   while k<m,
  28.     if (imag(s(k,i))~=0),
  29.       if (imag(s(k,i))<0),
  30.          s(k:k+1,i)=conj(s(k:k+1,i));
  31.          swap = ndx(k,i); ndx(k,i)=ndx(k+1,i); ndx(k+1,i)=swap;
  32.       end
  33.       k = k+2;
  34.     else
  35.       k = k+1;
  36.     end
  37.   end
  38. end
  39.