Mercurial > hg > octave-lyh
annotate scripts/polynomial/compan.m @ 14428:099bd779466c
test: Fix failing %!test in fileread.m
* fileread.m: Fix failing %!test.
author | Rik <octave@nomad.inbox5.com> |
---|---|
date | Fri, 02 Mar 2012 22:14:27 -0800 |
parents | f3d52523cde1 |
children |
rev | line source |
---|---|
14138
72c96de7a403
maint: update copyright notices for 2012
John W. Eaton <jwe@octave.org>
parents:
14104
diff
changeset
|
1 ## Copyright (C) 1994-2012 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 | |
7016 | 7 ## the Free Software Foundation; either version 3 of the License, or (at |
8 ## your option) any later version. | |
2313 | 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 | |
7016 | 16 ## along with Octave; see the file COPYING. If not, see |
17 ## <http://www.gnu.org/licenses/>. | |
904 | 18 |
3368 | 19 ## -*- texinfo -*- |
20 ## @deftypefn {Function File} {} compan (@var{c}) | |
21 ## Compute the companion matrix corresponding to polynomial coefficient | |
22 ## vector @var{c}. | |
3426 | 23 ## |
3368 | 24 ## The companion matrix is |
25 ## @tex | |
26 ## $$ | |
27 ## A = \left[\matrix{ | |
28 ## -c_2/c_1 & -c_3/c_1 & \cdots & -c_N/c_1 & -c_{N+1}/c_1\cr | |
29 ## 1 & 0 & \cdots & 0 & 0 \cr | |
30 ## 0 & 1 & \cdots & 0 & 0 \cr | |
31 ## \vdots & \vdots & \ddots & \vdots & \vdots \cr | |
32 ## 0 & 0 & \cdots & 1 & 0}\right]. | |
33 ## $$ | |
34 ## @end tex | |
6850 | 35 ## @ifnottex |
9153
5247e89688e1
Eliminate most overfull errors when running texi2pdf for generating pdf documentation
Rik <rdrider0-list@yahoo.com>
parents:
9051
diff
changeset
|
36 ## @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
|
37 ## |
3368 | 38 ## @smallexample |
10793
be55736a0783
Grammarcheck the documentation from m-files.
Rik <octave@nomad.inbox5.com>
parents:
10224
diff
changeset
|
39 ## @group |
3368 | 40 ## _ _ |
9051
1bf0ce0930be
Grammar check TexInfo in all .m files
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
41 ## | -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
|
42 ## | 1 0 @dots{} 0 0 | |
1bf0ce0930be
Grammar check TexInfo in all .m files
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
43 ## | 0 1 @dots{} 0 0 | |
10793
be55736a0783
Grammarcheck the documentation from m-files.
Rik <octave@nomad.inbox5.com>
parents:
10224
diff
changeset
|
44 ## A = | . . . . . | |
3368 | 45 ## | . . . . . | |
10793
be55736a0783
Grammarcheck the documentation from m-files.
Rik <octave@nomad.inbox5.com>
parents:
10224
diff
changeset
|
46 ## | . . . . . | |
9051
1bf0ce0930be
Grammar check TexInfo in all .m files
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
47 ## |_ 0 0 @dots{} 1 0 _| |
10793
be55736a0783
Grammarcheck the documentation from m-files.
Rik <octave@nomad.inbox5.com>
parents:
10224
diff
changeset
|
48 ## @end group |
3368 | 49 ## @end smallexample |
10821
693e22af08ae
Grammarcheck documentation of m-files
Rik <octave@nomad.inbox5.com>
parents:
10793
diff
changeset
|
50 ## |
6850 | 51 ## @end ifnottex |
2311 | 52 ## The eigenvalues of the companion matrix are equal to the roots of the |
53 ## polynomial. | |
14104
614505385171
doc: Overhaul docstrings for polynomial functions.
Rik <octave@nomad.inbox5.com>
parents:
13963
diff
changeset
|
54 ## @seealso{roots, poly, eig} |
3368 | 55 ## @end deftypefn |
1025 | 56 |
3202 | 57 ## Author: Tony Richardson <arichard@stark.cc.oh.us> |
2312 | 58 ## Created: June 1994 |
59 ## Adapted-By: jwe | |
561 | 60 |
2312 | 61 function A = compan (c) |
561 | 62 |
1025 | 63 if (nargin != 1) |
6046 | 64 print_usage (); |
561 | 65 endif |
66 | |
4030 | 67 if (! isvector (c)) |
3458 | 68 error ("compan: expecting a vector argument"); |
561 | 69 endif |
70 | |
1025 | 71 n = length (c); |
2716 | 72 |
73 if (n == 1) | |
74 A = []; | |
75 else | |
76 A = diag (ones (n-2, 1), -1); | |
77 A(1,:) = -c(2:n) / c(1); | |
78 endif | |
561 | 79 |
80 endfunction | |
7411 | 81 |
82 | |
14363
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
83 %!assert (compan ([1, 2, 3]), [-2, -3; 1, 0]) |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
84 %!assert (compan ([1; 2; 3]), [-2, -3; 1, 0]) |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
85 %!assert (isempty (compan (4))) |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
86 %!assert (compan ([3, 2, 1]), [-2/3, -1/3; 1, 0]) |
7411 | 87 |
14363
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
88 %!error compan ([1,2;3,4]) |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
89 %!error compan ([]) |
7411 | 90 |