Mercurial > octave
annotate scripts/polynomial/poly.m @ 20165:f1d0f506ee78 stable
doc: Update more docstrings to have one sentence summary as first line.
Reviewed optimization, polynomial, signal script directories.
* scripts/optimization/fminbnd.m, scripts/optimization/fminsearch.m,
scripts/optimization/fminunc.m, scripts/optimization/fsolve.m,
scripts/optimization/fzero.m, scripts/optimization/glpk.m,
scripts/optimization/lsqnonneg.m, scripts/optimization/pqpnonneg.m,
scripts/optimization/qp.m, scripts/optimization/sqp.m,
scripts/polynomial/compan.m, scripts/polynomial/mkpp.m,
scripts/polynomial/mpoles.m, scripts/polynomial/pchip.m,
scripts/polynomial/poly.m, scripts/polynomial/polyaffine.m,
scripts/polynomial/polyder.m, scripts/polynomial/polyeig.m,
scripts/polynomial/polyfit.m, scripts/polynomial/polygcd.m,
scripts/polynomial/polyint.m, scripts/polynomial/polyout.m,
scripts/polynomial/polyval.m, scripts/polynomial/ppder.m,
scripts/polynomial/ppint.m, scripts/polynomial/ppjumps.m,
scripts/polynomial/ppval.m, scripts/polynomial/residue.m,
scripts/polynomial/roots.m, scripts/polynomial/spline.m,
scripts/polynomial/splinefit.m, scripts/polynomial/unmkpp.m,
scripts/signal/arch_fit.m, scripts/signal/arch_rnd.m,
scripts/signal/arma_rnd.m, scripts/signal/autoreg_matrix.m,
scripts/signal/bartlett.m, scripts/signal/blackman.m, scripts/signal/detrend.m,
scripts/signal/diffpara.m, scripts/signal/durbinlevinson.m,
scripts/signal/fftconv.m, scripts/signal/fftfilt.m, scripts/signal/fftshift.m,
scripts/signal/filter2.m, scripts/signal/freqz.m, scripts/signal/hamming.m,
scripts/signal/hanning.m, scripts/signal/hurst.m, scripts/signal/ifftshift.m,
scripts/signal/periodogram.m, scripts/signal/sinc.m, scripts/signal/sinetone.m,
scripts/signal/sinewave.m, scripts/signal/spectral_adf.m,
scripts/signal/spectral_xdf.m, scripts/signal/spencer.m, scripts/signal/stft.m,
scripts/signal/synthesis.m, scripts/signal/unwrap.m,
scripts/signal/yulewalker.m:
Update more docstrings to have one sentence summary as first line.
author | Rik <rik@octave.org> |
---|---|
date | Mon, 04 May 2015 21:50:57 -0700 |
parents | 4197fc428c7d |
children | 516bb87ea72e |
rev | line source |
---|---|
19697
4197fc428c7d
maint: Update copyright notices for 2015.
John W. Eaton <jwe@octave.org>
parents:
19593
diff
changeset
|
1 ## Copyright (C) 1994-2015 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/>. | |
1025 | 18 |
3368 | 19 ## -*- texinfo -*- |
11471
994e2a93a8e2
Use uppercase 'A' to refer to matrix inputs in m-files.
Rik <octave@nomad.inbox5.com>
parents:
10821
diff
changeset
|
20 ## @deftypefn {Function File} {} poly (@var{A}) |
10687
a8ce6bdecce5
Improve documentation strings.
Rik <octave@nomad.inbox5.com>
parents:
9245
diff
changeset
|
21 ## @deftypefnx {Function File} {} poly (@var{x}) |
11471
994e2a93a8e2
Use uppercase 'A' to refer to matrix inputs in m-files.
Rik <octave@nomad.inbox5.com>
parents:
10821
diff
changeset
|
22 ## If @var{A} is a square @math{N}-by-@math{N} matrix, @code{poly (@var{A})} |
994e2a93a8e2
Use uppercase 'A' to refer to matrix inputs in m-files.
Rik <octave@nomad.inbox5.com>
parents:
10821
diff
changeset
|
23 ## is the row vector of the coefficients of @code{det (z * eye (N) - A)}, |
20165
f1d0f506ee78
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
24 ## the characteristic polynomial of @var{A}. |
f1d0f506ee78
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
25 ## |
f1d0f506ee78
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
26 ## For example, the following code finds the eigenvalues of @var{A} which are |
f1d0f506ee78
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
27 ## the roots of @code{poly (@var{A})}. |
10821
693e22af08ae
Grammarcheck documentation of m-files
Rik <octave@nomad.inbox5.com>
parents:
10687
diff
changeset
|
28 ## |
6850 | 29 ## @example |
9051
1bf0ce0930be
Grammar check TexInfo in all .m files
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
30 ## @group |
14327
4d917a6a858b
doc: Use Octave coding conventions in @example blocks of docstrings.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
31 ## roots (poly (eye (3))) |
4d917a6a858b
doc: Use Octave coding conventions in @example blocks of docstrings.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
32 ## @result{} 1.00001 + 0.00001i |
4d917a6a858b
doc: Use Octave coding conventions in @example blocks of docstrings.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
33 ## 1.00001 - 0.00001i |
4d917a6a858b
doc: Use Octave coding conventions in @example blocks of docstrings.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
34 ## 0.99999 + 0.00000i |
9051
1bf0ce0930be
Grammar check TexInfo in all .m files
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
35 ## @end group |
6850 | 36 ## @end example |
37 ## | |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
38 ## In fact, all three eigenvalues are exactly 1 which emphasizes that for |
10821
693e22af08ae
Grammarcheck documentation of m-files
Rik <octave@nomad.inbox5.com>
parents:
10687
diff
changeset
|
39 ## numerical performance the @code{eig} function should be used to compute |
693e22af08ae
Grammarcheck documentation of m-files
Rik <octave@nomad.inbox5.com>
parents:
10687
diff
changeset
|
40 ## eigenvalues. |
693e22af08ae
Grammarcheck documentation of m-files
Rik <octave@nomad.inbox5.com>
parents:
10687
diff
changeset
|
41 ## |
14104
614505385171
doc: Overhaul docstrings for polynomial functions.
Rik <octave@nomad.inbox5.com>
parents:
11587
diff
changeset
|
42 ## If @var{x} is a vector, @code{poly (@var{x})} is a vector of the |
19593
446c46af4b42
strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
43 ## coefficients of the polynomial whose roots are the elements of @var{x}. |
20165
f1d0f506ee78
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
44 ## That is, if @var{c} is a polynomial, then the elements of |
f1d0f506ee78
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
45 ## @code{@var{d} = roots (poly (@var{c}))} are contained in @var{c}. The |
f1d0f506ee78
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
46 ## vectors @var{c} and @var{d} are not identical, however, due to sorting and |
f1d0f506ee78
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
47 ## numerical errors. |
14104
614505385171
doc: Overhaul docstrings for polynomial functions.
Rik <octave@nomad.inbox5.com>
parents:
11587
diff
changeset
|
48 ## @seealso{roots, eig} |
3368 | 49 ## @end deftypefn |
787 | 50 |
5428 | 51 ## Author: KH <Kurt.Hornik@wu-wien.ac.at> |
2312 | 52 ## Created: 24 December 1993 |
53 ## Adapted-By: jwe | |
904 | 54 |
2312 | 55 function y = poly (x) |
1025 | 56 |
57 if (nargin != 1) | |
6046 | 58 print_usage (); |
1025 | 59 endif |
787 | 60 |
61 m = min (size (x)); | |
62 n = max (size (x)); | |
63 if (m == 0) | |
64 y = 1; | |
5158 | 65 return; |
787 | 66 elseif (m == 1) |
67 v = x; | |
68 elseif (m == n) | |
69 v = eig (x); | |
70 else | |
6046 | 71 print_usage (); |
787 | 72 endif |
2325 | 73 |
1336 | 74 y = zeros (1, n+1); |
75 y(1) = 1; | |
787 | 76 for j = 1:n; |
77 y(2:(j+1)) = y(2:(j+1)) - v(j) .* y(1:j); | |
78 endfor | |
2325 | 79 |
787 | 80 if (all (all (imag (x) == 0))) |
81 y = real (y); | |
82 endif | |
2325 | 83 |
787 | 84 endfunction |
7411 | 85 |
86 | |
14363
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14327
diff
changeset
|
87 %!assert (poly ([]), 1) |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14327
diff
changeset
|
88 %!assert (poly ([1, 2, 3]), [1, -6, 11, -6]) |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14327
diff
changeset
|
89 %!assert (poly ([1, 2; 3, 4]), [1, -5, -2], sqrt (eps)) |
7411 | 90 |
14363
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14327
diff
changeset
|
91 %!error poly ([1, 2, 3; 4, 5, 6]) |
7411 | 92 |