787
|
1 function y = poly (x) |
|
2 # |
|
3 # If A is a square n-by-n matrix, poly (A) is the row vector of |
|
4 # the coefficients of det (z * eye(n) - A), the characteristic |
|
5 # polynomial of A. |
|
6 # If x is a vector, poly (x) is a vector of coefficients of the |
|
7 # polynomial whose roots are the elements of x. |
|
8 |
|
9 # Written by KH (Kurt.Hornik@neuro.tuwien.ac.at) on Dec 24, 1993 |
|
10 # Copyright Dept of Probability Theory and Statistics TU Wien |
|
11 |
|
12 m = min (size (x)); |
|
13 n = max (size (x)); |
|
14 if (m == 0) |
|
15 y = 1; |
|
16 elseif (m == 1) |
|
17 v = x; |
|
18 elseif (m == n) |
|
19 v = eig (x); |
|
20 else |
|
21 error ("usage: poly(x), where x is a vector or a square matrix"); |
|
22 endif |
|
23 |
|
24 y = [1, zeros (1, n)]; |
|
25 for j = 1:n; |
|
26 y(2:(j+1)) = y(2:(j+1)) - v(j) .* y(1:j); |
|
27 endfor |
|
28 |
|
29 if (all (all (imag (x) == 0))) |
|
30 y = real (y); |
|
31 endif |
|
32 |
|
33 endfunction |