2847
|
1 ## Copyright (C) 1996, 1997 John W. Eaton |
2313
|
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 |
|
7 ## the Free Software Foundation; either version 2, or (at your option) |
|
8 ## any later version. |
|
9 ## |
|
10 ## Octave is distributed in the hope that it will be useful, but |
|
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
13 ## General Public License 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 |
5307
|
17 ## Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
|
18 ## 02110-1301, USA. |
1025
|
19 |
3368
|
20 ## -*- texinfo -*- |
|
21 ## @deftypefn {Function File} {} poly (@var{a}) |
3499
|
22 ## If @var{a} is a square @math{N}-by-@math{N} matrix, @code{poly (@var{a})} |
3368
|
23 ## is the row vector of the coefficients of @code{det (z * eye (N) - a)}, |
|
24 ## the characteristic polynomial of @var{a}. If @var{x} is a vector, |
|
25 ## @code{poly (@var{x})} is a vector of coefficients of the polynomial |
|
26 ## whose roots are the elements of @var{x}. |
|
27 ## @end deftypefn |
787
|
28 |
5428
|
29 ## Author: KH <Kurt.Hornik@wu-wien.ac.at> |
2312
|
30 ## Created: 24 December 1993 |
|
31 ## Adapted-By: jwe |
904
|
32 |
2312
|
33 function y = poly (x) |
1025
|
34 |
|
35 if (nargin != 1) |
6046
|
36 print_usage (); |
1025
|
37 endif |
787
|
38 |
|
39 m = min (size (x)); |
|
40 n = max (size (x)); |
|
41 if (m == 0) |
|
42 y = 1; |
5158
|
43 return; |
787
|
44 elseif (m == 1) |
|
45 v = x; |
|
46 elseif (m == n) |
|
47 v = eig (x); |
|
48 else |
6046
|
49 print_usage (); |
787
|
50 endif |
2325
|
51 |
1336
|
52 y = zeros (1, n+1); |
|
53 y(1) = 1; |
787
|
54 for j = 1:n; |
|
55 y(2:(j+1)) = y(2:(j+1)) - v(j) .* y(1:j); |
|
56 endfor |
2325
|
57 |
787
|
58 if (all (all (imag (x) == 0))) |
|
59 y = real (y); |
|
60 endif |
2325
|
61 |
787
|
62 endfunction |