2313
|
1 ## Copyright (C) 1996 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 |
|
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 |
|
17 ## Software Foundation, 59 Temple Place - Suite 330, Boston, MA |
|
18 ## 02111-1307, USA. |
1025
|
19 |
2311
|
20 ## usage: poly (x) |
|
21 ## |
2325
|
22 ## If A is a square n-by-n matrix, poly (A) is the row vector of |
2311
|
23 ## the coefficients of det (z * eye(n) - A), the characteristic |
|
24 ## polynomial of A. |
|
25 ## |
|
26 ## If x is a vector, poly (x) is a vector of coefficients of the |
|
27 ## polynomial whose roots are the elements of x. |
787
|
28 |
2312
|
29 ## Author: KH <Kurt.Hornik@neuro.tuwien.ac.at> |
|
30 ## Created: 24 December 1993 |
|
31 ## Adapted-By: jwe |
904
|
32 |
2312
|
33 function y = poly (x) |
1025
|
34 |
|
35 if (nargin != 1) |
|
36 usage ("poly (x)"); |
|
37 endif |
787
|
38 |
|
39 m = min (size (x)); |
|
40 n = max (size (x)); |
|
41 if (m == 0) |
|
42 y = 1; |
|
43 elseif (m == 1) |
|
44 v = x; |
|
45 elseif (m == n) |
|
46 v = eig (x); |
|
47 else |
1025
|
48 usage ("poly (x), where x is a vector or a square matrix"); |
787
|
49 endif |
2325
|
50 |
1336
|
51 y = zeros (1, n+1); |
|
52 y(1) = 1; |
787
|
53 for j = 1:n; |
|
54 y(2:(j+1)) = y(2:(j+1)) - v(j) .* y(1:j); |
|
55 endfor |
2325
|
56 |
787
|
57 if (all (all (imag (x) == 0))) |
|
58 y = real (y); |
|
59 endif |
2325
|
60 |
787
|
61 endfunction |