Mercurial > hg > octave-nkf
annotate doc/interpreter/poly.txi @ 12408:187d48827b47 release-3-4-x
don't warn about coercing nested functions to subfunctions if yyparse failed
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Tue, 08 Feb 2011 03:22:12 -0500 |
parents | 6eded7561d9d |
children | 663594b481e5 |
rev | line source |
---|---|
11523 | 1 @c Copyright (C) 1996-2011 John W. Eaton |
7018 | 2 @c |
3 @c This file is part of Octave. | |
4 @c | |
5 @c Octave is free software; you can redistribute it and/or modify it | |
6 @c under the terms of the GNU General Public License as published by the | |
7 @c Free Software Foundation; either version 3 of the License, or (at | |
8 @c your option) any later version. | |
9 @c | |
10 @c Octave is distributed in the hope that it will be useful, but WITHOUT | |
11 @c ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
12 @c FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
13 @c for more details. | |
14 @c | |
15 @c You should have received a copy of the GNU General Public License | |
16 @c along with Octave; see the file COPYING. If not, see | |
17 @c <http://www.gnu.org/licenses/>. | |
3294 | 18 |
4167 | 19 @node Polynomial Manipulations |
3294 | 20 @chapter Polynomial Manipulations |
21 | |
22 In Octave, a polynomial is represented by its coefficients (arranged | |
6850 | 23 in descending order). For example, a vector @var{c} of length |
24 @math{N+1} corresponds to the following polynomial of order | |
3294 | 25 @tex |
26 $N$ | |
27 $$ | |
6850 | 28 p (x) = c_1 x^N + \ldots + c_N x + c_{N+1}. |
3294 | 29 $$ |
30 @end tex | |
10668
72585f1ca7a2
Replace @ifinfo with @ifnottex.
Rik <octave@nomad.inbox5.com>
parents:
10224
diff
changeset
|
31 @ifnottex |
3294 | 32 @var{N} |
33 | |
34 @example | |
9070
e9dc2ed2ec0f
Cleanup documentation for poly.texi, interp.texi, geometry.texi
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
35 p(x) = @var{c}(1) x^@var{N} + @dots{} + @var{c}(@var{N}) x + @var{c}(@var{N}+1). |
3294 | 36 @end example |
10828
322f43e0e170
Grammarcheck .txi documentation files.
Rik <octave@nomad.inbox5.com>
parents:
10668
diff
changeset
|
37 |
10668
72585f1ca7a2
Replace @ifinfo with @ifnottex.
Rik <octave@nomad.inbox5.com>
parents:
10224
diff
changeset
|
38 @end ifnottex |
3294 | 39 |
6850 | 40 @menu |
41 * Evaluating Polynomials:: | |
42 * Finding Roots:: | |
43 * Products of Polynomials:: | |
11538
6eded7561d9d
Add undocumented polyaffine function to documentation.
Rik <octave@nomad.inbox5.com>
parents:
11536
diff
changeset
|
44 * Derivatives / Integrals / Transforms:: |
6850 | 45 * Polynomial Interpolation:: |
46 * Miscellaneous Functions:: | |
47 @end menu | |
48 | |
49 @node Evaluating Polynomials | |
50 @section Evaluating Polynomials | |
51 | |
52 The value of a polynomial represented by the vector @var{c} can be evaluated | |
8828 | 53 at the point @var{x} very easily, as the following example shows: |
6850 | 54 |
55 @example | |
9070
e9dc2ed2ec0f
Cleanup documentation for poly.texi, interp.texi, geometry.texi
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
56 @group |
6850 | 57 N = length(c)-1; |
58 val = dot( x.^(N:-1:0), c ); | |
9070
e9dc2ed2ec0f
Cleanup documentation for poly.texi, interp.texi, geometry.texi
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
59 @end group |
6850 | 60 @end example |
61 | |
62 @noindent | |
63 While the above example shows how easy it is to compute the value of a | |
64 polynomial, it isn't the most stable algorithm. With larger polynomials | |
65 you should use more elegant algorithms, such as Horner's Method, which | |
66 is exactly what the Octave function @code{polyval} does. | |
67 | |
68 In the case where @var{x} is a square matrix, the polynomial given by | |
69 @var{c} is still well-defined. As when @var{x} is a scalar the obvious | |
70 implementation is easily expressed in Octave, but also in this case | |
71 more elegant algorithms perform better. The @code{polyvalm} function | |
72 provides such an algorithm. | |
73 | |
74 @DOCSTRING(polyval) | |
75 | |
76 @DOCSTRING(polyvalm) | |
77 | |
78 @node Finding Roots | |
79 @section Finding Roots | |
80 | |
81 Octave can find the roots of a given polynomial. This is done by computing | |
82 the companion matrix of the polynomial (see the @code{compan} function | |
83 for a definition), and then finding its eigenvalues. | |
84 | |
85 @DOCSTRING(roots) | |
86 | |
3368 | 87 @DOCSTRING(compan) |
3294 | 88 |
8286
6f2d95255911
fix @seealso references to point to existing anchors
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
7640
diff
changeset
|
89 @DOCSTRING(mpoles) |
6f2d95255911
fix @seealso references to point to existing anchors
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
7640
diff
changeset
|
90 |
6850 | 91 @node Products of Polynomials |
92 @section Products of Polynomials | |
93 | |
3368 | 94 @DOCSTRING(conv) |
3294 | 95 |
7640 | 96 @DOCSTRING(convn) |
97 | |
3368 | 98 @DOCSTRING(deconv) |
3294 | 99 |
6549 | 100 @DOCSTRING(conv2) |
101 | |
6850 | 102 @DOCSTRING(polygcd) |
103 | |
104 @DOCSTRING(residue) | |
105 | |
11538
6eded7561d9d
Add undocumented polyaffine function to documentation.
Rik <octave@nomad.inbox5.com>
parents:
11536
diff
changeset
|
106 @node Derivatives / Integrals / Transforms |
6eded7561d9d
Add undocumented polyaffine function to documentation.
Rik <octave@nomad.inbox5.com>
parents:
11536
diff
changeset
|
107 @section Derivatives / Integrals / Transforms |
6850 | 108 |
109 Octave comes with functions for computing the derivative and the integral | |
6898 | 110 of a polynomial. The functions @code{polyderiv} and @code{polyint} |
6850 | 111 both return new polynomials describing the result. As an example we'll |
112 compute the definite integral of @math{p(x) = x^2 + 1} from 0 to 3. | |
113 | |
114 @example | |
9070
e9dc2ed2ec0f
Cleanup documentation for poly.texi, interp.texi, geometry.texi
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
115 @group |
6850 | 116 c = [1, 0, 1]; |
6898 | 117 integral = polyint(c); |
6850 | 118 area = polyval(integral, 3) - polyval(integral, 0) |
119 @result{} 12 | |
9070
e9dc2ed2ec0f
Cleanup documentation for poly.texi, interp.texi, geometry.texi
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
120 @end group |
6850 | 121 @end example |
3294 | 122 |
3368 | 123 @DOCSTRING(polyderiv) |
3294 | 124 |
6502 | 125 @DOCSTRING(polyder) |
126 | |
6898 | 127 @DOCSTRING(polyint) |
3294 | 128 |
11538
6eded7561d9d
Add undocumented polyaffine function to documentation.
Rik <octave@nomad.inbox5.com>
parents:
11536
diff
changeset
|
129 @DOCSTRING(polyaffine) |
6eded7561d9d
Add undocumented polyaffine function to documentation.
Rik <octave@nomad.inbox5.com>
parents:
11536
diff
changeset
|
130 |
6850 | 131 @node Polynomial Interpolation |
132 @section Polynomial Interpolation | |
3294 | 133 |
6850 | 134 Octave comes with good support for various kinds of interpolation, |
135 most of which are described in @ref{Interpolation}. One simple alternative | |
136 to the functions described in the aforementioned chapter, is to fit | |
137 a single polynomial to some given data points. To avoid a highly | |
138 fluctuating polynomial, one most often wants to fit a low-order polynomial | |
139 to data. This usually means that it is necessary to fit the polynomial | |
11536
702dbd0c53f5
Add undocumented ppder, ppint, ppjumps functions to documentation.
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
140 in a least-squares sense, which just is what the @code{polyfit} function does. |
3294 | 141 |
6850 | 142 @DOCSTRING(polyfit) |
3294 | 143 |
6850 | 144 In situations where a single polynomial isn't good enough, a solution |
145 is to use several polynomials pieced together. The function @code{mkpp} | |
11536
702dbd0c53f5
Add undocumented ppder, ppint, ppjumps functions to documentation.
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
146 creates a piecewise polynomial, @code{ppval} evaluates the function |
6850 | 147 created by @code{mkpp}, and @code{unmkpp} returns detailed information |
148 about the function. | |
149 | |
150 The following example shows how to combine two linear functions and a | |
7001 | 151 quadratic into one function. Each of these functions is expressed |
6850 | 152 on adjoined intervals. |
3294 | 153 |
6850 | 154 @example |
9070
e9dc2ed2ec0f
Cleanup documentation for poly.texi, interp.texi, geometry.texi
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
155 @group |
6850 | 156 x = [-2, -1, 1, 2]; |
157 p = [ 0, 1, 0; | |
158 1, -2, 1; | |
159 0, -1, 1 ]; | |
160 pp = mkpp(x, p); | |
161 xi = linspace(-2, 2, 50); | |
162 yi = ppval(pp, xi); | |
163 plot(xi, yi); | |
9070
e9dc2ed2ec0f
Cleanup documentation for poly.texi, interp.texi, geometry.texi
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
164 @end group |
6850 | 165 @end example |
6502 | 166 |
167 @DOCSTRING(mkpp) | |
168 | |
169 @DOCSTRING(unmkpp) | |
6850 | 170 |
11536
702dbd0c53f5
Add undocumented ppder, ppint, ppjumps functions to documentation.
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
171 @DOCSTRING(ppval) |
702dbd0c53f5
Add undocumented ppder, ppint, ppjumps functions to documentation.
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
172 |
702dbd0c53f5
Add undocumented ppder, ppint, ppjumps functions to documentation.
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
173 @DOCSTRING(ppder) |
702dbd0c53f5
Add undocumented ppder, ppint, ppjumps functions to documentation.
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
174 |
702dbd0c53f5
Add undocumented ppder, ppint, ppjumps functions to documentation.
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
175 @DOCSTRING(ppint) |
702dbd0c53f5
Add undocumented ppder, ppint, ppjumps functions to documentation.
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
176 |
702dbd0c53f5
Add undocumented ppder, ppint, ppjumps functions to documentation.
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
177 @DOCSTRING(ppjumps) |
702dbd0c53f5
Add undocumented ppder, ppint, ppjumps functions to documentation.
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
178 |
6850 | 179 @node Miscellaneous Functions |
180 @section Miscellaneous Functions | |
181 | |
182 @DOCSTRING(poly) | |
183 | |
184 @DOCSTRING(polyout) | |
185 | |
186 @DOCSTRING(polyreduce) | |
187 | |
188 | |
8286
6f2d95255911
fix @seealso references to point to existing anchors
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
7640
diff
changeset
|
189 |
6f2d95255911
fix @seealso references to point to existing anchors
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
7640
diff
changeset
|
190 |