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 |
|
17 ## Software Foundation, 59 Temple Place - Suite 330, Boston, MA |
|
18 ## 02111-1307, USA. |
904
|
19 |
3368
|
20 ## -*- texinfo -*- |
|
21 ## @deftypefn {Function File} {} compan (@var{c}) |
|
22 ## Compute the companion matrix corresponding to polynomial coefficient |
|
23 ## vector @var{c}. |
3426
|
24 ## |
3368
|
25 ## The companion matrix is |
|
26 ## @iftex |
|
27 ## @tex |
|
28 ## $$ |
|
29 ## A = \left[\matrix{ |
|
30 ## -c_2/c_1 & -c_3/c_1 & \cdots & -c_N/c_1 & -c_{N+1}/c_1\cr |
|
31 ## 1 & 0 & \cdots & 0 & 0 \cr |
|
32 ## 0 & 1 & \cdots & 0 & 0 \cr |
|
33 ## \vdots & \vdots & \ddots & \vdots & \vdots \cr |
|
34 ## 0 & 0 & \cdots & 1 & 0}\right]. |
|
35 ## $$ |
|
36 ## @end tex |
|
37 ## @end iftex |
|
38 ## @ifinfo |
3426
|
39 ## |
3368
|
40 ## @smallexample |
|
41 ## _ _ |
|
42 ## | -c(2)/c(1) -c(3)/c(1) ... -c(N)/c(1) -c(N+1)/c(1) | |
|
43 ## | 1 0 ... 0 0 | |
|
44 ## | 0 1 ... 0 0 | |
|
45 ## A = | . . . . . | |
|
46 ## | . . . . . | |
|
47 ## | . . . . . | |
|
48 ## |_ 0 0 ... 1 0 _| |
|
49 ## @end smallexample |
|
50 ## @end ifinfo |
3426
|
51 ## |
2311
|
52 ## The eigenvalues of the companion matrix are equal to the roots of the |
|
53 ## polynomial. |
3368
|
54 ## @end deftypefn |
5053
|
55 ## |
3457
|
56 ## @seealso{poly, roots, residue, conv, deconv, polyval, polyderiv, and |
|
57 ## polyinteg} |
1025
|
58 |
3202
|
59 ## Author: Tony Richardson <arichard@stark.cc.oh.us> |
2312
|
60 ## Created: June 1994 |
|
61 ## Adapted-By: jwe |
561
|
62 |
2312
|
63 function A = compan (c) |
561
|
64 |
1025
|
65 if (nargin != 1) |
|
66 usage ("compan (vector)"); |
561
|
67 endif |
|
68 |
4030
|
69 if (! isvector (c)) |
3458
|
70 error ("compan: expecting a vector argument"); |
561
|
71 endif |
|
72 |
2303
|
73 ## Ensure that c is a row vector. |
1025
|
74 |
2716
|
75 if (rows (c) > 1) |
561
|
76 c = c.'; |
|
77 endif |
|
78 |
1025
|
79 n = length (c); |
2716
|
80 |
|
81 if (n == 1) |
|
82 A = []; |
|
83 else |
|
84 A = diag (ones (n-2, 1), -1); |
|
85 A(1,:) = -c(2:n) / c(1); |
|
86 endif |
561
|
87 |
|
88 endfunction |