Mercurial > hg > octave-nkf
annotate doc/interpreter/poly.txi @ 10224:f6e0404421f4
point to polyint in @seealso, not polyinteg
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Fri, 29 Jan 2010 12:52:32 -0500 |
parents | 923c7cb7f13f |
children | 72585f1ca7a2 |
rev | line source |
---|---|
8920 | 1 @c Copyright (C) 1996, 1997, 1999, 2000, 2002, 2007, 2008, 2009 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 | |
31 @ifinfo | |
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 |
37 @end ifinfo | |
38 | |
6850 | 39 @menu |
40 * Evaluating Polynomials:: | |
41 * Finding Roots:: | |
42 * Products of Polynomials:: | |
43 * Derivatives and Integrals:: | |
44 * Polynomial Interpolation:: | |
45 * Miscellaneous Functions:: | |
46 @end menu | |
47 | |
48 @node Evaluating Polynomials | |
49 @section Evaluating Polynomials | |
50 | |
51 The value of a polynomial represented by the vector @var{c} can be evaluated | |
8828 | 52 at the point @var{x} very easily, as the following example shows: |
6850 | 53 |
54 @example | |
9070
e9dc2ed2ec0f
Cleanup documentation for poly.texi, interp.texi, geometry.texi
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
55 @group |
6850 | 56 N = length(c)-1; |
57 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
|
58 @end group |
6850 | 59 @end example |
60 | |
61 @noindent | |
62 While the above example shows how easy it is to compute the value of a | |
63 polynomial, it isn't the most stable algorithm. With larger polynomials | |
64 you should use more elegant algorithms, such as Horner's Method, which | |
65 is exactly what the Octave function @code{polyval} does. | |
66 | |
67 In the case where @var{x} is a square matrix, the polynomial given by | |
68 @var{c} is still well-defined. As when @var{x} is a scalar the obvious | |
69 implementation is easily expressed in Octave, but also in this case | |
70 more elegant algorithms perform better. The @code{polyvalm} function | |
71 provides such an algorithm. | |
72 | |
73 @DOCSTRING(polyval) | |
74 | |
75 @DOCSTRING(polyvalm) | |
76 | |
77 @node Finding Roots | |
78 @section Finding Roots | |
79 | |
80 Octave can find the roots of a given polynomial. This is done by computing | |
81 the companion matrix of the polynomial (see the @code{compan} function | |
82 for a definition), and then finding its eigenvalues. | |
83 | |
84 @DOCSTRING(roots) | |
85 | |
3368 | 86 @DOCSTRING(compan) |
3294 | 87 |
8286
6f2d95255911
fix @seealso references to point to existing anchors
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
7640
diff
changeset
|
88 @DOCSTRING(mpoles) |
6f2d95255911
fix @seealso references to point to existing anchors
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
7640
diff
changeset
|
89 |
6850 | 90 @node Products of Polynomials |
91 @section Products of Polynomials | |
92 | |
3368 | 93 @DOCSTRING(conv) |
3294 | 94 |
7640 | 95 @DOCSTRING(convn) |
96 | |
3368 | 97 @DOCSTRING(deconv) |
3294 | 98 |
6549 | 99 @DOCSTRING(conv2) |
100 | |
6850 | 101 @DOCSTRING(polygcd) |
102 | |
103 @DOCSTRING(residue) | |
104 | |
105 @node Derivatives and Integrals | |
106 @section Derivatives and Integrals | |
107 | |
108 Octave comes with functions for computing the derivative and the integral | |
6898 | 109 of a polynomial. The functions @code{polyderiv} and @code{polyint} |
6850 | 110 both return new polynomials describing the result. As an example we'll |
111 compute the definite integral of @math{p(x) = x^2 + 1} from 0 to 3. | |
112 | |
113 @example | |
9070
e9dc2ed2ec0f
Cleanup documentation for poly.texi, interp.texi, geometry.texi
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
114 @group |
6850 | 115 c = [1, 0, 1]; |
6898 | 116 integral = polyint(c); |
6850 | 117 area = polyval(integral, 3) - polyval(integral, 0) |
118 @result{} 12 | |
9070
e9dc2ed2ec0f
Cleanup documentation for poly.texi, interp.texi, geometry.texi
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
119 @end group |
6850 | 120 @end example |
3294 | 121 |
3368 | 122 @DOCSTRING(polyderiv) |
3294 | 123 |
6502 | 124 @DOCSTRING(polyder) |
125 | |
6898 | 126 @DOCSTRING(polyint) |
3294 | 127 |
6850 | 128 @node Polynomial Interpolation |
129 @section Polynomial Interpolation | |
3294 | 130 |
6850 | 131 Octave comes with good support for various kinds of interpolation, |
132 most of which are described in @ref{Interpolation}. One simple alternative | |
133 to the functions described in the aforementioned chapter, is to fit | |
134 a single polynomial to some given data points. To avoid a highly | |
135 fluctuating polynomial, one most often wants to fit a low-order polynomial | |
136 to data. This usually means that it is necessary to fit the polynomial | |
137 in a least-squares sense, which is what the @code{polyfit} function does. | |
3294 | 138 |
6850 | 139 @DOCSTRING(polyfit) |
3294 | 140 |
6850 | 141 In situations where a single polynomial isn't good enough, a solution |
142 is to use several polynomials pieced together. The function @code{mkpp} | |
143 creates a piece-wise polynomial, @code{ppval} evaluates the function | |
144 created by @code{mkpp}, and @code{unmkpp} returns detailed information | |
145 about the function. | |
146 | |
147 The following example shows how to combine two linear functions and a | |
7001 | 148 quadratic into one function. Each of these functions is expressed |
6850 | 149 on adjoined intervals. |
3294 | 150 |
6850 | 151 @example |
9070
e9dc2ed2ec0f
Cleanup documentation for poly.texi, interp.texi, geometry.texi
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
152 @group |
6850 | 153 x = [-2, -1, 1, 2]; |
154 p = [ 0, 1, 0; | |
155 1, -2, 1; | |
156 0, -1, 1 ]; | |
157 pp = mkpp(x, p); | |
158 xi = linspace(-2, 2, 50); | |
159 yi = ppval(pp, xi); | |
160 plot(xi, yi); | |
9070
e9dc2ed2ec0f
Cleanup documentation for poly.texi, interp.texi, geometry.texi
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
161 @end group |
6850 | 162 @end example |
6502 | 163 |
164 @DOCSTRING(ppval) | |
165 | |
166 @DOCSTRING(mkpp) | |
167 | |
168 @DOCSTRING(unmkpp) | |
6850 | 169 |
170 @node Miscellaneous Functions | |
171 @section Miscellaneous Functions | |
172 | |
173 @DOCSTRING(poly) | |
174 | |
175 @DOCSTRING(polyout) | |
176 | |
177 @DOCSTRING(polyreduce) | |
178 | |
179 | |
8286
6f2d95255911
fix @seealso references to point to existing anchors
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
7640
diff
changeset
|
180 |
6f2d95255911
fix @seealso references to point to existing anchors
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
7640
diff
changeset
|
181 |