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