Mercurial > hg > octave-lyh
annotate scripts/polynomial/compan.m @ 10846:a4f482e66b65
Grammarcheck more of the documentation.
Use @noindent macro appropriately.
Limit line length to 80 characters.
author | Rik <octave@nomad.inbox5.com> |
---|---|
date | Sun, 01 Aug 2010 20:22:17 -0700 |
parents | 693e22af08ae |
children | fd0a3ac60b0e |
rev | line source |
---|---|
7017 | 1 ## Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2002, 2004, |
9245 | 2 ## 2005, 2006, 2007, 2008, 2009 John W. Eaton |
2313 | 3 ## |
4 ## This file is part of Octave. | |
5 ## | |
6 ## Octave is free software; you can redistribute it and/or modify it | |
7 ## under the terms of the GNU General Public License as published by | |
7016 | 8 ## the Free Software Foundation; either version 3 of the License, or (at |
9 ## your option) any later version. | |
2313 | 10 ## |
11 ## Octave is distributed in the hope that it will be useful, but | |
12 ## WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
14 ## General Public License for more details. | |
15 ## | |
16 ## You should have received a copy of the GNU General Public License | |
7016 | 17 ## along with Octave; see the file COPYING. If not, see |
18 ## <http://www.gnu.org/licenses/>. | |
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 ## @tex | |
27 ## $$ | |
28 ## A = \left[\matrix{ | |
29 ## -c_2/c_1 & -c_3/c_1 & \cdots & -c_N/c_1 & -c_{N+1}/c_1\cr | |
30 ## 1 & 0 & \cdots & 0 & 0 \cr | |
31 ## 0 & 1 & \cdots & 0 & 0 \cr | |
32 ## \vdots & \vdots & \ddots & \vdots & \vdots \cr | |
33 ## 0 & 0 & \cdots & 1 & 0}\right]. | |
34 ## $$ | |
35 ## @end tex | |
6850 | 36 ## @ifnottex |
9153
5247e89688e1
Eliminate most overfull errors when running texi2pdf for generating pdf documentation
Rik <rdrider0-list@yahoo.com>
parents:
9051
diff
changeset
|
37 ## @c Set example in small font to prevent overfull line |
10846
a4f482e66b65
Grammarcheck more of the documentation.
Rik <octave@nomad.inbox5.com>
parents:
10821
diff
changeset
|
38 ## |
3368 | 39 ## @smallexample |
10793
be55736a0783
Grammarcheck the documentation from m-files.
Rik <octave@nomad.inbox5.com>
parents:
10224
diff
changeset
|
40 ## @group |
3368 | 41 ## _ _ |
9051
1bf0ce0930be
Grammar check TexInfo in all .m files
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
42 ## | -c(2)/c(1) -c(3)/c(1) @dots{} -c(N)/c(1) -c(N+1)/c(1) | |
1bf0ce0930be
Grammar check TexInfo in all .m files
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
43 ## | 1 0 @dots{} 0 0 | |
1bf0ce0930be
Grammar check TexInfo in all .m files
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
44 ## | 0 1 @dots{} 0 0 | |
10793
be55736a0783
Grammarcheck the documentation from m-files.
Rik <octave@nomad.inbox5.com>
parents:
10224
diff
changeset
|
45 ## A = | . . . . . | |
3368 | 46 ## | . . . . . | |
10793
be55736a0783
Grammarcheck the documentation from m-files.
Rik <octave@nomad.inbox5.com>
parents:
10224
diff
changeset
|
47 ## | . . . . . | |
9051
1bf0ce0930be
Grammar check TexInfo in all .m files
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
48 ## |_ 0 0 @dots{} 1 0 _| |
10793
be55736a0783
Grammarcheck the documentation from m-files.
Rik <octave@nomad.inbox5.com>
parents:
10224
diff
changeset
|
49 ## @end group |
3368 | 50 ## @end smallexample |
10821
693e22af08ae
Grammarcheck documentation of m-files
Rik <octave@nomad.inbox5.com>
parents:
10793
diff
changeset
|
51 ## |
6850 | 52 ## @end ifnottex |
2311 | 53 ## The eigenvalues of the companion matrix are equal to the roots of the |
54 ## polynomial. | |
5642 | 55 ## @seealso{poly, roots, residue, conv, deconv, polyval, polyderiv, |
10224
f6e0404421f4
point to polyint in @seealso, not polyinteg
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
56 ## polyint} |
3368 | 57 ## @end deftypefn |
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) |
6046 | 66 print_usage (); |
561 | 67 endif |
68 | |
4030 | 69 if (! isvector (c)) |
3458 | 70 error ("compan: expecting a vector argument"); |
561 | 71 endif |
72 | |
1025 | 73 n = length (c); |
2716 | 74 |
75 if (n == 1) | |
76 A = []; | |
77 else | |
78 A = diag (ones (n-2, 1), -1); | |
79 A(1,:) = -c(2:n) / c(1); | |
80 endif | |
561 | 81 |
82 endfunction | |
7411 | 83 |
84 %!assert(all (all (compan ([1, 2, 3]) == [-2, -3; 1, 0]))); | |
85 | |
86 %!assert(all (all (compan ([1; 2; 3]) == [-2, -3; 1, 0]))); | |
87 | |
88 %!assert(isempty (compan (4))); | |
89 | |
90 %!assert(all (all (compan ([3, 2, 1]) == [-2/3, -1/3; 1, 0]))); | |
91 | |
92 %!error compan ([1,2;3,4]); | |
93 | |
94 %!error compan ([]); | |
95 |