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. |
904
|
19 |
2311
|
20 ## usage: compan (c) |
|
21 ## |
|
22 ## Compute the companion matrix corresponding to polynomial vector c. |
|
23 ## |
|
24 ## In octave a polynomial is represented by it's coefficients (arranged |
|
25 ## in descending order). For example a vector c of length n+1 corresponds |
|
26 ## to the following nth order polynomial |
|
27 ## |
|
28 ## p(x) = c(1) x^n + ... + c(n) x + c(n+1). |
|
29 ## |
|
30 ## The corresponding companion matrix is |
|
31 ## _ _ |
|
32 ## | -c(2)/c(1) -c(3)/c(1) ... -c(n)/c(1) -c(n+1)/c(1) | |
|
33 ## | 1 0 ... 0 0 | |
|
34 ## | 0 1 ... 0 0 | |
|
35 ## A = | . . . . . | |
|
36 ## | . . . . . | |
|
37 ## | . . . . . | |
|
38 ## |_ 0 0 ... 1 0 _| |
|
39 ## |
|
40 ## The eigenvalues of the companion matrix are equal to the roots of the |
|
41 ## polynomial. |
|
42 ## |
|
43 ## SEE ALSO: poly, roots, residue, conv, deconv, polyval, polyderiv, polyinteg |
1025
|
44 |
2312
|
45 ## Author: Tony Richardson <amr@mpl.ucsd.edu> |
|
46 ## Created: June 1994 |
|
47 ## Adapted-By: jwe |
561
|
48 |
2312
|
49 function A = compan (c) |
561
|
50 |
1025
|
51 if (nargin != 1) |
|
52 usage ("compan (vector)"); |
561
|
53 endif |
|
54 |
1025
|
55 if(is_matrix (c)) |
561
|
56 error("compan: expecting a vector argument."); |
|
57 endif |
|
58 |
2303
|
59 ## Ensure that c is a row vector. |
1025
|
60 |
561
|
61 if(rows(c) > 1) |
|
62 c = c.'; |
|
63 endif |
|
64 |
1025
|
65 n = length (c); |
|
66 A = diag (ones (n-2, 1), -1); |
|
67 A (1, :) = -c (2:n) /c (1); |
561
|
68 |
|
69 endfunction |