1025
|
1 # Copyright (C) 1995 John W. Eaton |
|
2 # |
|
3 # This file is part of Octave. |
|
4 # |
|
5 # Octave is free software; you can redistribute it and/or modify it |
|
6 # under the terms of the GNU General Public License as published by the |
|
7 # Free Software Foundation; either version 2, or (at your option) any |
|
8 # later version. |
|
9 # |
|
10 # Octave is distributed in the hope that it will be useful, but WITHOUT |
|
11 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
12 # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
13 # for more details. |
|
14 # |
|
15 # You should have received a copy of the GNU General Public License |
|
16 # along with Octave; see the file COPYING. If not, write to the Free |
1315
|
17 # Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
1025
|
18 |
787
|
19 function y = poly (x) |
|
20 |
1025
|
21 # usage: poly (x) |
|
22 # |
904
|
23 # If A is a square n-by-n matrix, poly (A) is the row vector of |
|
24 # the coefficients of det (z * eye(n) - A), the characteristic |
|
25 # polynomial of A. |
1025
|
26 # |
904
|
27 # If x is a vector, poly (x) is a vector of coefficients of the |
|
28 # polynomial whose roots are the elements of x. |
|
29 |
1025
|
30 # Written by KH (Kurt.Hornik@neuro.tuwien.ac.at) Dec 24, 1993. |
|
31 |
|
32 if (nargin != 1) |
|
33 usage ("poly (x)"); |
|
34 endif |
787
|
35 |
|
36 m = min (size (x)); |
|
37 n = max (size (x)); |
|
38 if (m == 0) |
|
39 y = 1; |
|
40 elseif (m == 1) |
|
41 v = x; |
|
42 elseif (m == n) |
|
43 v = eig (x); |
|
44 else |
1025
|
45 usage ("poly (x), where x is a vector or a square matrix"); |
787
|
46 endif |
|
47 |
|
48 y = [1, zeros (1, n)]; |
|
49 for j = 1:n; |
|
50 y(2:(j+1)) = y(2:(j+1)) - v(j) .* y(1:j); |
|
51 endfor |
|
52 |
|
53 if (all (all (imag (x) == 0))) |
|
54 y = real (y); |
|
55 endif |
|
56 |
|
57 endfunction |