annotate doc/interpreter/poly.txi @ 20595:c1a6c31ac29a

eliminate more simple uses of error_state * ov-classdef.cc: Eliminate simple uses of error_state.
author John W. Eaton <jwe@octave.org>
date Tue, 06 Oct 2015 00:20:02 -0400
parents 4197fc428c7d
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
19731
4197fc428c7d maint: Update copyright notices for 2015.
John W. Eaton <jwe@octave.org>
parents: 19627
diff changeset
1 @c Copyright (C) 1996-2015 John W. Eaton
7018
fd42779a8428 [project @ 2007-10-13 00:52:12 by jwe]
jwe
parents: 7001
diff changeset
2 @c
fd42779a8428 [project @ 2007-10-13 00:52:12 by jwe]
jwe
parents: 7001
diff changeset
3 @c This file is part of Octave.
fd42779a8428 [project @ 2007-10-13 00:52:12 by jwe]
jwe
parents: 7001
diff changeset
4 @c
fd42779a8428 [project @ 2007-10-13 00:52:12 by jwe]
jwe
parents: 7001
diff changeset
5 @c Octave is free software; you can redistribute it and/or modify it
fd42779a8428 [project @ 2007-10-13 00:52:12 by jwe]
jwe
parents: 7001
diff changeset
6 @c under the terms of the GNU General Public License as published by the
fd42779a8428 [project @ 2007-10-13 00:52:12 by jwe]
jwe
parents: 7001
diff changeset
7 @c Free Software Foundation; either version 3 of the License, or (at
fd42779a8428 [project @ 2007-10-13 00:52:12 by jwe]
jwe
parents: 7001
diff changeset
8 @c your option) any later version.
19627
446c46af4b42 strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents: 17744
diff changeset
9 @c
7018
fd42779a8428 [project @ 2007-10-13 00:52:12 by jwe]
jwe
parents: 7001
diff changeset
10 @c Octave is distributed in the hope that it will be useful, but WITHOUT
fd42779a8428 [project @ 2007-10-13 00:52:12 by jwe]
jwe
parents: 7001
diff changeset
11 @c ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
fd42779a8428 [project @ 2007-10-13 00:52:12 by jwe]
jwe
parents: 7001
diff changeset
12 @c FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
fd42779a8428 [project @ 2007-10-13 00:52:12 by jwe]
jwe
parents: 7001
diff changeset
13 @c for more details.
19627
446c46af4b42 strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents: 17744
diff changeset
14 @c
7018
fd42779a8428 [project @ 2007-10-13 00:52:12 by jwe]
jwe
parents: 7001
diff changeset
15 @c You should have received a copy of the GNU General Public License
fd42779a8428 [project @ 2007-10-13 00:52:12 by jwe]
jwe
parents: 7001
diff changeset
16 @c along with Octave; see the file COPYING. If not, see
fd42779a8428 [project @ 2007-10-13 00:52:12 by jwe]
jwe
parents: 7001
diff changeset
17 @c <http://www.gnu.org/licenses/>.
3294
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
18
4167
aae05d51353c [project @ 2002-11-12 02:52:50 by jwe]
jwe
parents: 3428
diff changeset
19 @node Polynomial Manipulations
3294
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
20 @chapter Polynomial Manipulations
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
21
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
22 In Octave, a polynomial is represented by its coefficients (arranged
6850
9398f6a81bdf [project @ 2007-08-31 17:29:22 by jwe]
jwe
parents: 6778
diff changeset
23 in descending order). For example, a vector @var{c} of length
9398f6a81bdf [project @ 2007-08-31 17:29:22 by jwe]
jwe
parents: 6778
diff changeset
24 @math{N+1} corresponds to the following polynomial of order
3294
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
25 @tex
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
26 $N$
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
27 $$
6850
9398f6a81bdf [project @ 2007-08-31 17:29:22 by jwe]
jwe
parents: 6778
diff changeset
28 p (x) = c_1 x^N + \ldots + c_N x + c_{N+1}.
3294
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
29 $$
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
30 @end tex
10668
72585f1ca7a2 Replace @ifinfo with @ifnottex.
Rik <octave@nomad.inbox5.com>
parents: 10224
diff changeset
31 @ifnottex
3294
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
32 @var{N}
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
33
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
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
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
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
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
39
6850
9398f6a81bdf [project @ 2007-08-31 17:29:22 by jwe]
jwe
parents: 6778
diff changeset
40 @menu
9398f6a81bdf [project @ 2007-08-31 17:29:22 by jwe]
jwe
parents: 6778
diff changeset
41 * Evaluating Polynomials::
9398f6a81bdf [project @ 2007-08-31 17:29:22 by jwe]
jwe
parents: 6778
diff changeset
42 * Finding Roots::
9398f6a81bdf [project @ 2007-08-31 17:29:22 by jwe]
jwe
parents: 6778
diff changeset
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
9398f6a81bdf [project @ 2007-08-31 17:29:22 by jwe]
jwe
parents: 6778
diff changeset
45 * Polynomial Interpolation::
9398f6a81bdf [project @ 2007-08-31 17:29:22 by jwe]
jwe
parents: 6778
diff changeset
46 * Miscellaneous Functions::
9398f6a81bdf [project @ 2007-08-31 17:29:22 by jwe]
jwe
parents: 6778
diff changeset
47 @end menu
9398f6a81bdf [project @ 2007-08-31 17:29:22 by jwe]
jwe
parents: 6778
diff changeset
48
9398f6a81bdf [project @ 2007-08-31 17:29:22 by jwe]
jwe
parents: 6778
diff changeset
49 @node Evaluating Polynomials
9398f6a81bdf [project @ 2007-08-31 17:29:22 by jwe]
jwe
parents: 6778
diff changeset
50 @section Evaluating Polynomials
9398f6a81bdf [project @ 2007-08-31 17:29:22 by jwe]
jwe
parents: 6778
diff changeset
51
9398f6a81bdf [project @ 2007-08-31 17:29:22 by jwe]
jwe
parents: 6778
diff changeset
52 The value of a polynomial represented by the vector @var{c} can be evaluated
8828
8463d1a2e544 Doc fixes.
Brian Gough <bjg@network-theory.co.uk>
parents: 8286
diff changeset
53 at the point @var{x} very easily, as the following example shows:
6850
9398f6a81bdf [project @ 2007-08-31 17:29:22 by jwe]
jwe
parents: 6778
diff changeset
54
9398f6a81bdf [project @ 2007-08-31 17:29:22 by jwe]
jwe
parents: 6778
diff changeset
55 @example
9070
e9dc2ed2ec0f Cleanup documentation for poly.texi, interp.texi, geometry.texi
Rik <rdrider0-list@yahoo.com>
parents: 8920
diff changeset
56 @group
14856
c3fd61c59e9c maint: Use Octave coding conventions for cuddling parentheses in doc directory
Rik <octave@nomad.inbox5.com>
parents: 14853
diff changeset
57 N = length (c) - 1;
c3fd61c59e9c maint: Use Octave coding conventions for cuddling parentheses in doc directory
Rik <octave@nomad.inbox5.com>
parents: 14853
diff changeset
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
9398f6a81bdf [project @ 2007-08-31 17:29:22 by jwe]
jwe
parents: 6778
diff changeset
60 @end example
9398f6a81bdf [project @ 2007-08-31 17:29:22 by jwe]
jwe
parents: 6778
diff changeset
61
9398f6a81bdf [project @ 2007-08-31 17:29:22 by jwe]
jwe
parents: 6778
diff changeset
62 @noindent
9398f6a81bdf [project @ 2007-08-31 17:29:22 by jwe]
jwe
parents: 6778
diff changeset
63 While the above example shows how easy it is to compute the value of a
9398f6a81bdf [project @ 2007-08-31 17:29:22 by jwe]
jwe
parents: 6778
diff changeset
64 polynomial, it isn't the most stable algorithm. With larger polynomials
9398f6a81bdf [project @ 2007-08-31 17:29:22 by jwe]
jwe
parents: 6778
diff changeset
65 you should use more elegant algorithms, such as Horner's Method, which
9398f6a81bdf [project @ 2007-08-31 17:29:22 by jwe]
jwe
parents: 6778
diff changeset
66 is exactly what the Octave function @code{polyval} does.
9398f6a81bdf [project @ 2007-08-31 17:29:22 by jwe]
jwe
parents: 6778
diff changeset
67
9398f6a81bdf [project @ 2007-08-31 17:29:22 by jwe]
jwe
parents: 6778
diff changeset
68 In the case where @var{x} is a square matrix, the polynomial given by
9398f6a81bdf [project @ 2007-08-31 17:29:22 by jwe]
jwe
parents: 6778
diff changeset
69 @var{c} is still well-defined. As when @var{x} is a scalar the obvious
9398f6a81bdf [project @ 2007-08-31 17:29:22 by jwe]
jwe
parents: 6778
diff changeset
70 implementation is easily expressed in Octave, but also in this case
9398f6a81bdf [project @ 2007-08-31 17:29:22 by jwe]
jwe
parents: 6778
diff changeset
71 more elegant algorithms perform better. The @code{polyvalm} function
9398f6a81bdf [project @ 2007-08-31 17:29:22 by jwe]
jwe
parents: 6778
diff changeset
72 provides such an algorithm.
9398f6a81bdf [project @ 2007-08-31 17:29:22 by jwe]
jwe
parents: 6778
diff changeset
73
9398f6a81bdf [project @ 2007-08-31 17:29:22 by jwe]
jwe
parents: 6778
diff changeset
74 @DOCSTRING(polyval)
9398f6a81bdf [project @ 2007-08-31 17:29:22 by jwe]
jwe
parents: 6778
diff changeset
75
9398f6a81bdf [project @ 2007-08-31 17:29:22 by jwe]
jwe
parents: 6778
diff changeset
76 @DOCSTRING(polyvalm)
9398f6a81bdf [project @ 2007-08-31 17:29:22 by jwe]
jwe
parents: 6778
diff changeset
77
9398f6a81bdf [project @ 2007-08-31 17:29:22 by jwe]
jwe
parents: 6778
diff changeset
78 @node Finding Roots
9398f6a81bdf [project @ 2007-08-31 17:29:22 by jwe]
jwe
parents: 6778
diff changeset
79 @section Finding Roots
9398f6a81bdf [project @ 2007-08-31 17:29:22 by jwe]
jwe
parents: 6778
diff changeset
80
9398f6a81bdf [project @ 2007-08-31 17:29:22 by jwe]
jwe
parents: 6778
diff changeset
81 Octave can find the roots of a given polynomial. This is done by computing
9398f6a81bdf [project @ 2007-08-31 17:29:22 by jwe]
jwe
parents: 6778
diff changeset
82 the companion matrix of the polynomial (see the @code{compan} function
9398f6a81bdf [project @ 2007-08-31 17:29:22 by jwe]
jwe
parents: 6778
diff changeset
83 for a definition), and then finding its eigenvalues.
9398f6a81bdf [project @ 2007-08-31 17:29:22 by jwe]
jwe
parents: 6778
diff changeset
84
9398f6a81bdf [project @ 2007-08-31 17:29:22 by jwe]
jwe
parents: 6778
diff changeset
85 @DOCSTRING(roots)
9398f6a81bdf [project @ 2007-08-31 17:29:22 by jwe]
jwe
parents: 6778
diff changeset
86
15186
504fec921af5 polyeig: new function
Fotios Kasolis <fotios.kasolis@gmail.com>
parents: 14856
diff changeset
87 @DOCSTRING(polyeig)
504fec921af5 polyeig: new function
Fotios Kasolis <fotios.kasolis@gmail.com>
parents: 14856
diff changeset
88
3368
a4cd1e9d9962 [project @ 1999-11-20 17:22:48 by jwe]
jwe
parents: 3294
diff changeset
89 @DOCSTRING(compan)
3294
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
90
8286
6f2d95255911 fix @seealso references to point to existing anchors
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 7640
diff changeset
91 @DOCSTRING(mpoles)
6f2d95255911 fix @seealso references to point to existing anchors
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 7640
diff changeset
92
6850
9398f6a81bdf [project @ 2007-08-31 17:29:22 by jwe]
jwe
parents: 6778
diff changeset
93 @node Products of Polynomials
9398f6a81bdf [project @ 2007-08-31 17:29:22 by jwe]
jwe
parents: 6778
diff changeset
94 @section Products of Polynomials
9398f6a81bdf [project @ 2007-08-31 17:29:22 by jwe]
jwe
parents: 6778
diff changeset
95
3368
a4cd1e9d9962 [project @ 1999-11-20 17:22:48 by jwe]
jwe
parents: 3294
diff changeset
96 @DOCSTRING(conv)
3294
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
97
7640
3398ce778b4b Added support for N-dimensional convolution
sh@sh-laptop
parents: 7018
diff changeset
98 @DOCSTRING(convn)
3398ce778b4b Added support for N-dimensional convolution
sh@sh-laptop
parents: 7018
diff changeset
99
3368
a4cd1e9d9962 [project @ 1999-11-20 17:22:48 by jwe]
jwe
parents: 3294
diff changeset
100 @DOCSTRING(deconv)
3294
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
101
6549
5a5a09d7deb8 [project @ 2007-04-20 06:55:29 by jwe]
jwe
parents: 6502
diff changeset
102 @DOCSTRING(conv2)
5a5a09d7deb8 [project @ 2007-04-20 06:55:29 by jwe]
jwe
parents: 6502
diff changeset
103
6850
9398f6a81bdf [project @ 2007-08-31 17:29:22 by jwe]
jwe
parents: 6778
diff changeset
104 @DOCSTRING(polygcd)
9398f6a81bdf [project @ 2007-08-31 17:29:22 by jwe]
jwe
parents: 6778
diff changeset
105
9398f6a81bdf [project @ 2007-08-31 17:29:22 by jwe]
jwe
parents: 6778
diff changeset
106 @DOCSTRING(residue)
9398f6a81bdf [project @ 2007-08-31 17:29:22 by jwe]
jwe
parents: 6778
diff changeset
107
11538
6eded7561d9d Add undocumented polyaffine function to documentation.
Rik <octave@nomad.inbox5.com>
parents: 11536
diff changeset
108 @node Derivatives / Integrals / Transforms
6eded7561d9d Add undocumented polyaffine function to documentation.
Rik <octave@nomad.inbox5.com>
parents: 11536
diff changeset
109 @section Derivatives / Integrals / Transforms
6850
9398f6a81bdf [project @ 2007-08-31 17:29:22 by jwe]
jwe
parents: 6778
diff changeset
110
9398f6a81bdf [project @ 2007-08-31 17:29:22 by jwe]
jwe
parents: 6778
diff changeset
111 Octave comes with functions for computing the derivative and the integral
13963
663594b481e5 doc: Remove documentation references to deprecated functions cut() and polyderiv()
Rik <octave@nomad.inbox5.com>
parents: 11538
diff changeset
112 of a polynomial. The functions @code{polyder} and @code{polyint}
6850
9398f6a81bdf [project @ 2007-08-31 17:29:22 by jwe]
jwe
parents: 6778
diff changeset
113 both return new polynomials describing the result. As an example we'll
9398f6a81bdf [project @ 2007-08-31 17:29:22 by jwe]
jwe
parents: 6778
diff changeset
114 compute the definite integral of @math{p(x) = x^2 + 1} from 0 to 3.
9398f6a81bdf [project @ 2007-08-31 17:29:22 by jwe]
jwe
parents: 6778
diff changeset
115
9398f6a81bdf [project @ 2007-08-31 17:29:22 by jwe]
jwe
parents: 6778
diff changeset
116 @example
9070
e9dc2ed2ec0f Cleanup documentation for poly.texi, interp.texi, geometry.texi
Rik <rdrider0-list@yahoo.com>
parents: 8920
diff changeset
117 @group
6850
9398f6a81bdf [project @ 2007-08-31 17:29:22 by jwe]
jwe
parents: 6778
diff changeset
118 c = [1, 0, 1];
14856
c3fd61c59e9c maint: Use Octave coding conventions for cuddling parentheses in doc directory
Rik <octave@nomad.inbox5.com>
parents: 14853
diff changeset
119 integral = polyint (c);
c3fd61c59e9c maint: Use Octave coding conventions for cuddling parentheses in doc directory
Rik <octave@nomad.inbox5.com>
parents: 14853
diff changeset
120 area = polyval (integral, 3) - polyval (integral, 0)
6850
9398f6a81bdf [project @ 2007-08-31 17:29:22 by jwe]
jwe
parents: 6778
diff changeset
121 @result{} 12
9070
e9dc2ed2ec0f Cleanup documentation for poly.texi, interp.texi, geometry.texi
Rik <rdrider0-list@yahoo.com>
parents: 8920
diff changeset
122 @end group
6850
9398f6a81bdf [project @ 2007-08-31 17:29:22 by jwe]
jwe
parents: 6778
diff changeset
123 @end example
3294
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
124
6502
6ab0a8767780 [project @ 2007-04-06 03:32:06 by jwe]
jwe
parents: 4167
diff changeset
125 @DOCSTRING(polyder)
6ab0a8767780 [project @ 2007-04-06 03:32:06 by jwe]
jwe
parents: 4167
diff changeset
126
6898
f4e1bdb66535 [project @ 2007-09-14 05:20:43 by jwe]
jwe
parents: 6850
diff changeset
127 @DOCSTRING(polyint)
3294
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
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
9398f6a81bdf [project @ 2007-08-31 17:29:22 by jwe]
jwe
parents: 6778
diff changeset
131 @node Polynomial Interpolation
9398f6a81bdf [project @ 2007-08-31 17:29:22 by jwe]
jwe
parents: 6778
diff changeset
132 @section Polynomial Interpolation
3294
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
133
6850
9398f6a81bdf [project @ 2007-08-31 17:29:22 by jwe]
jwe
parents: 6778
diff changeset
134 Octave comes with good support for various kinds of interpolation,
9398f6a81bdf [project @ 2007-08-31 17:29:22 by jwe]
jwe
parents: 6778
diff changeset
135 most of which are described in @ref{Interpolation}. One simple alternative
9398f6a81bdf [project @ 2007-08-31 17:29:22 by jwe]
jwe
parents: 6778
diff changeset
136 to the functions described in the aforementioned chapter, is to fit
14509
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents: 14138
diff changeset
137 a single polynomial, or a piecewise polynomial (spline) to some given
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents: 14138
diff changeset
138 data points. To avoid a highly fluctuating polynomial, one most often
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents: 14138
diff changeset
139 wants to fit a low-order polynomial to data. This usually means that it
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents: 14138
diff changeset
140 is necessary to fit the polynomial in a least-squares sense, which just
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents: 14138
diff changeset
141 is what the @code{polyfit} function does.
3294
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
142
6850
9398f6a81bdf [project @ 2007-08-31 17:29:22 by jwe]
jwe
parents: 6778
diff changeset
143 @DOCSTRING(polyfit)
3294
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
144
6850
9398f6a81bdf [project @ 2007-08-31 17:29:22 by jwe]
jwe
parents: 6778
diff changeset
145 In situations where a single polynomial isn't good enough, a solution
14509
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents: 14138
diff changeset
146 is to use several polynomials pieced together. The function
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents: 14138
diff changeset
147 @code{splinefit} fits a peicewise polynomial (spline) to a set of
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents: 14138
diff changeset
148 data.
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents: 14138
diff changeset
149
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents: 14138
diff changeset
150 @DOCSTRING(splinefit)
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents: 14138
diff changeset
151
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents: 14138
diff changeset
152 The number of @var{breaks} (or knots) used to construct the piecewise
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents: 14138
diff changeset
153 polynomial is a significant factor in suppressing the noise present in
14853
72b8b39e12be doc: Periodic grammarcheck of documentation.
Rik <octave@nomad.inbox5.com>
parents: 14551
diff changeset
154 the input data, @var{x} and @var{y}. This is demonstrated by the example
14509
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents: 14138
diff changeset
155 below.
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents: 14138
diff changeset
156
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents: 14138
diff changeset
157 @example
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents: 14138
diff changeset
158 @group
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents: 14138
diff changeset
159 x = 2 * pi * rand (1, 200);
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents: 14138
diff changeset
160 y = sin (x) + sin (2 * x) + 0.2 * randn (size (x));
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents: 14138
diff changeset
161 ## Uniform breaks
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents: 14138
diff changeset
162 breaks = linspace (0, 2 * pi, 41); % 41 breaks, 40 pieces
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents: 14138
diff changeset
163 pp1 = splinefit (x, y, breaks);
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents: 14138
diff changeset
164 ## Breaks interpolated from data
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents: 14138
diff changeset
165 pp2 = splinefit (x, y, 10); % 11 breaks, 10 pieces
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents: 14138
diff changeset
166 ## Plot
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents: 14138
diff changeset
167 xx = linspace (0, 2 * pi, 400);
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents: 14138
diff changeset
168 y1 = ppval (pp1, xx);
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents: 14138
diff changeset
169 y2 = ppval (pp2, xx);
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents: 14138
diff changeset
170 plot (x, y, ".", xx, [y1; y2])
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents: 14138
diff changeset
171 axis tight
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents: 14138
diff changeset
172 ylim auto
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents: 14138
diff changeset
173 legend (@{"data", "41 breaks, 40 pieces", "11 breaks, 10 pieces"@})
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents: 14138
diff changeset
174 @end group
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents: 14138
diff changeset
175 @end example
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents: 14138
diff changeset
176
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents: 14138
diff changeset
177 @ifnotinfo
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents: 14138
diff changeset
178 @noindent
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents: 14138
diff changeset
179 The result of which can be seen in @ref{fig:splinefit1}.
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents: 14138
diff changeset
180
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents: 14138
diff changeset
181 @float Figure,fig:splinefit1
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents: 14138
diff changeset
182 @center @image{splinefit1,4in}
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents: 14138
diff changeset
183 @caption{Comparison of a fitting a piecewise polynomial with 41 breaks to one
14853
72b8b39e12be doc: Periodic grammarcheck of documentation.
Rik <octave@nomad.inbox5.com>
parents: 14551
diff changeset
184 with 11 breaks. The fit with the large number of breaks exhibits a fast ripple
14509
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents: 14138
diff changeset
185 that is not present in the underlying function.}
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents: 14138
diff changeset
186 @end float
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents: 14138
diff changeset
187 @end ifnotinfo
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents: 14138
diff changeset
188
14853
72b8b39e12be doc: Periodic grammarcheck of documentation.
Rik <octave@nomad.inbox5.com>
parents: 14551
diff changeset
189 The piecewise polynomial fit, provided by @code{splinefit}, has
72b8b39e12be doc: Periodic grammarcheck of documentation.
Rik <octave@nomad.inbox5.com>
parents: 14551
diff changeset
190 continuous derivatives up to the @var{order}-1. For example, a cubic fit
72b8b39e12be doc: Periodic grammarcheck of documentation.
Rik <octave@nomad.inbox5.com>
parents: 14551
diff changeset
191 has continuous first and second derivatives. This is demonstrated by
14551
60ed9260399a Improve/correct documentation for splinefit.m
Ben Abbott <bpabbott@mac.com>
parents: 14531
diff changeset
192 the code
14509
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents: 14138
diff changeset
193
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents: 14138
diff changeset
194 @example
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents: 14138
diff changeset
195 ## Data (200 points)
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents: 14138
diff changeset
196 x = 2 * pi * rand (1, 200);
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents: 14138
diff changeset
197 y = sin (x) + sin (2 * x) + 0.1 * randn (size (x));
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents: 14138
diff changeset
198 ## Piecewise constant
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents: 14138
diff changeset
199 pp1 = splinefit (x, y, 8, "order", 0);
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents: 14138
diff changeset
200 ## Piecewise linear
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents: 14138
diff changeset
201 pp2 = splinefit (x, y, 8, "order", 1);
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents: 14138
diff changeset
202 ## Piecewise quadratic
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents: 14138
diff changeset
203 pp3 = splinefit (x, y, 8, "order", 2);
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents: 14138
diff changeset
204 ## Piecewise cubic
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents: 14138
diff changeset
205 pp4 = splinefit (x, y, 8, "order", 3);
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents: 14138
diff changeset
206 ## Piecewise quartic
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents: 14138
diff changeset
207 pp5 = splinefit (x, y, 8, "order", 4);
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents: 14138
diff changeset
208 ## Plot
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents: 14138
diff changeset
209 xx = linspace (0, 2 * pi, 400);
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents: 14138
diff changeset
210 y1 = ppval (pp1, xx);
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents: 14138
diff changeset
211 y2 = ppval (pp2, xx);
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents: 14138
diff changeset
212 y3 = ppval (pp3, xx);
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents: 14138
diff changeset
213 y4 = ppval (pp4, xx);
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents: 14138
diff changeset
214 y5 = ppval (pp5, xx);
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents: 14138
diff changeset
215 plot (x, y, ".", xx, [y1; y2; y3; y4; y5])
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents: 14138
diff changeset
216 axis tight
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents: 14138
diff changeset
217 ylim auto
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents: 14138
diff changeset
218 legend (@{"data", "order 0", "order 1", "order 2", "order 3", "order 4"@})
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents: 14138
diff changeset
219 @end example
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents: 14138
diff changeset
220
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents: 14138
diff changeset
221 @ifnotinfo
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents: 14138
diff changeset
222 @noindent
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents: 14138
diff changeset
223 The result of which can be seen in @ref{fig:splinefit2}.
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents: 14138
diff changeset
224
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents: 14138
diff changeset
225 @float Figure,fig:splinefit2
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents: 14138
diff changeset
226 @center @image{splinefit2,4in}
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents: 14138
diff changeset
227 @caption{Comparison of a piecewise constant, linear, quadratic, cubic, and
14853
72b8b39e12be doc: Periodic grammarcheck of documentation.
Rik <octave@nomad.inbox5.com>
parents: 14551
diff changeset
228 quartic polynomials with 8 breaks to noisy data. The higher order solutions
14509
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents: 14138
diff changeset
229 more accurately represent the underlying function, but come with the
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents: 14138
diff changeset
230 expense of computational complexity.}
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents: 14138
diff changeset
231 @end float
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents: 14138
diff changeset
232 @end ifnotinfo
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents: 14138
diff changeset
233
14531
8985cbbd2fe4 doc: Periodic spellcheck of documentation
Rik <octave@nomad.inbox5.com>
parents: 14509
diff changeset
234 When the underlying function to provide a fit to is periodic, @code{splinefit}
14509
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents: 14138
diff changeset
235 is able to apply the boundary conditions needed to manifest a periodic fit.
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents: 14138
diff changeset
236 This is demonstrated by the code below.
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents: 14138
diff changeset
237
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents: 14138
diff changeset
238 @example
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents: 14138
diff changeset
239 @group
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents: 14138
diff changeset
240 ## Data (100 points)
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents: 14138
diff changeset
241 x = 2 * pi * [0, (rand (1, 98)), 1];
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents: 14138
diff changeset
242 y = sin (x) - cos (2 * x) + 0.2 * randn (size (x));
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents: 14138
diff changeset
243 ## No constraints
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents: 14138
diff changeset
244 pp1 = splinefit (x, y, 10, "order", 5);
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents: 14138
diff changeset
245 ## Periodic boundaries
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents: 14138
diff changeset
246 pp2 = splinefit (x, y, 10, "order", 5, "periodic", true);
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents: 14138
diff changeset
247 ## Plot
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents: 14138
diff changeset
248 xx = linspace (0, 2 * pi, 400);
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents: 14138
diff changeset
249 y1 = ppval (pp1, xx);
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents: 14138
diff changeset
250 y2 = ppval (pp2, xx);
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents: 14138
diff changeset
251 plot (x, y, ".", xx, [y1; y2])
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents: 14138
diff changeset
252 axis tight
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents: 14138
diff changeset
253 ylim auto
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents: 14138
diff changeset
254 legend (@{"data", "no constraints", "periodic"@})
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents: 14138
diff changeset
255 @end group
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents: 14138
diff changeset
256 @end example
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents: 14138
diff changeset
257
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents: 14138
diff changeset
258 @ifnotinfo
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents: 14138
diff changeset
259 @noindent
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents: 14138
diff changeset
260 The result of which can be seen in @ref{fig:splinefit3}.
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents: 14138
diff changeset
261
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents: 14138
diff changeset
262 @float Figure,fig:splinefit3
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents: 14138
diff changeset
263 @center @image{splinefit3,4in}
14551
60ed9260399a Improve/correct documentation for splinefit.m
Ben Abbott <bpabbott@mac.com>
parents: 14531
diff changeset
264 @caption{Comparison of piecewise polynomial fits to a noisy periodic
60ed9260399a Improve/correct documentation for splinefit.m
Ben Abbott <bpabbott@mac.com>
parents: 14531
diff changeset
265 function with, and without, periodic boundary conditions.}
14509
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents: 14138
diff changeset
266 @end float
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents: 14138
diff changeset
267 @end ifnotinfo
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents: 14138
diff changeset
268
14853
72b8b39e12be doc: Periodic grammarcheck of documentation.
Rik <octave@nomad.inbox5.com>
parents: 14551
diff changeset
269 More complex constraints may be added as well. For example, the code below
72b8b39e12be doc: Periodic grammarcheck of documentation.
Rik <octave@nomad.inbox5.com>
parents: 14551
diff changeset
270 illustrates a periodic fit with values that have been clamped at the endpoints,
72b8b39e12be doc: Periodic grammarcheck of documentation.
Rik <octave@nomad.inbox5.com>
parents: 14551
diff changeset
271 and a second periodic fit which is hinged at the endpoints.
14509
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents: 14138
diff changeset
272
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents: 14138
diff changeset
273 @example
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents: 14138
diff changeset
274 ## Data (200 points)
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents: 14138
diff changeset
275 x = 2 * pi * rand (1, 200);
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents: 14138
diff changeset
276 y = sin (2 * x) + 0.1 * randn (size (x));
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents: 14138
diff changeset
277 ## Breaks
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents: 14138
diff changeset
278 breaks = linspace (0, 2 * pi, 10);
14551
60ed9260399a Improve/correct documentation for splinefit.m
Ben Abbott <bpabbott@mac.com>
parents: 14531
diff changeset
279 ## Clamped endpoints, y = y' = 0
14509
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents: 14138
diff changeset
280 xc = [0, 0, 2*pi, 2*pi];
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents: 14138
diff changeset
281 cc = [(eye (2)), (eye (2))];
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents: 14138
diff changeset
282 con = struct ("xc", xc, "cc", cc);
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents: 14138
diff changeset
283 pp1 = splinefit (x, y, breaks, "constraints", con);
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents: 14138
diff changeset
284 ## Hinged periodic endpoints, y = 0
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents: 14138
diff changeset
285 con = struct ("xc", 0);
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents: 14138
diff changeset
286 pp2 = splinefit (x, y, breaks, "constraints", con, "periodic", true);
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents: 14138
diff changeset
287 ## Plot
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents: 14138
diff changeset
288 xx = linspace (0, 2 * pi, 400);
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents: 14138
diff changeset
289 y1 = ppval (pp1, xx);
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents: 14138
diff changeset
290 y2 = ppval (pp2, xx);
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents: 14138
diff changeset
291 plot (x, y, ".", xx, [y1; y2])
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents: 14138
diff changeset
292 axis tight
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents: 14138
diff changeset
293 ylim auto
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents: 14138
diff changeset
294 legend (@{"data", "clamped", "hinged periodic"@})
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents: 14138
diff changeset
295 @end example
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents: 14138
diff changeset
296
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents: 14138
diff changeset
297 @ifnotinfo
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents: 14138
diff changeset
298 @noindent
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents: 14138
diff changeset
299 The result of which can be seen in @ref{fig:splinefit4}.
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents: 14138
diff changeset
300
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents: 14138
diff changeset
301 @float Figure,fig:splinefit4
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents: 14138
diff changeset
302 @center @image{splinefit4,4in}
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents: 14138
diff changeset
303 @caption{Comparison of two periodic piecewise cubic fits to a noisy periodic
14853
72b8b39e12be doc: Periodic grammarcheck of documentation.
Rik <octave@nomad.inbox5.com>
parents: 14551
diff changeset
304 signal. One fit has its endpoints clamped and the second has its endpoints
14509
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents: 14138
diff changeset
305 hinged.}
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents: 14138
diff changeset
306 @end float
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents: 14138
diff changeset
307 @end ifnotinfo
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents: 14138
diff changeset
308
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents: 14138
diff changeset
309 The @code{splinefit} function also provides the convenience of a @var{robust}
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents: 14138
diff changeset
310 fitting, where the effect of outlying data is reduced. In the example below,
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents: 14138
diff changeset
311 three different fits are provided. Two with differing levels of outlier
14531
8985cbbd2fe4 doc: Periodic spellcheck of documentation
Rik <octave@nomad.inbox5.com>
parents: 14509
diff changeset
312 suppression and a third illustrating the non-robust solution.
14509
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents: 14138
diff changeset
313
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents: 14138
diff changeset
314 @example
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents: 14138
diff changeset
315 ## Data
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents: 14138
diff changeset
316 x = linspace (0, 2*pi, 200);
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents: 14138
diff changeset
317 y = sin (x) + sin (2 * x) + 0.05 * randn (size (x));
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents: 14138
diff changeset
318 ## Add outliers
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents: 14138
diff changeset
319 x = [x, linspace(0,2*pi,60)];
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents: 14138
diff changeset
320 y = [y, -ones(1,60)];
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents: 14138
diff changeset
321 ## Fit splines with hinged conditions
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents: 14138
diff changeset
322 con = struct ("xc", [0, 2*pi]);
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents: 14138
diff changeset
323 ## Robust fitting, beta = 0.25
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents: 14138
diff changeset
324 pp1 = splinefit (x, y, 8, "constraints", con, "beta", 0.25);
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents: 14138
diff changeset
325 ## Robust fitting, beta = 0.75
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents: 14138
diff changeset
326 pp2 = splinefit (x, y, 8, "constraints", con, "beta", 0.75);
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents: 14138
diff changeset
327 ## No robust fitting
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents: 14138
diff changeset
328 pp3 = splinefit (x, y, 8, "constraints", con);
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents: 14138
diff changeset
329 ## Plot
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents: 14138
diff changeset
330 xx = linspace (0, 2*pi, 400);
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents: 14138
diff changeset
331 y1 = ppval (pp1, xx);
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents: 14138
diff changeset
332 y2 = ppval (pp2, xx);
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents: 14138
diff changeset
333 y3 = ppval (pp3, xx);
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents: 14138
diff changeset
334 plot (x, y, ".", xx, [y1; y2; y3])
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents: 14138
diff changeset
335 legend (@{"data with outliers","robust, beta = 0.25", ...
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents: 14138
diff changeset
336 "robust, beta = 0.75", "no robust fitting"@})
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents: 14138
diff changeset
337 axis tight
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents: 14138
diff changeset
338 ylim auto
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents: 14138
diff changeset
339 @end example
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents: 14138
diff changeset
340
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents: 14138
diff changeset
341 @ifnotinfo
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents: 14138
diff changeset
342 @noindent
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents: 14138
diff changeset
343 The result of which can be seen in @ref{fig:splinefit6}.
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents: 14138
diff changeset
344
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents: 14138
diff changeset
345 @float Figure,fig:splinefit6
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents: 14138
diff changeset
346 @center @image{splinefit6,4in}
14853
72b8b39e12be doc: Periodic grammarcheck of documentation.
Rik <octave@nomad.inbox5.com>
parents: 14551
diff changeset
347 @caption{Comparison of two different levels of robust fitting (@var{beta} = 0.25 and 0.75) to noisy data combined with outlying data. A conventional fit, without
14551
60ed9260399a Improve/correct documentation for splinefit.m
Ben Abbott <bpabbott@mac.com>
parents: 14531
diff changeset
348 robust fitting (@var{beta} = 0) is also included.}
14509
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents: 14138
diff changeset
349 @end float
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents: 14138
diff changeset
350 @end ifnotinfo
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents: 14138
diff changeset
351
14531
8985cbbd2fe4 doc: Periodic spellcheck of documentation
Rik <octave@nomad.inbox5.com>
parents: 14509
diff changeset
352 The function, @code{ppval}, evaluates the piecewise polynomials, created
14509
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents: 14138
diff changeset
353 by @code{mkpp} or other means, and @code{unmkpp} returns detailed
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents: 14138
diff changeset
354 information about the piecewise polynomial.
6850
9398f6a81bdf [project @ 2007-08-31 17:29:22 by jwe]
jwe
parents: 6778
diff changeset
355
9398f6a81bdf [project @ 2007-08-31 17:29:22 by jwe]
jwe
parents: 6778
diff changeset
356 The following example shows how to combine two linear functions and a
7001
8b0cfeb06365 [project @ 2007-10-10 18:02:59 by jwe]
jwe
parents: 6898
diff changeset
357 quadratic into one function. Each of these functions is expressed
6850
9398f6a81bdf [project @ 2007-08-31 17:29:22 by jwe]
jwe
parents: 6778
diff changeset
358 on adjoined intervals.
3294
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
359
6850
9398f6a81bdf [project @ 2007-08-31 17:29:22 by jwe]
jwe
parents: 6778
diff changeset
360 @example
9070
e9dc2ed2ec0f Cleanup documentation for poly.texi, interp.texi, geometry.texi
Rik <rdrider0-list@yahoo.com>
parents: 8920
diff changeset
361 @group
6850
9398f6a81bdf [project @ 2007-08-31 17:29:22 by jwe]
jwe
parents: 6778
diff changeset
362 x = [-2, -1, 1, 2];
9398f6a81bdf [project @ 2007-08-31 17:29:22 by jwe]
jwe
parents: 6778
diff changeset
363 p = [ 0, 1, 0;
9398f6a81bdf [project @ 2007-08-31 17:29:22 by jwe]
jwe
parents: 6778
diff changeset
364 1, -2, 1;
9398f6a81bdf [project @ 2007-08-31 17:29:22 by jwe]
jwe
parents: 6778
diff changeset
365 0, -1, 1 ];
14856
c3fd61c59e9c maint: Use Octave coding conventions for cuddling parentheses in doc directory
Rik <octave@nomad.inbox5.com>
parents: 14853
diff changeset
366 pp = mkpp (x, p);
c3fd61c59e9c maint: Use Octave coding conventions for cuddling parentheses in doc directory
Rik <octave@nomad.inbox5.com>
parents: 14853
diff changeset
367 xi = linspace (-2, 2, 50);
c3fd61c59e9c maint: Use Octave coding conventions for cuddling parentheses in doc directory
Rik <octave@nomad.inbox5.com>
parents: 14853
diff changeset
368 yi = ppval (pp, xi);
c3fd61c59e9c maint: Use Octave coding conventions for cuddling parentheses in doc directory
Rik <octave@nomad.inbox5.com>
parents: 14853
diff changeset
369 plot (xi, yi);
9070
e9dc2ed2ec0f Cleanup documentation for poly.texi, interp.texi, geometry.texi
Rik <rdrider0-list@yahoo.com>
parents: 8920
diff changeset
370 @end group
6850
9398f6a81bdf [project @ 2007-08-31 17:29:22 by jwe]
jwe
parents: 6778
diff changeset
371 @end example
6502
6ab0a8767780 [project @ 2007-04-06 03:32:06 by jwe]
jwe
parents: 4167
diff changeset
372
6ab0a8767780 [project @ 2007-04-06 03:32:06 by jwe]
jwe
parents: 4167
diff changeset
373 @DOCSTRING(mkpp)
6ab0a8767780 [project @ 2007-04-06 03:32:06 by jwe]
jwe
parents: 4167
diff changeset
374
6ab0a8767780 [project @ 2007-04-06 03:32:06 by jwe]
jwe
parents: 4167
diff changeset
375 @DOCSTRING(unmkpp)
6850
9398f6a81bdf [project @ 2007-08-31 17:29:22 by jwe]
jwe
parents: 6778
diff changeset
376
11536
702dbd0c53f5 Add undocumented ppder, ppint, ppjumps functions to documentation.
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
377 @DOCSTRING(ppval)
702dbd0c53f5 Add undocumented ppder, ppint, ppjumps functions to documentation.
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
378
702dbd0c53f5 Add undocumented ppder, ppint, ppjumps functions to documentation.
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
379 @DOCSTRING(ppder)
702dbd0c53f5 Add undocumented ppder, ppint, ppjumps functions to documentation.
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
380
702dbd0c53f5 Add undocumented ppder, ppint, ppjumps functions to documentation.
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
381 @DOCSTRING(ppint)
702dbd0c53f5 Add undocumented ppder, ppint, ppjumps functions to documentation.
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
382
702dbd0c53f5 Add undocumented ppder, ppint, ppjumps functions to documentation.
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
383 @DOCSTRING(ppjumps)
702dbd0c53f5 Add undocumented ppder, ppint, ppjumps functions to documentation.
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
384
6850
9398f6a81bdf [project @ 2007-08-31 17:29:22 by jwe]
jwe
parents: 6778
diff changeset
385 @node Miscellaneous Functions
9398f6a81bdf [project @ 2007-08-31 17:29:22 by jwe]
jwe
parents: 6778
diff changeset
386 @section Miscellaneous Functions
9398f6a81bdf [project @ 2007-08-31 17:29:22 by jwe]
jwe
parents: 6778
diff changeset
387
9398f6a81bdf [project @ 2007-08-31 17:29:22 by jwe]
jwe
parents: 6778
diff changeset
388 @DOCSTRING(poly)
9398f6a81bdf [project @ 2007-08-31 17:29:22 by jwe]
jwe
parents: 6778
diff changeset
389
9398f6a81bdf [project @ 2007-08-31 17:29:22 by jwe]
jwe
parents: 6778
diff changeset
390 @DOCSTRING(polyout)
9398f6a81bdf [project @ 2007-08-31 17:29:22 by jwe]
jwe
parents: 6778
diff changeset
391
9398f6a81bdf [project @ 2007-08-31 17:29:22 by jwe]
jwe
parents: 6778
diff changeset
392 @DOCSTRING(polyreduce)
9398f6a81bdf [project @ 2007-08-31 17:29:22 by jwe]
jwe
parents: 6778
diff changeset
393
9398f6a81bdf [project @ 2007-08-31 17:29:22 by jwe]
jwe
parents: 6778
diff changeset
394
8286
6f2d95255911 fix @seealso references to point to existing anchors
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 7640
diff changeset
395
6f2d95255911 fix @seealso references to point to existing anchors
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 7640
diff changeset
396