home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 10 / 10.iso / l / l460 / 2.ddi / POLYFUN.DI$ / POLY.M < prev    next >
Encoding:
Text File  |  1993-03-07  |  1.1 KB  |  47 lines

  1. function c = poly(x)
  2. %POLY    Characteristic polynomial.
  3. %    If A is an N by N matrix, POLY(A) is a row vector with
  4. %    N+1 elements which are the coefficients of the
  5. %    characteristic polynomial, DET(lambda*EYE(A) - A) .
  6. %    If V is a vector, POLY(V) is a vector whose elements are
  7. %    the coefficients of the polynomial whose roots are the
  8. %    elements of V . For vectors, ROOTS and POLY are inverse
  9. %    functions of each other, up to ordering, scaling, and
  10. %    roundoff error.
  11. %    ROOTS(POLY(1:20)) generates Wilkinson's famous example.
  12. %
  13. %    See also ROOTS, POLYVAL.
  14.  
  15. %    J.N. Little 4-21-85
  16. %    Revised 3-17-86 JNL
  17. %    Revised 11-6-90 CMT
  18. %    Copyright (c) 1984-93 by The MathWorks, Inc.
  19.  
  20. n = size(x);
  21. e = x;
  22.  
  23. % Characteristic polynomial (square x)
  24. if ~sum(n == 1)
  25.     e = eig(x);
  26. end
  27.  
  28. if max(size(e)) == 0
  29.     c = 1;
  30.     return
  31. end
  32.  
  33. % Strip infinities and throw away.
  34. e = e( finite(e) );
  35. n = max(size(e));
  36.  
  37. % Expand recursion formula
  38. c = [1 zeros(1,n)];
  39. for j=1:n
  40.     c(2:(j+1)) = c(2:(j+1)) - e(j).*c(1:j);
  41. end
  42.  
  43. % Force real if matrix was real.
  44. if all(imag(x) == 0)
  45.     c = real(c);
  46. end
  47.