Mercurial > octave-nkf
annotate doc/interpreter/interp.txi @ 18830:322eb69e30ad stable
doc: Fix some Latin wording in documentation.
* external.txi, interp.txi, sparse.txi: Use "a priori" rather than "a-priori".
Don't use "Firstly".
author | Rik <rik@octave.org> |
---|---|
date | Mon, 02 Jun 2014 08:59:26 -0700 |
parents | dae2230227a7 |
children | 1c4994e66962 446c46af4b42 |
rev | line source |
---|---|
17744
d63878346099
maint: Update copyright notices for release.
John W. Eaton <jwe@octave.org>
parents:
17694
diff
changeset
|
1 @c Copyright (C) 2007-2013 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/>. | |
6549 | 18 |
19 @node Interpolation | |
20 @chapter Interpolation | |
21 | |
6702 | 22 @menu |
23 * One-dimensional Interpolation:: | |
24 * Multi-dimensional Interpolation:: | |
25 @end menu | |
26 | |
27 @node One-dimensional Interpolation | |
28 @section One-dimensional Interpolation | |
6549 | 29 |
6850 | 30 Octave supports several methods for one-dimensional interpolation, most |
31 of which are described in this section. @ref{Polynomial Interpolation} | |
17097
e7a059a9a644
doc: Use XREF as anchor prefix in documentation for clearer results in Info viewer.
Rik <rik@octave.org>
parents:
14856
diff
changeset
|
32 and @ref{Interpolation on Scattered Data} describe additional methods. |
6850 | 33 |
6549 | 34 @DOCSTRING(interp1) |
35 | |
6721 | 36 There are some important differences between the various interpolation |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17097
diff
changeset
|
37 methods. The @qcode{"spline"} method enforces that both the first and second |
6721 | 38 derivatives of the interpolated values have a continuous derivative, |
9070
e9dc2ed2ec0f
Cleanup documentation for poly.texi, interp.texi, geometry.texi
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
39 whereas the other methods do not. This means that the results of the |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17097
diff
changeset
|
40 @qcode{"spline"} method are generally smoother. If the function to be |
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17097
diff
changeset
|
41 interpolated is in fact smooth, then @qcode{"spline"} will give excellent |
9070
e9dc2ed2ec0f
Cleanup documentation for poly.texi, interp.texi, geometry.texi
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
42 results. However, if the function to be evaluated is in some manner |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17097
diff
changeset
|
43 discontinuous, then @qcode{"pchip"} interpolation might give better results. |
6743 | 44 |
45 This can be demonstrated by the code | |
6721 | 46 |
47 @example | |
48 @group | |
6743 | 49 t = -2:2; |
50 dt = 1; | |
51 ti =-2:0.025:2; | |
52 dti = 0.025; | |
14856
c3fd61c59e9c
maint: Use Octave coding conventions for cuddling parentheses in doc directory
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
53 y = sign (t); |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17097
diff
changeset
|
54 ys = interp1 (t,y,ti,"spline"); |
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17097
diff
changeset
|
55 yp = interp1 (t,y,ti,"pchip"); |
14856
c3fd61c59e9c
maint: Use Octave coding conventions for cuddling parentheses in doc directory
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
56 ddys = diff (diff (ys)./dti) ./ dti; |
c3fd61c59e9c
maint: Use Octave coding conventions for cuddling parentheses in doc directory
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
57 ddyp = diff (diff (yp)./dti) ./ dti; |
c3fd61c59e9c
maint: Use Octave coding conventions for cuddling parentheses in doc directory
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
58 figure (1); |
17757
dae2230227a7
doc: Use double-quote in preference to single quote in code examples.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
59 plot (ti,ys,"r-", ti,yp,"g-"); |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17097
diff
changeset
|
60 legend ("spline", "pchip", 4); |
14856
c3fd61c59e9c
maint: Use Octave coding conventions for cuddling parentheses in doc directory
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
61 figure (2); |
17757
dae2230227a7
doc: Use double-quote in preference to single quote in code examples.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
62 plot (ti,ddys,"r+", ti,ddyp,"g*"); |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17097
diff
changeset
|
63 legend ("spline", "pchip"); |
6721 | 64 @end group |
65 @end example | |
66 | |
67 @ifnotinfo | |
68 @noindent | |
6743 | 69 The result of which can be seen in @ref{fig:interpderiv1} and |
70 @ref{fig:interpderiv2}. | |
6721 | 71 |
6743 | 72 @float Figure,fig:interpderiv1 |
9088
77e71f3da3d6
Fix documentation image printing under new development code
Rik <rdrider0-list@yahoo.com>
parents:
9070
diff
changeset
|
73 @center @image{interpderiv1,4in} |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17097
diff
changeset
|
74 @caption{Comparison of @qcode{"pchip"} and @qcode{"spline"} interpolation methods for a |
6743 | 75 step function} |
76 @end float | |
77 | |
78 @float Figure,fig:interpderiv2 | |
9088
77e71f3da3d6
Fix documentation image printing under new development code
Rik <rdrider0-list@yahoo.com>
parents:
9070
diff
changeset
|
79 @center @image{interpderiv2,4in} |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17097
diff
changeset
|
80 @caption{Comparison of the second derivative of the @qcode{"pchip"} and @qcode{"spline"} |
6743 | 81 interpolation methods for a step function} |
6721 | 82 @end float |
83 @end ifnotinfo | |
84 | |
6702 | 85 Fourier interpolation, is a resampling technique where a signal is |
86 converted to the frequency domain, padded with zeros and then | |
87 reconverted to the time domain. | |
6549 | 88 |
89 @DOCSTRING(interpft) | |
90 | |
18830
322eb69e30ad
doc: Fix some Latin wording in documentation.
Rik <rik@octave.org>
parents:
17757
diff
changeset
|
91 There are two significant limitations on Fourier interpolation. First, |
8495
e7b4de25ecb6
[docs] non periodic => non-periodic
Brian Gough <bjg@gnu.org>
parents:
8347
diff
changeset
|
92 the function signal is assumed to be periodic, and so non-periodic |
18830
322eb69e30ad
doc: Fix some Latin wording in documentation.
Rik <rik@octave.org>
parents:
17757
diff
changeset
|
93 signals will be poorly represented at the edges. Second, both the |
6702 | 94 signal and its interpolation are required to be sampled at equispaced |
9070
e9dc2ed2ec0f
Cleanup documentation for poly.texi, interp.texi, geometry.texi
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
95 points. An example of the use of @code{interpft} is |
6549 | 96 |
6702 | 97 @example |
98 @group | |
99 t = 0 : 0.3 : pi; dt = t(2)-t(1); | |
100 n = length (t); k = 100; | |
101 ti = t(1) + [0 : k-1]*dt*n/k; | |
102 y = sin (4*t + 0.3) .* cos (3*t - 0.1); | |
103 yp = sin (4*ti + 0.3) .* cos (3*ti - 0.1); | |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17097
diff
changeset
|
104 plot (ti, yp, "g", ti, interp1 (t, y, ti, "spline"), "b", ... |
17757
dae2230227a7
doc: Use double-quote in preference to single quote in code examples.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
105 ti, interpft (y, k), "c", t, y, "r+"); |
dae2230227a7
doc: Use double-quote in preference to single quote in code examples.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
106 legend ("sin(4t+0.3)cos(3t-0.1)", "spline", "interpft", "data"); |
6702 | 107 @end group |
108 @end example | |
109 | |
8828 | 110 @noindent |
6721 | 111 @ifinfo |
10828
322f43e0e170
Grammarcheck .txi documentation files.
Rik <octave@nomad.inbox5.com>
parents:
9367
diff
changeset
|
112 which demonstrates the poor behavior of Fourier interpolation for non-periodic |
322f43e0e170
Grammarcheck .txi documentation files.
Rik <octave@nomad.inbox5.com>
parents:
9367
diff
changeset
|
113 functions. |
6721 | 114 @end ifinfo |
115 @ifnotinfo | |
10828
322f43e0e170
Grammarcheck .txi documentation files.
Rik <octave@nomad.inbox5.com>
parents:
9367
diff
changeset
|
116 which demonstrates the poor behavior of Fourier interpolation for non-periodic |
322f43e0e170
Grammarcheck .txi documentation files.
Rik <octave@nomad.inbox5.com>
parents:
9367
diff
changeset
|
117 functions, as can be seen in @ref{fig:interpft}. |
6721 | 118 |
119 @float Figure,fig:interpft | |
9088
77e71f3da3d6
Fix documentation image printing under new development code
Rik <rdrider0-list@yahoo.com>
parents:
9070
diff
changeset
|
120 @center @image{interpft,4in} |
8495
e7b4de25ecb6
[docs] non periodic => non-periodic
Brian Gough <bjg@gnu.org>
parents:
8347
diff
changeset
|
121 @caption{Comparison of @code{interp1} and @code{interpft} for non-periodic data} |
6721 | 122 @end float |
123 @end ifnotinfo | |
6702 | 124 |
17097
e7a059a9a644
doc: Use XREF as anchor prefix in documentation for clearer results in Info viewer.
Rik <rik@octave.org>
parents:
14856
diff
changeset
|
125 In addition, the support functions @code{spline} and @code{lookup} that |
6702 | 126 underlie the @code{interp1} function can be called directly. |
6549 | 127 |
6558 | 128 @DOCSTRING(spline) |
129 | |
6702 | 130 @node Multi-dimensional Interpolation |
131 @section Multi-dimensional Interpolation | |
132 | |
6939 | 133 There are three multi-dimensional interpolation functions in Octave, with |
6850 | 134 similar capabilities. Methods using Delaunay tessellation are described |
135 in @ref{Interpolation on Scattered Data}. | |
6702 | 136 |
137 @DOCSTRING(interp2) | |
138 | |
139 @DOCSTRING(interp3) | |
140 | |
141 @DOCSTRING(interpn) | |
142 | |
143 A significant difference between @code{interpn} and the other two | |
10828
322f43e0e170
Grammarcheck .txi documentation files.
Rik <octave@nomad.inbox5.com>
parents:
9367
diff
changeset
|
144 multi-dimensional interpolation functions is the fashion in which the |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17097
diff
changeset
|
145 dimensions are treated. For @code{interp2} and @code{interp3}, the y-axis is |
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17097
diff
changeset
|
146 considered to be the columns of the matrix, whereas the x-axis corresponds to |
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17097
diff
changeset
|
147 the rows of the array. As Octave indexes arrays in column major order, the |
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17097
diff
changeset
|
148 first dimension of any array is the columns, and so @code{interpn} effectively |
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17097
diff
changeset
|
149 reverses the 'x' and 'y' dimensions. Consider the example, |
6702 | 150 |
151 @example | |
152 @group | |
153 x = y = z = -1:1; | |
154 f = @@(x,y,z) x.^2 - y - z.^2; | |
155 [xx, yy, zz] = meshgrid (x, y, z); | |
156 v = f (xx,yy,zz); | |
6721 | 157 xi = yi = zi = -1:0.1:1; |
6702 | 158 [xxi, yyi, zzi] = meshgrid (xi, yi, zi); |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17097
diff
changeset
|
159 vi = interp3 (x, y, z, v, xxi, yyi, zzi, "spline"); |
6702 | 160 [xxi, yyi, zzi] = ndgrid (xi, yi, zi); |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17097
diff
changeset
|
161 vi2 = interpn (x, y, z, v, xxi, yyi, zzi, "spline"); |
6723 | 162 mesh (zi, yi, squeeze (vi2(1,:,:))); |
6702 | 163 @end group |
164 @end example | |
165 | |
166 @noindent | |
9070
e9dc2ed2ec0f
Cleanup documentation for poly.texi, interp.texi, geometry.texi
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
167 where @code{vi} and @code{vi2} are identical. The reversal of the |
6702 | 168 dimensions is treated in the @code{meshgrid} and @code{ndgrid} functions |
169 respectively. | |
6721 | 170 @ifnotinfo |
171 The result of this code can be seen in @ref{fig:interpn}. | |
172 | |
173 @float Figure,fig:interpn | |
9088
77e71f3da3d6
Fix documentation image printing under new development code
Rik <rdrider0-list@yahoo.com>
parents:
9070
diff
changeset
|
174 @center @image{interpn,4in} |
6721 | 175 @caption{Demonstration of the use of @code{interpn}} |
176 @end float | |
177 @end ifnotinfo | |
6702 | 178 |
179 In additional the support function @code{bicubic} that underlies the | |
180 cubic interpolation of @code{interp2} function can be called directly. | |
181 | |
182 @DOCSTRING(bicubic) |