Mercurial > hg > octave-lyh
annotate scripts/general/interp1.m @ 14526:e12945668746
doc: Stop constant rebuild of spline images in txt format.
* splineimages.m: Fix typo in output filename generation for txt format.
author | Rik <octave@nomad.inbox5.com> |
---|---|
date | Wed, 04 Apr 2012 19:28:16 -0700 |
parents | 7ce925166af6 |
children | 5d3a684236b0 |
rev | line source |
---|---|
14138
72c96de7a403
maint: update copyright notices for 2012
John W. Eaton <jwe@octave.org>
parents:
13141
diff
changeset
|
1 ## Copyright (C) 2000-2012 Paul Kienzle |
9929
45c08d7c2c79
allow discontinuous interpolant in interp1
Jaroslav Hajek <highegg@gmail.com>
parents:
9769
diff
changeset
|
2 ## Copyright (C) 2009 VZLU Prague |
5837 | 3 ## |
4 ## This file is part of Octave. | |
5 ## | |
6 ## Octave is free software; you can redistribute it and/or modify it | |
7 ## under the terms of the GNU General Public License as published by | |
7016 | 8 ## the Free Software Foundation; either version 3 of the License, or (at |
9 ## your option) any later version. | |
5837 | 10 ## |
11 ## Octave is distributed in the hope that it will be useful, but | |
12 ## WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
14 ## General Public License for more details. | |
15 ## | |
16 ## You should have received a copy of the GNU General Public License | |
7016 | 17 ## along with Octave; see the file COPYING. If not, see |
18 ## <http://www.gnu.org/licenses/>. | |
5837 | 19 |
20 ## -*- texinfo -*- | |
10846
a4f482e66b65
Grammarcheck more of the documentation.
Rik <octave@nomad.inbox5.com>
parents:
10821
diff
changeset
|
21 ## @deftypefn {Function File} {@var{yi} =} interp1 (@var{x}, @var{y}, @var{xi}) |
10820
c44c786f87ba
interp1.m: When absent set X equal to the inices of Y.
Ben Abbott <bpabbott@mac.com>
parents:
10793
diff
changeset
|
22 ## @deftypefnx {Function File} {@var{yi} =} interp1 (@var{y}, @var{xi}) |
5837 | 23 ## @deftypefnx {Function File} {@var{yi} =} interp1 (@dots{}, @var{method}) |
24 ## @deftypefnx {Function File} {@var{yi} =} interp1 (@dots{}, @var{extrap}) | |
14359
7277fe922e99
doc: Use Octave preference for double quote in docstrings in scripts/
Rik <octave@nomad.inbox5.com>
parents:
14335
diff
changeset
|
25 ## @deftypefnx {Function File} {@var{pp} =} interp1 (@dots{}, "pp") |
5837 | 26 ## |
9051
1bf0ce0930be
Grammar check TexInfo in all .m files
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
27 ## One-dimensional interpolation. Interpolate @var{y}, defined at the |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11536
diff
changeset
|
28 ## points @var{x}, at the points @var{xi}. The sample points @var{x} |
10846
a4f482e66b65
Grammarcheck more of the documentation.
Rik <octave@nomad.inbox5.com>
parents:
10821
diff
changeset
|
29 ## must be monotonic. If not specified, @var{x} is taken to be the |
a4f482e66b65
Grammarcheck more of the documentation.
Rik <octave@nomad.inbox5.com>
parents:
10821
diff
changeset
|
30 ## indices of @var{y}. If @var{y} is an array, treat the columns |
7001 | 31 ## of @var{y} separately. |
5837 | 32 ## |
33 ## Method is one of: | |
34 ## | |
35 ## @table @asis | |
14359
7277fe922e99
doc: Use Octave preference for double quote in docstrings in scripts/
Rik <octave@nomad.inbox5.com>
parents:
14335
diff
changeset
|
36 ## @item "nearest" |
9070
e9dc2ed2ec0f
Cleanup documentation for poly.texi, interp.texi, geometry.texi
Rik <rdrider0-list@yahoo.com>
parents:
9051
diff
changeset
|
37 ## Return the nearest neighbor. |
10821
693e22af08ae
Grammarcheck documentation of m-files
Rik <octave@nomad.inbox5.com>
parents:
10820
diff
changeset
|
38 ## |
14359
7277fe922e99
doc: Use Octave preference for double quote in docstrings in scripts/
Rik <octave@nomad.inbox5.com>
parents:
14335
diff
changeset
|
39 ## @item "linear" |
9070
e9dc2ed2ec0f
Cleanup documentation for poly.texi, interp.texi, geometry.texi
Rik <rdrider0-list@yahoo.com>
parents:
9051
diff
changeset
|
40 ## Linear interpolation from nearest neighbors |
10821
693e22af08ae
Grammarcheck documentation of m-files
Rik <octave@nomad.inbox5.com>
parents:
10820
diff
changeset
|
41 ## |
14359
7277fe922e99
doc: Use Octave preference for double quote in docstrings in scripts/
Rik <octave@nomad.inbox5.com>
parents:
14335
diff
changeset
|
42 ## @item "pchip" |
11536
702dbd0c53f5
Add undocumented ppder, ppint, ppjumps functions to documentation.
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
43 ## Piecewise cubic Hermite interpolating polynomial |
10821
693e22af08ae
Grammarcheck documentation of m-files
Rik <octave@nomad.inbox5.com>
parents:
10820
diff
changeset
|
44 ## |
14359
7277fe922e99
doc: Use Octave preference for double quote in docstrings in scripts/
Rik <octave@nomad.inbox5.com>
parents:
14335
diff
changeset
|
45 ## @item "cubic" |
12608
59e2460acae1
make piecewise polynomial (pp) functions more compatible
Kai Habel <kai.habel@gmx.de>
parents:
12459
diff
changeset
|
46 ## Cubic interpolation (same as @code{pchip}) |
10821
693e22af08ae
Grammarcheck documentation of m-files
Rik <octave@nomad.inbox5.com>
parents:
10820
diff
changeset
|
47 ## |
14359
7277fe922e99
doc: Use Octave preference for double quote in docstrings in scripts/
Rik <octave@nomad.inbox5.com>
parents:
14335
diff
changeset
|
48 ## @item "spline" |
12175
2090995ca588
Correct en-dash,em-dash instances in docstrings.
Rik <octave@nomad.inbox5.com>
parents:
11587
diff
changeset
|
49 ## Cubic spline interpolation---smooth first and second derivatives |
5837 | 50 ## throughout the curve |
51 ## @end table | |
52 ## | |
53 ## Appending '*' to the start of the above method forces @code{interp1} | |
54 ## to assume that @var{x} is uniformly spaced, and only @code{@var{x} | |
9051
1bf0ce0930be
Grammar check TexInfo in all .m files
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
55 ## (1)} and @code{@var{x} (2)} are referenced. This is usually faster, |
14359
7277fe922e99
doc: Use Octave preference for double quote in docstrings in scripts/
Rik <octave@nomad.inbox5.com>
parents:
14335
diff
changeset
|
56 ## and is never slower. The default method is "linear". |
5837 | 57 ## |
14359
7277fe922e99
doc: Use Octave preference for double quote in docstrings in scripts/
Rik <octave@nomad.inbox5.com>
parents:
14335
diff
changeset
|
58 ## If @var{extrap} is the string "extrap", then extrapolate values beyond |
5837 | 59 ## the endpoints. If @var{extrap} is a number, replace values beyond the |
6742 | 60 ## endpoints with that number. If @var{extrap} is missing, assume NA. |
5837 | 61 ## |
14359
7277fe922e99
doc: Use Octave preference for double quote in docstrings in scripts/
Rik <octave@nomad.inbox5.com>
parents:
14335
diff
changeset
|
62 ## If the string argument "pp" is specified, then @var{xi} should not be |
11536
702dbd0c53f5
Add undocumented ppder, ppint, ppjumps functions to documentation.
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
63 ## supplied and @code{interp1} returns the piecewise polynomial that |
5837 | 64 ## can later be used with @code{ppval} to evaluate the interpolation. |
65 ## There is an equivalence, such that @code{ppval (interp1 (@var{x}, | |
14359
7277fe922e99
doc: Use Octave preference for double quote in docstrings in scripts/
Rik <octave@nomad.inbox5.com>
parents:
14335
diff
changeset
|
66 ## @var{y}, @var{method}, "pp"), @var{xi}) == interp1 (@var{x}, @var{y}, |
7277fe922e99
doc: Use Octave preference for double quote in docstrings in scripts/
Rik <octave@nomad.inbox5.com>
parents:
14335
diff
changeset
|
67 ## @var{xi}, @var{method}, "extrap")}. |
5837 | 68 ## |
10711
fbd7843974fa
Periodic grammar check of documentation files to ensure common format.
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
69 ## Duplicate points in @var{x} specify a discontinuous interpolant. There |
9929
45c08d7c2c79
allow discontinuous interpolant in interp1
Jaroslav Hajek <highegg@gmail.com>
parents:
9769
diff
changeset
|
70 ## should be at most 2 consecutive points with the same value. |
45c08d7c2c79
allow discontinuous interpolant in interp1
Jaroslav Hajek <highegg@gmail.com>
parents:
9769
diff
changeset
|
71 ## The discontinuous interpolant is right-continuous if @var{x} is increasing, |
45c08d7c2c79
allow discontinuous interpolant in interp1
Jaroslav Hajek <highegg@gmail.com>
parents:
9769
diff
changeset
|
72 ## left-continuous if it is decreasing. |
45c08d7c2c79
allow discontinuous interpolant in interp1
Jaroslav Hajek <highegg@gmail.com>
parents:
9769
diff
changeset
|
73 ## Discontinuities are (currently) only allowed for "nearest" and "linear" |
45c08d7c2c79
allow discontinuous interpolant in interp1
Jaroslav Hajek <highegg@gmail.com>
parents:
9769
diff
changeset
|
74 ## methods; in all other cases, @var{x} must be strictly monotonic. |
45c08d7c2c79
allow discontinuous interpolant in interp1
Jaroslav Hajek <highegg@gmail.com>
parents:
9769
diff
changeset
|
75 ## |
5837 | 76 ## An example of the use of @code{interp1} is |
77 ## | |
78 ## @example | |
79 ## @group | |
8507 | 80 ## xf = [0:0.05:10]; |
81 ## yf = sin (2*pi*xf/5); | |
82 ## xp = [0:10]; | |
83 ## yp = sin (2*pi*xp/5); | |
84 ## lin = interp1 (xp, yp, xf); | |
85 ## spl = interp1 (xp, yp, xf, "spline"); | |
86 ## cub = interp1 (xp, yp, xf, "cubic"); | |
87 ## near = interp1 (xp, yp, xf, "nearest"); | |
88 ## plot (xf, yf, "r", xf, lin, "g", xf, spl, "b", | |
89 ## xf, cub, "c", xf, near, "m", xp, yp, "r*"); | |
14327
4d917a6a858b
doc: Use Octave coding conventions in @example blocks of docstrings.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
90 ## legend ("original", "linear", "spline", "cubic", "nearest"); |
5837 | 91 ## @end group |
92 ## @end example | |
93 ## | |
94 ## @seealso{interpft} | |
95 ## @end deftypefn | |
96 | |
5838 | 97 ## Author: Paul Kienzle |
98 ## Date: 2000-03-25 | |
5837 | 99 ## added 'nearest' as suggested by Kai Habel |
100 ## 2000-07-17 Paul Kienzle | |
101 ## added '*' methods and matrix y | |
102 ## check for proper table lengths | |
103 ## 2002-01-23 Paul Kienzle | |
104 ## fixed extrapolation | |
105 | |
5838 | 106 function yi = interp1 (x, y, varargin) |
5837 | 107 |
10820
c44c786f87ba
interp1.m: When absent set X equal to the inices of Y.
Ben Abbott <bpabbott@mac.com>
parents:
10793
diff
changeset
|
108 if (nargin < 2 || nargin > 6) |
5837 | 109 print_usage (); |
110 endif | |
111 | |
112 method = "linear"; | |
6742 | 113 extrap = NA; |
5837 | 114 xi = []; |
12608
59e2460acae1
make piecewise polynomial (pp) functions more compatible
Kai Habel <kai.habel@gmx.de>
parents:
12459
diff
changeset
|
115 ispp = false; |
5837 | 116 firstnumeric = true; |
117 | |
118 if (nargin > 2) | |
5838 | 119 for i = 1:length (varargin) |
5837 | 120 arg = varargin{i}; |
5838 | 121 if (ischar (arg)) |
10549 | 122 arg = tolower (arg); |
123 if (strcmp ("extrap", arg)) | |
124 extrap = "extrap"; | |
125 elseif (strcmp ("pp", arg)) | |
12608
59e2460acae1
make piecewise polynomial (pp) functions more compatible
Kai Habel <kai.habel@gmx.de>
parents:
12459
diff
changeset
|
126 ispp = true; |
10549 | 127 else |
128 method = arg; | |
129 endif | |
5837 | 130 else |
10549 | 131 if (firstnumeric) |
132 xi = arg; | |
133 firstnumeric = false; | |
134 else | |
135 extrap = arg; | |
136 endif | |
5837 | 137 endif |
138 endfor | |
139 endif | |
140 | |
12608
59e2460acae1
make piecewise polynomial (pp) functions more compatible
Kai Habel <kai.habel@gmx.de>
parents:
12459
diff
changeset
|
141 if (isempty (xi) && firstnumeric && ! ispp) |
10820
c44c786f87ba
interp1.m: When absent set X equal to the inices of Y.
Ben Abbott <bpabbott@mac.com>
parents:
10793
diff
changeset
|
142 xi = y; |
c44c786f87ba
interp1.m: When absent set X equal to the inices of Y.
Ben Abbott <bpabbott@mac.com>
parents:
10793
diff
changeset
|
143 y = x; |
c44c786f87ba
interp1.m: When absent set X equal to the inices of Y.
Ben Abbott <bpabbott@mac.com>
parents:
10793
diff
changeset
|
144 x = 1:numel(y); |
c44c786f87ba
interp1.m: When absent set X equal to the inices of Y.
Ben Abbott <bpabbott@mac.com>
parents:
10793
diff
changeset
|
145 endif |
c44c786f87ba
interp1.m: When absent set X equal to the inices of Y.
Ben Abbott <bpabbott@mac.com>
parents:
10793
diff
changeset
|
146 |
5837 | 147 ## reshape matrices for convenience |
148 x = x(:); | |
9754
4219e5cf773d
improve interp1 and pchip
Jaroslav Hajek <highegg@gmail.com>
parents:
9070
diff
changeset
|
149 nx = rows (x); |
9769
9a1c4fe44af8
small interp1 simplification
Jaroslav Hajek <highegg@gmail.com>
parents:
9754
diff
changeset
|
150 szx = size (xi); |
9754
4219e5cf773d
improve interp1 and pchip
Jaroslav Hajek <highegg@gmail.com>
parents:
9070
diff
changeset
|
151 if (isvector (y)) |
5838 | 152 y = y(:); |
5837 | 153 endif |
13141
e81ddf9cacd5
maint: untabify and remove trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
12608
diff
changeset
|
154 |
5838 | 155 szy = size (y); |
9754
4219e5cf773d
improve interp1 and pchip
Jaroslav Hajek <highegg@gmail.com>
parents:
9070
diff
changeset
|
156 y = y(:,:); |
4219e5cf773d
improve interp1 and pchip
Jaroslav Hajek <highegg@gmail.com>
parents:
9070
diff
changeset
|
157 [ny, nc] = size (y); |
5837 | 158 xi = xi(:); |
159 | |
160 ## determine sizes | |
161 if (nx < 2 || ny < 2) | |
5838 | 162 error ("interp1: table too short"); |
5837 | 163 endif |
164 | |
9754
4219e5cf773d
improve interp1 and pchip
Jaroslav Hajek <highegg@gmail.com>
parents:
9070
diff
changeset
|
165 ## check whether x is sorted; sort if not. |
9929
45c08d7c2c79
allow discontinuous interpolant in interp1
Jaroslav Hajek <highegg@gmail.com>
parents:
9769
diff
changeset
|
166 if (! issorted (x, "either")) |
9754
4219e5cf773d
improve interp1 and pchip
Jaroslav Hajek <highegg@gmail.com>
parents:
9070
diff
changeset
|
167 [x, p] = sort (x); |
4219e5cf773d
improve interp1 and pchip
Jaroslav Hajek <highegg@gmail.com>
parents:
9070
diff
changeset
|
168 y = y(p,:); |
5837 | 169 endif |
5838 | 170 |
9754
4219e5cf773d
improve interp1 and pchip
Jaroslav Hajek <highegg@gmail.com>
parents:
9070
diff
changeset
|
171 starmethod = method(1) == "*"; |
4219e5cf773d
improve interp1 and pchip
Jaroslav Hajek <highegg@gmail.com>
parents:
9070
diff
changeset
|
172 |
4219e5cf773d
improve interp1 and pchip
Jaroslav Hajek <highegg@gmail.com>
parents:
9070
diff
changeset
|
173 if (starmethod) |
4219e5cf773d
improve interp1 and pchip
Jaroslav Hajek <highegg@gmail.com>
parents:
9070
diff
changeset
|
174 dx = x(2) - x(1); |
4219e5cf773d
improve interp1 and pchip
Jaroslav Hajek <highegg@gmail.com>
parents:
9070
diff
changeset
|
175 else |
9929
45c08d7c2c79
allow discontinuous interpolant in interp1
Jaroslav Hajek <highegg@gmail.com>
parents:
9769
diff
changeset
|
176 jumps = x(1:nx-1) == x(2:nx); |
45c08d7c2c79
allow discontinuous interpolant in interp1
Jaroslav Hajek <highegg@gmail.com>
parents:
9769
diff
changeset
|
177 have_jumps = any (jumps); |
45c08d7c2c79
allow discontinuous interpolant in interp1
Jaroslav Hajek <highegg@gmail.com>
parents:
9769
diff
changeset
|
178 if (have_jumps) |
45c08d7c2c79
allow discontinuous interpolant in interp1
Jaroslav Hajek <highegg@gmail.com>
parents:
9769
diff
changeset
|
179 if (any (strcmp (method, {"nearest", "linear"}))) |
45c08d7c2c79
allow discontinuous interpolant in interp1
Jaroslav Hajek <highegg@gmail.com>
parents:
9769
diff
changeset
|
180 if (any (jumps(1:nx-2) & jumps(2:nx-1))) |
45c08d7c2c79
allow discontinuous interpolant in interp1
Jaroslav Hajek <highegg@gmail.com>
parents:
9769
diff
changeset
|
181 warning ("interp1: extra points in discontinuities"); |
45c08d7c2c79
allow discontinuous interpolant in interp1
Jaroslav Hajek <highegg@gmail.com>
parents:
9769
diff
changeset
|
182 endif |
45c08d7c2c79
allow discontinuous interpolant in interp1
Jaroslav Hajek <highegg@gmail.com>
parents:
9769
diff
changeset
|
183 else |
45c08d7c2c79
allow discontinuous interpolant in interp1
Jaroslav Hajek <highegg@gmail.com>
parents:
9769
diff
changeset
|
184 error ("interp1: discontinuities not supported for method %s", method); |
45c08d7c2c79
allow discontinuous interpolant in interp1
Jaroslav Hajek <highegg@gmail.com>
parents:
9769
diff
changeset
|
185 endif |
5837 | 186 endif |
187 endif | |
188 | |
9754
4219e5cf773d
improve interp1 and pchip
Jaroslav Hajek <highegg@gmail.com>
parents:
9070
diff
changeset
|
189 ## Proceed with interpolating by all methods. |
4219e5cf773d
improve interp1 and pchip
Jaroslav Hajek <highegg@gmail.com>
parents:
9070
diff
changeset
|
190 |
4219e5cf773d
improve interp1 and pchip
Jaroslav Hajek <highegg@gmail.com>
parents:
9070
diff
changeset
|
191 switch (method) |
4219e5cf773d
improve interp1 and pchip
Jaroslav Hajek <highegg@gmail.com>
parents:
9070
diff
changeset
|
192 case "nearest" |
12608
59e2460acae1
make piecewise polynomial (pp) functions more compatible
Kai Habel <kai.habel@gmx.de>
parents:
12459
diff
changeset
|
193 pp = mkpp ([x(1); (x(1:nx-1)+x(2:nx))/2; x(nx)], shiftdim (y, 1), szy(2:end)); |
59e2460acae1
make piecewise polynomial (pp) functions more compatible
Kai Habel <kai.habel@gmx.de>
parents:
12459
diff
changeset
|
194 pp.orient = "first"; |
13141
e81ddf9cacd5
maint: untabify and remove trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
12608
diff
changeset
|
195 |
12608
59e2460acae1
make piecewise polynomial (pp) functions more compatible
Kai Habel <kai.habel@gmx.de>
parents:
12459
diff
changeset
|
196 if (ispp) |
59e2460acae1
make piecewise polynomial (pp) functions more compatible
Kai Habel <kai.habel@gmx.de>
parents:
12459
diff
changeset
|
197 yi = pp; |
5837 | 198 else |
12608
59e2460acae1
make piecewise polynomial (pp) functions more compatible
Kai Habel <kai.habel@gmx.de>
parents:
12459
diff
changeset
|
199 yi = ppval (pp, reshape (xi, szx)); |
5837 | 200 endif |
9754
4219e5cf773d
improve interp1 and pchip
Jaroslav Hajek <highegg@gmail.com>
parents:
9070
diff
changeset
|
201 case "*nearest" |
12608
59e2460acae1
make piecewise polynomial (pp) functions more compatible
Kai Habel <kai.habel@gmx.de>
parents:
12459
diff
changeset
|
202 pp = mkpp ([x(1), x(1)+[0.5:(nx-1)]*dx, x(nx)], shiftdim (y, 1), szy(2:end)); |
59e2460acae1
make piecewise polynomial (pp) functions more compatible
Kai Habel <kai.habel@gmx.de>
parents:
12459
diff
changeset
|
203 pp.orient = "first"; |
59e2460acae1
make piecewise polynomial (pp) functions more compatible
Kai Habel <kai.habel@gmx.de>
parents:
12459
diff
changeset
|
204 if (ispp) |
59e2460acae1
make piecewise polynomial (pp) functions more compatible
Kai Habel <kai.habel@gmx.de>
parents:
12459
diff
changeset
|
205 yi = pp; |
5837 | 206 else |
12608
59e2460acae1
make piecewise polynomial (pp) functions more compatible
Kai Habel <kai.habel@gmx.de>
parents:
12459
diff
changeset
|
207 yi = ppval(pp, reshape (xi, szx)); |
5837 | 208 endif |
9754
4219e5cf773d
improve interp1 and pchip
Jaroslav Hajek <highegg@gmail.com>
parents:
9070
diff
changeset
|
209 case "linear" |
4219e5cf773d
improve interp1 and pchip
Jaroslav Hajek <highegg@gmail.com>
parents:
9070
diff
changeset
|
210 dy = diff (y); |
13141
e81ddf9cacd5
maint: untabify and remove trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
12608
diff
changeset
|
211 dx = diff (x); |
12608
59e2460acae1
make piecewise polynomial (pp) functions more compatible
Kai Habel <kai.habel@gmx.de>
parents:
12459
diff
changeset
|
212 dx = repmat (dx, [1 size(dy)(2:end)]); |
59e2460acae1
make piecewise polynomial (pp) functions more compatible
Kai Habel <kai.habel@gmx.de>
parents:
12459
diff
changeset
|
213 coefs = [(dy./dx).'(:), y(1:nx-1, :).'(:)]; |
59e2460acae1
make piecewise polynomial (pp) functions more compatible
Kai Habel <kai.habel@gmx.de>
parents:
12459
diff
changeset
|
214 xx = x; |
59e2460acae1
make piecewise polynomial (pp) functions more compatible
Kai Habel <kai.habel@gmx.de>
parents:
12459
diff
changeset
|
215 |
59e2460acae1
make piecewise polynomial (pp) functions more compatible
Kai Habel <kai.habel@gmx.de>
parents:
12459
diff
changeset
|
216 if (have_jumps) |
59e2460acae1
make piecewise polynomial (pp) functions more compatible
Kai Habel <kai.habel@gmx.de>
parents:
12459
diff
changeset
|
217 ## Omit zero-size intervals. |
59e2460acae1
make piecewise polynomial (pp) functions more compatible
Kai Habel <kai.habel@gmx.de>
parents:
12459
diff
changeset
|
218 coefs(jumps, :) = []; |
59e2460acae1
make piecewise polynomial (pp) functions more compatible
Kai Habel <kai.habel@gmx.de>
parents:
12459
diff
changeset
|
219 xx(jumps) = []; |
59e2460acae1
make piecewise polynomial (pp) functions more compatible
Kai Habel <kai.habel@gmx.de>
parents:
12459
diff
changeset
|
220 endif |
59e2460acae1
make piecewise polynomial (pp) functions more compatible
Kai Habel <kai.habel@gmx.de>
parents:
12459
diff
changeset
|
221 |
59e2460acae1
make piecewise polynomial (pp) functions more compatible
Kai Habel <kai.habel@gmx.de>
parents:
12459
diff
changeset
|
222 pp = mkpp (xx, coefs, szy(2:end)); |
59e2460acae1
make piecewise polynomial (pp) functions more compatible
Kai Habel <kai.habel@gmx.de>
parents:
12459
diff
changeset
|
223 pp.orient = "first"; |
59e2460acae1
make piecewise polynomial (pp) functions more compatible
Kai Habel <kai.habel@gmx.de>
parents:
12459
diff
changeset
|
224 |
59e2460acae1
make piecewise polynomial (pp) functions more compatible
Kai Habel <kai.habel@gmx.de>
parents:
12459
diff
changeset
|
225 if (ispp) |
59e2460acae1
make piecewise polynomial (pp) functions more compatible
Kai Habel <kai.habel@gmx.de>
parents:
12459
diff
changeset
|
226 yi = pp; |
5837 | 227 else |
12608
59e2460acae1
make piecewise polynomial (pp) functions more compatible
Kai Habel <kai.habel@gmx.de>
parents:
12459
diff
changeset
|
228 yi = ppval(pp, reshape (xi, szx)); |
5837 | 229 endif |
12608
59e2460acae1
make piecewise polynomial (pp) functions more compatible
Kai Habel <kai.habel@gmx.de>
parents:
12459
diff
changeset
|
230 |
9754
4219e5cf773d
improve interp1 and pchip
Jaroslav Hajek <highegg@gmail.com>
parents:
9070
diff
changeset
|
231 case "*linear" |
4219e5cf773d
improve interp1 and pchip
Jaroslav Hajek <highegg@gmail.com>
parents:
9070
diff
changeset
|
232 dy = diff (y); |
12608
59e2460acae1
make piecewise polynomial (pp) functions more compatible
Kai Habel <kai.habel@gmx.de>
parents:
12459
diff
changeset
|
233 coefs = [(dy/dx).'(:), y(1:nx-1, :).'(:)]; |
59e2460acae1
make piecewise polynomial (pp) functions more compatible
Kai Habel <kai.habel@gmx.de>
parents:
12459
diff
changeset
|
234 pp = mkpp (x, coefs, szy(2:end)); |
59e2460acae1
make piecewise polynomial (pp) functions more compatible
Kai Habel <kai.habel@gmx.de>
parents:
12459
diff
changeset
|
235 pp.orient = "first"; |
59e2460acae1
make piecewise polynomial (pp) functions more compatible
Kai Habel <kai.habel@gmx.de>
parents:
12459
diff
changeset
|
236 |
59e2460acae1
make piecewise polynomial (pp) functions more compatible
Kai Habel <kai.habel@gmx.de>
parents:
12459
diff
changeset
|
237 if (ispp) |
59e2460acae1
make piecewise polynomial (pp) functions more compatible
Kai Habel <kai.habel@gmx.de>
parents:
12459
diff
changeset
|
238 yi = pp; |
5837 | 239 else |
12608
59e2460acae1
make piecewise polynomial (pp) functions more compatible
Kai Habel <kai.habel@gmx.de>
parents:
12459
diff
changeset
|
240 yi = ppval(pp, reshape (xi, szx)); |
59e2460acae1
make piecewise polynomial (pp) functions more compatible
Kai Habel <kai.habel@gmx.de>
parents:
12459
diff
changeset
|
241 endif |
5837 | 242 |
12608
59e2460acae1
make piecewise polynomial (pp) functions more compatible
Kai Habel <kai.habel@gmx.de>
parents:
12459
diff
changeset
|
243 case {"pchip", "*pchip", "cubic", "*cubic"} |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11536
diff
changeset
|
244 if (nx == 2 || starmethod) |
6374 | 245 x = linspace (x(1), x(nx), ny); |
5837 | 246 endif |
13141
e81ddf9cacd5
maint: untabify and remove trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
12608
diff
changeset
|
247 |
12608
59e2460acae1
make piecewise polynomial (pp) functions more compatible
Kai Habel <kai.habel@gmx.de>
parents:
12459
diff
changeset
|
248 if (ispp) |
59e2460acae1
make piecewise polynomial (pp) functions more compatible
Kai Habel <kai.habel@gmx.de>
parents:
12459
diff
changeset
|
249 y = shiftdim (reshape (y, szy), 1); |
59e2460acae1
make piecewise polynomial (pp) functions more compatible
Kai Habel <kai.habel@gmx.de>
parents:
12459
diff
changeset
|
250 yi = pchip (x, y); |
14492
7ce925166af6
Fix inconsistent orientation of output matrix for interp1.
Olaf Till <i7tiol@t-online.de>
parents:
14363
diff
changeset
|
251 yi.orient = "first"; |
9754
4219e5cf773d
improve interp1 and pchip
Jaroslav Hajek <highegg@gmail.com>
parents:
9070
diff
changeset
|
252 else |
12608
59e2460acae1
make piecewise polynomial (pp) functions more compatible
Kai Habel <kai.habel@gmx.de>
parents:
12459
diff
changeset
|
253 y = shiftdim (y, 1); |
59e2460acae1
make piecewise polynomial (pp) functions more compatible
Kai Habel <kai.habel@gmx.de>
parents:
12459
diff
changeset
|
254 yi = pchip (x, y, reshape (xi, szx)); |
14492
7ce925166af6
Fix inconsistent orientation of output matrix for interp1.
Olaf Till <i7tiol@t-online.de>
parents:
14363
diff
changeset
|
255 if (! isvector (y)) |
7ce925166af6
Fix inconsistent orientation of output matrix for interp1.
Olaf Till <i7tiol@t-online.de>
parents:
14363
diff
changeset
|
256 yi = shiftdim (yi, 1); |
7ce925166af6
Fix inconsistent orientation of output matrix for interp1.
Olaf Till <i7tiol@t-online.de>
parents:
14363
diff
changeset
|
257 endif |
9754
4219e5cf773d
improve interp1 and pchip
Jaroslav Hajek <highegg@gmail.com>
parents:
9070
diff
changeset
|
258 endif |
4219e5cf773d
improve interp1 and pchip
Jaroslav Hajek <highegg@gmail.com>
parents:
9070
diff
changeset
|
259 case {"spline", "*spline"} |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11536
diff
changeset
|
260 if (nx == 2 || starmethod) |
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11536
diff
changeset
|
261 x = linspace(x(1), x(nx), ny); |
5837 | 262 endif |
13141
e81ddf9cacd5
maint: untabify and remove trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
12608
diff
changeset
|
263 |
12608
59e2460acae1
make piecewise polynomial (pp) functions more compatible
Kai Habel <kai.habel@gmx.de>
parents:
12459
diff
changeset
|
264 if (ispp) |
59e2460acae1
make piecewise polynomial (pp) functions more compatible
Kai Habel <kai.habel@gmx.de>
parents:
12459
diff
changeset
|
265 y = shiftdim (reshape (y, szy), 1); |
59e2460acae1
make piecewise polynomial (pp) functions more compatible
Kai Habel <kai.habel@gmx.de>
parents:
12459
diff
changeset
|
266 yi = spline (x, y); |
14492
7ce925166af6
Fix inconsistent orientation of output matrix for interp1.
Olaf Till <i7tiol@t-online.de>
parents:
14363
diff
changeset
|
267 yi.orient = "first"; |
5837 | 268 else |
12608
59e2460acae1
make piecewise polynomial (pp) functions more compatible
Kai Habel <kai.habel@gmx.de>
parents:
12459
diff
changeset
|
269 y = shiftdim (y, 1); |
59e2460acae1
make piecewise polynomial (pp) functions more compatible
Kai Habel <kai.habel@gmx.de>
parents:
12459
diff
changeset
|
270 yi = spline (x, y, reshape (xi, szx)); |
14492
7ce925166af6
Fix inconsistent orientation of output matrix for interp1.
Olaf Till <i7tiol@t-online.de>
parents:
14363
diff
changeset
|
271 if (! isvector (y)) |
7ce925166af6
Fix inconsistent orientation of output matrix for interp1.
Olaf Till <i7tiol@t-online.de>
parents:
14363
diff
changeset
|
272 yi = shiftdim (yi, 1); |
7ce925166af6
Fix inconsistent orientation of output matrix for interp1.
Olaf Till <i7tiol@t-online.de>
parents:
14363
diff
changeset
|
273 endif |
5837 | 274 endif |
9754
4219e5cf773d
improve interp1 and pchip
Jaroslav Hajek <highegg@gmail.com>
parents:
9070
diff
changeset
|
275 otherwise |
5838 | 276 error ("interp1: invalid method '%s'", method); |
9754
4219e5cf773d
improve interp1 and pchip
Jaroslav Hajek <highegg@gmail.com>
parents:
9070
diff
changeset
|
277 endswitch |
5837 | 278 |
12608
59e2460acae1
make piecewise polynomial (pp) functions more compatible
Kai Habel <kai.habel@gmx.de>
parents:
12459
diff
changeset
|
279 if (! ispp) |
9754
4219e5cf773d
improve interp1 and pchip
Jaroslav Hajek <highegg@gmail.com>
parents:
9070
diff
changeset
|
280 if (! ischar (extrap)) |
4219e5cf773d
improve interp1 and pchip
Jaroslav Hajek <highegg@gmail.com>
parents:
9070
diff
changeset
|
281 ## determine which values are out of range and set them to extrap, |
4219e5cf773d
improve interp1 and pchip
Jaroslav Hajek <highegg@gmail.com>
parents:
9070
diff
changeset
|
282 ## unless extrap == "extrap". |
4219e5cf773d
improve interp1 and pchip
Jaroslav Hajek <highegg@gmail.com>
parents:
9070
diff
changeset
|
283 minx = min (x(1), x(nx)); |
4219e5cf773d
improve interp1 and pchip
Jaroslav Hajek <highegg@gmail.com>
parents:
9070
diff
changeset
|
284 maxx = max (x(1), x(nx)); |
4219e5cf773d
improve interp1 and pchip
Jaroslav Hajek <highegg@gmail.com>
parents:
9070
diff
changeset
|
285 |
4219e5cf773d
improve interp1 and pchip
Jaroslav Hajek <highegg@gmail.com>
parents:
9070
diff
changeset
|
286 outliers = xi < minx | ! (xi <= maxx); # this catches even NaNs |
12608
59e2460acae1
make piecewise polynomial (pp) functions more compatible
Kai Habel <kai.habel@gmx.de>
parents:
12459
diff
changeset
|
287 if (size_equal (outliers, yi)) |
59e2460acae1
make piecewise polynomial (pp) functions more compatible
Kai Habel <kai.habel@gmx.de>
parents:
12459
diff
changeset
|
288 yi(outliers) = extrap; |
59e2460acae1
make piecewise polynomial (pp) functions more compatible
Kai Habel <kai.habel@gmx.de>
parents:
12459
diff
changeset
|
289 yi = reshape (yi, szx); |
59e2460acae1
make piecewise polynomial (pp) functions more compatible
Kai Habel <kai.habel@gmx.de>
parents:
12459
diff
changeset
|
290 elseif (!isvector (yi)) |
14492
7ce925166af6
Fix inconsistent orientation of output matrix for interp1.
Olaf Till <i7tiol@t-online.de>
parents:
14363
diff
changeset
|
291 yi(outliers, :) = extrap; |
12608
59e2460acae1
make piecewise polynomial (pp) functions more compatible
Kai Habel <kai.habel@gmx.de>
parents:
12459
diff
changeset
|
292 else |
59e2460acae1
make piecewise polynomial (pp) functions more compatible
Kai Habel <kai.habel@gmx.de>
parents:
12459
diff
changeset
|
293 yi(outliers.') = extrap; |
59e2460acae1
make piecewise polynomial (pp) functions more compatible
Kai Habel <kai.habel@gmx.de>
parents:
12459
diff
changeset
|
294 endif |
9754
4219e5cf773d
improve interp1 and pchip
Jaroslav Hajek <highegg@gmail.com>
parents:
9070
diff
changeset
|
295 endif |
5837 | 296 endif |
297 | |
298 endfunction | |
299 | |
14237
11949c9795a0
Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
300 |
5837 | 301 %!demo |
14237
11949c9795a0
Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
302 %! clf; |
14363
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14359
diff
changeset
|
303 %! xf = 0:0.05:10; yf = sin (2*pi*xf/5); |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14359
diff
changeset
|
304 %! xp = 0:10; yp = sin (2*pi*xp/5); |
14237
11949c9795a0
Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
305 %! lin = interp1 (xp,yp,xf, "linear"); |
11949c9795a0
Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
306 %! spl = interp1 (xp,yp,xf, "spline"); |
11949c9795a0
Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
307 %! cub = interp1 (xp,yp,xf, "pchip"); |
11949c9795a0
Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
308 %! near= interp1 (xp,yp,xf, "nearest"); |
11949c9795a0
Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
309 %! plot (xf,yf,"r",xf,near,"g",xf,lin,"b",xf,cub,"c",xf,spl,"m",xp,yp,"r*"); |
11949c9795a0
Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
310 %! legend ("original", "nearest", "linear", "pchip", "spline"); |
5837 | 311 %! %-------------------------------------------------------- |
312 %! % confirm that interpolated function matches the original | |
313 | |
314 %!demo | |
14237
11949c9795a0
Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
315 %! clf; |
14363
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14359
diff
changeset
|
316 %! xf = 0:0.05:10; yf = sin (2*pi*xf/5); |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14359
diff
changeset
|
317 %! xp = 0:10; yp = sin (2*pi*xp/5); |
14237
11949c9795a0
Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
318 %! lin = interp1 (xp,yp,xf, "*linear"); |
11949c9795a0
Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
319 %! spl = interp1 (xp,yp,xf, "*spline"); |
11949c9795a0
Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
320 %! cub = interp1 (xp,yp,xf, "*cubic"); |
11949c9795a0
Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
321 %! near= interp1 (xp,yp,xf, "*nearest"); |
11949c9795a0
Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
322 %! plot (xf,yf,"r",xf,near,"g",xf,lin,"b",xf,cub,"c",xf,spl,"m",xp,yp,"r*"); |
11949c9795a0
Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
323 %! legend ("*original", "*nearest", "*linear", "*cubic", "*spline"); |
5837 | 324 %! %-------------------------------------------------------- |
325 %! % confirm that interpolated function matches the original | |
326 | |
6721 | 327 %!demo |
14237
11949c9795a0
Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
328 %! clf; |
6721 | 329 %! t = 0 : 0.3 : pi; dt = t(2)-t(1); |
330 %! n = length (t); k = 100; dti = dt*n/k; | |
331 %! ti = t(1) + [0 : k-1]*dti; | |
332 %! y = sin (4*t + 0.3) .* cos (3*t - 0.1); | |
14237
11949c9795a0
Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
333 %! ddyc = diff (diff (interp1 (t,y,ti, "cubic")) ./dti)./dti; |
11949c9795a0
Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
334 %! ddys = diff (diff (interp1 (t,y,ti, "spline"))./dti)./dti; |
11949c9795a0
Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
335 %! ddyp = diff (diff (interp1 (t,y,ti, "pchip")) ./dti)./dti; |
11949c9795a0
Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
336 %! plot (ti(2:end-1),ddyc,'g+', ti(2:end-1),ddys,'b*', ti(2:end-1),ddyp,'c^'); |
11949c9795a0
Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
337 %! legend ("cubic", "spline", "pchip"); |
11949c9795a0
Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
338 %! title ("Second derivative of interpolated 'sin (4*t + 0.3) .* cos (3*t - 0.1)'"); |
6721 | 339 |
9929
45c08d7c2c79
allow discontinuous interpolant in interp1
Jaroslav Hajek <highegg@gmail.com>
parents:
9769
diff
changeset
|
340 %!demo |
14237
11949c9795a0
Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
341 %! clf; |
14363
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14359
diff
changeset
|
342 %! xf = 0:0.05:10; yf = sin (2*pi*xf/5) - (xf >= 5); |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14359
diff
changeset
|
343 %! xp = [0:.5:4.5,4.99,5:.5:10]; yp = sin (2*pi*xp/5) - (xp >= 5); |
14237
11949c9795a0
Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
344 %! lin = interp1 (xp,yp,xf, "linear"); |
11949c9795a0
Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
345 %! near= interp1 (xp,yp,xf, "nearest"); |
11949c9795a0
Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
346 %! plot (xf,yf,"r", xf,near,"g", xf,lin,"b", xp,yp,"r*"); |
11949c9795a0
Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
347 %! legend ("original", "nearest", "linear"); |
9929
45c08d7c2c79
allow discontinuous interpolant in interp1
Jaroslav Hajek <highegg@gmail.com>
parents:
9769
diff
changeset
|
348 %! %-------------------------------------------------------- |
45c08d7c2c79
allow discontinuous interpolant in interp1
Jaroslav Hajek <highegg@gmail.com>
parents:
9769
diff
changeset
|
349 %! % confirm that interpolated function matches the original |
45c08d7c2c79
allow discontinuous interpolant in interp1
Jaroslav Hajek <highegg@gmail.com>
parents:
9769
diff
changeset
|
350 |
12608
59e2460acae1
make piecewise polynomial (pp) functions more compatible
Kai Habel <kai.habel@gmx.de>
parents:
12459
diff
changeset
|
351 ##FIXME: add test for n-d arguments here |
9929
45c08d7c2c79
allow discontinuous interpolant in interp1
Jaroslav Hajek <highegg@gmail.com>
parents:
9769
diff
changeset
|
352 |
6374 | 353 ## For each type of interpolated test, confirm that the interpolated |
354 ## value at the knots match the values at the knots. Points away | |
14359
7277fe922e99
doc: Use Octave preference for double quote in docstrings in scripts/
Rik <octave@nomad.inbox5.com>
parents:
14335
diff
changeset
|
355 ## from the knots are requested, but only "nearest" and "linear" |
6374 | 356 ## confirm they are the correct values. |
357 | |
5837 | 358 %!shared xp, yp, xi, style |
14237
11949c9795a0
Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
359 %! xp = 0:2:10; |
11949c9795a0
Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
360 %! yp = sin (2*pi*xp/5); |
6374 | 361 %! xi = [-1, 0, 2.2, 4, 6.6, 10, 11]; |
362 | |
363 ## The following BLOCK/ENDBLOCK section is repeated for each style | |
364 ## nearest, linear, cubic, spline, pchip | |
365 ## The test for ppval of cubic has looser tolerance, but otherwise | |
366 ## the tests are identical. | |
367 ## Note that the block checks style and *style; if you add more tests | |
14237
11949c9795a0
Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
368 ## be sure to add them to both sections of each block. One test, |
6374 | 369 ## style vs. *style, occurs only in the first section. |
370 ## There is an ENDBLOCKTEST after the final block | |
14237
11949c9795a0
Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
371 |
5837 | 372 %!test style = "nearest"; |
6374 | 373 ## BLOCK |
14363
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14359
diff
changeset
|
374 %!assert (interp1 (xp, yp, [min(xp)-1, max(xp)+1],style), [NA, NA]) |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14359
diff
changeset
|
375 %!assert (interp1 (xp,yp,xp,style), yp, 100*eps) |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14359
diff
changeset
|
376 %!assert (interp1 (xp,yp,xp',style), yp', 100*eps) |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14359
diff
changeset
|
377 %!assert (interp1 (xp',yp',xp',style), yp', 100*eps) |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14359
diff
changeset
|
378 %!assert (interp1 (xp',yp',xp,style), yp, 100*eps) |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14359
diff
changeset
|
379 %!assert (isempty (interp1 (xp',yp',[],style))) |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14359
diff
changeset
|
380 %!assert (isempty (interp1 (xp,yp,[],style))) |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14359
diff
changeset
|
381 %!assert (interp1 (xp,[yp',yp'],xi(:),style),... |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14359
diff
changeset
|
382 %! [interp1(xp,yp,xi(:),style),interp1(xp,yp,xi(:),style)]) |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14359
diff
changeset
|
383 %!assert (interp1 (xp,yp,xi,style),... |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14359
diff
changeset
|
384 %! interp1 (fliplr (xp),fliplr (yp),xi,style),100*eps) |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14359
diff
changeset
|
385 %!assert (ppval (interp1 (xp,yp,style,"pp"),xi), |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14359
diff
changeset
|
386 %! interp1 (xp,yp,xi,style,"extrap"),10*eps) |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14359
diff
changeset
|
387 %!error interp1 (1,1,1, style) |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14359
diff
changeset
|
388 %!assert (interp1 (xp,[yp',yp'],xi,style), |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14359
diff
changeset
|
389 %! interp1 (xp,[yp',yp'],xi,["*",style]),100*eps) |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14359
diff
changeset
|
390 %!test style = ["*",style]; |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14359
diff
changeset
|
391 %!assert (interp1 (xp, yp, [min(xp)-1, max(xp)+1],style), [NA, NA]) |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14359
diff
changeset
|
392 %!assert (interp1 (xp,yp,xp,style), yp, 100*eps) |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14359
diff
changeset
|
393 %!assert (interp1 (xp,yp,xp',style), yp', 100*eps) |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14359
diff
changeset
|
394 %!assert (interp1 (xp',yp',xp',style), yp', 100*eps) |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14359
diff
changeset
|
395 %!assert (interp1 (xp',yp',xp,style), yp, 100*eps) |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14359
diff
changeset
|
396 %!assert (isempty (interp1 (xp',yp',[],style))) |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14359
diff
changeset
|
397 %!assert (isempty (interp1 (xp,yp,[],style))) |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14359
diff
changeset
|
398 %!assert (interp1 (xp,[yp',yp'],xi(:),style),... |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14359
diff
changeset
|
399 %! [interp1(xp,yp,xi(:),style),interp1(xp,yp,xi(:),style)]) |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14359
diff
changeset
|
400 %!assert (interp1 (xp,yp,xi,style),... |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14359
diff
changeset
|
401 %! interp1 (fliplr (xp),fliplr (yp),xi,style),100*eps) |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14359
diff
changeset
|
402 %!assert (ppval (interp1 (xp,yp,style,"pp"),xi), |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14359
diff
changeset
|
403 %! interp1 (xp,yp,xi,style,"extrap"),10*eps) |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14359
diff
changeset
|
404 %!error interp1 (1,1,1, style) |
6374 | 405 ## ENDBLOCK |
14237
11949c9795a0
Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
406 |
14363
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14359
diff
changeset
|
407 %!test style = "linear"; |
6374 | 408 ## BLOCK |
14363
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14359
diff
changeset
|
409 %!assert (interp1 (xp, yp, [min(xp)-1, max(xp)+1],style), [NA, NA]) |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14359
diff
changeset
|
410 %!assert (interp1 (xp,yp,xp,style), yp, 100*eps) |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14359
diff
changeset
|
411 %!assert (interp1 (xp,yp,xp',style), yp', 100*eps) |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14359
diff
changeset
|
412 %!assert (interp1 (xp',yp',xp',style), yp', 100*eps) |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14359
diff
changeset
|
413 %!assert (interp1 (xp',yp',xp,style), yp, 100*eps) |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14359
diff
changeset
|
414 %!assert (isempty (interp1 (xp',yp',[],style))) |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14359
diff
changeset
|
415 %!assert (isempty (interp1 (xp,yp,[],style))) |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14359
diff
changeset
|
416 %!assert (interp1 (xp,[yp',yp'],xi(:),style),... |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14359
diff
changeset
|
417 %! [interp1(xp,yp,xi(:),style),interp1(xp,yp,xi(:),style)]) |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14359
diff
changeset
|
418 %!assert (interp1 (xp,yp,xi,style),... |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14359
diff
changeset
|
419 %! interp1 (fliplr (xp),fliplr (yp),xi,style),100*eps) |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14359
diff
changeset
|
420 %!assert (ppval (interp1 (xp,yp,style,"pp"),xi), |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14359
diff
changeset
|
421 %! interp1 (xp,yp,xi,style,"extrap"),10*eps) |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14359
diff
changeset
|
422 %!error interp1 (1,1,1, style) |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14359
diff
changeset
|
423 %!assert (interp1 (xp,[yp',yp'],xi,style), |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14359
diff
changeset
|
424 %! interp1 (xp,[yp',yp'],xi,["*",style]),100*eps) |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14359
diff
changeset
|
425 %!test style = ['*',style]; |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14359
diff
changeset
|
426 %!assert (interp1 (xp, yp, [min(xp)-1, max(xp)+1],style), [NA, NA]) |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14359
diff
changeset
|
427 %!assert (interp1 (xp,yp,xp,style), yp, 100*eps) |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14359
diff
changeset
|
428 %!assert (interp1 (xp,yp,xp',style), yp', 100*eps) |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14359
diff
changeset
|
429 %!assert (interp1 (xp',yp',xp',style), yp', 100*eps) |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14359
diff
changeset
|
430 %!assert (interp1 (xp',yp',xp,style), yp, 100*eps) |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14359
diff
changeset
|
431 %!assert (isempty (interp1 (xp',yp',[],style))) |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14359
diff
changeset
|
432 %!assert (isempty (interp1 (xp,yp,[],style))) |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14359
diff
changeset
|
433 %!assert (interp1 (xp,[yp',yp'],xi(:),style),... |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14359
diff
changeset
|
434 %! [interp1(xp,yp,xi(:),style),interp1(xp,yp,xi(:),style)]) |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14359
diff
changeset
|
435 %!assert (interp1 (xp,yp,xi,style),... |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14359
diff
changeset
|
436 %! interp1 (fliplr (xp),fliplr (yp),xi,style),100*eps) |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14359
diff
changeset
|
437 %!assert (ppval (interp1 (xp,yp,style,"pp"),xi), |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14359
diff
changeset
|
438 %! interp1 (xp,yp,xi,style,"extrap"),10*eps) |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14359
diff
changeset
|
439 %!error interp1 (1,1,1, style) |
6374 | 440 ## ENDBLOCK |
14237
11949c9795a0
Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
441 |
14363
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14359
diff
changeset
|
442 %!test style = "cubic"; |
6374 | 443 ## BLOCK |
14363
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14359
diff
changeset
|
444 %!assert (interp1 (xp, yp, [min(xp)-1, max(xp)+1],style), [NA, NA]) |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14359
diff
changeset
|
445 %!assert (interp1 (xp,yp,xp,style), yp, 100*eps) |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14359
diff
changeset
|
446 %!assert (interp1 (xp,yp,xp',style), yp', 100*eps) |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14359
diff
changeset
|
447 %!assert (interp1 (xp',yp',xp',style), yp', 100*eps) |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14359
diff
changeset
|
448 %!assert (interp1 (xp',yp',xp,style), yp, 100*eps) |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14359
diff
changeset
|
449 %!assert (isempty (interp1 (xp',yp',[],style))) |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14359
diff
changeset
|
450 %!assert (isempty (interp1 (xp,yp,[],style))) |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14359
diff
changeset
|
451 %!assert (interp1 (xp,[yp',yp'],xi(:),style),... |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14359
diff
changeset
|
452 %! [interp1(xp,yp,xi(:),style),interp1(xp,yp,xi(:),style)]) |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14359
diff
changeset
|
453 %!assert (interp1 (xp,yp,xi,style),... |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14359
diff
changeset
|
454 %! interp1 (fliplr (xp),fliplr (yp),xi,style),100*eps) |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14359
diff
changeset
|
455 %!assert (ppval (interp1 (xp,yp,style,"pp"),xi), |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14359
diff
changeset
|
456 %! interp1 (xp,yp,xi,style,"extrap"),100*eps) |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14359
diff
changeset
|
457 %!error interp1 (1,1,1, style) |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14359
diff
changeset
|
458 %!assert (interp1 (xp,[yp',yp'],xi,style), |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14359
diff
changeset
|
459 %! interp1 (xp,[yp',yp'],xi,["*",style]),100*eps) |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14359
diff
changeset
|
460 %!test style = ["*",style]; |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14359
diff
changeset
|
461 %!assert (interp1 (xp, yp, [min(xp)-1, max(xp)+1],style), [NA, NA]) |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14359
diff
changeset
|
462 %!assert (interp1 (xp,yp,xp,style), yp, 100*eps) |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14359
diff
changeset
|
463 %!assert (interp1 (xp,yp,xp',style), yp', 100*eps) |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14359
diff
changeset
|
464 %!assert (interp1 (xp',yp',xp',style), yp', 100*eps) |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14359
diff
changeset
|
465 %!assert (interp1 (xp',yp',xp,style), yp, 100*eps) |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14359
diff
changeset
|
466 %!assert (isempty (interp1 (xp',yp',[],style))) |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14359
diff
changeset
|
467 %!assert (isempty (interp1 (xp,yp,[],style))) |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14359
diff
changeset
|
468 %!assert (interp1 (xp,[yp',yp'],xi(:),style),... |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14359
diff
changeset
|
469 %! [interp1(xp,yp,xi(:),style),interp1(xp,yp,xi(:),style)]) |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14359
diff
changeset
|
470 %!assert (interp1 (xp,yp,xi,style),... |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14359
diff
changeset
|
471 %! interp1 (fliplr (xp),fliplr (yp),xi,style),100*eps) |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14359
diff
changeset
|
472 %!assert (ppval (interp1 (xp,yp,style,"pp"),xi), |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14359
diff
changeset
|
473 %! interp1 (xp,yp,xi,style,"extrap"),100*eps) |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14359
diff
changeset
|
474 %!error interp1 (1,1,1, style) |
6374 | 475 ## ENDBLOCK |
14237
11949c9795a0
Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
476 |
14363
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14359
diff
changeset
|
477 %!test style = "pchip"; |
6374 | 478 ## BLOCK |
14363
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14359
diff
changeset
|
479 %!assert (interp1 (xp, yp, [min(xp)-1, max(xp)+1],style), [NA, NA]) |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14359
diff
changeset
|
480 %!assert (interp1 (xp,yp,xp,style), yp, 100*eps) |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14359
diff
changeset
|
481 %!assert (interp1 (xp,yp,xp',style), yp', 100*eps) |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14359
diff
changeset
|
482 %!assert (interp1 (xp',yp',xp',style), yp', 100*eps) |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14359
diff
changeset
|
483 %!assert (interp1 (xp',yp',xp,style), yp, 100*eps) |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14359
diff
changeset
|
484 %!assert (isempty (interp1 (xp',yp',[],style))) |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14359
diff
changeset
|
485 %!assert (isempty (interp1 (xp,yp,[],style))) |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14359
diff
changeset
|
486 %!assert (interp1 (xp,[yp',yp'],xi(:),style),... |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14359
diff
changeset
|
487 %! [interp1(xp,yp,xi(:),style),interp1(xp,yp,xi(:),style)]) |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14359
diff
changeset
|
488 %!assert (interp1 (xp,yp,xi,style),... |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14359
diff
changeset
|
489 %! interp1 (fliplr (xp),fliplr (yp),xi,style),100*eps) |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14359
diff
changeset
|
490 %!assert (ppval (interp1 (xp,yp,style,"pp"),xi), |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14359
diff
changeset
|
491 %! interp1 (xp,yp,xi,style,"extrap"),10*eps) |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14359
diff
changeset
|
492 %!error interp1 (1,1,1, style) |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14359
diff
changeset
|
493 %!assert (interp1 (xp,[yp',yp'],xi,style), |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14359
diff
changeset
|
494 %! interp1 (xp,[yp',yp'],xi,["*",style]),100*eps) |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14359
diff
changeset
|
495 %!test style = ["*",style]; |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14359
diff
changeset
|
496 %!assert (interp1 (xp, yp, [min(xp)-1, max(xp)+1],style), [NA, NA]) |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14359
diff
changeset
|
497 %!assert (interp1 (xp,yp,xp,style), yp, 100*eps) |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14359
diff
changeset
|
498 %!assert (interp1 (xp,yp,xp',style), yp', 100*eps) |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14359
diff
changeset
|
499 %!assert (interp1 (xp',yp',xp',style), yp', 100*eps) |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14359
diff
changeset
|
500 %!assert (interp1 (xp',yp',xp,style), yp, 100*eps) |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14359
diff
changeset
|
501 %!assert (isempty (interp1 (xp',yp',[],style))) |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14359
diff
changeset
|
502 %!assert (isempty (interp1 (xp,yp,[],style))) |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14359
diff
changeset
|
503 %!assert (interp1 (xp,[yp',yp'],xi(:),style),... |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14359
diff
changeset
|
504 %! [interp1(xp,yp,xi(:),style),interp1(xp,yp,xi(:),style)]) |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14359
diff
changeset
|
505 %!assert (interp1 (xp,yp,xi,style),... |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14359
diff
changeset
|
506 %! interp1 (fliplr (xp),fliplr (yp),xi,style),100*eps) |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14359
diff
changeset
|
507 %!assert (ppval (interp1 (xp,yp,style,"pp"),xi), |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14359
diff
changeset
|
508 %! interp1 (xp,yp,xi,style,"extrap"),10*eps) |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14359
diff
changeset
|
509 %!error interp1 (1,1,1, style) |
6374 | 510 ## ENDBLOCK |
14237
11949c9795a0
Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
511 |
14363
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14359
diff
changeset
|
512 %!test style = "spline"; |
6374 | 513 ## BLOCK |
14363
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14359
diff
changeset
|
514 %!assert (interp1 (xp, yp, [min(xp)-1, max(xp)+1],style), [NA, NA]) |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14359
diff
changeset
|
515 %!assert (interp1 (xp,yp,xp,style), yp, 100*eps) |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14359
diff
changeset
|
516 %!assert (interp1 (xp,yp,xp',style), yp', 100*eps) |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14359
diff
changeset
|
517 %!assert (interp1 (xp',yp',xp',style), yp', 100*eps) |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14359
diff
changeset
|
518 %!assert (interp1 (xp',yp',xp,style), yp, 100*eps) |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14359
diff
changeset
|
519 %!assert (isempty (interp1 (xp',yp',[],style))) |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14359
diff
changeset
|
520 %!assert (isempty (interp1 (xp,yp,[],style))) |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14359
diff
changeset
|
521 %!assert (interp1 (xp,[yp',yp'],xi(:),style),... |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14359
diff
changeset
|
522 %! [interp1(xp,yp,xi(:),style),interp1(xp,yp,xi(:),style)]) |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14359
diff
changeset
|
523 %!assert (interp1 (xp,yp,xi,style),... |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14359
diff
changeset
|
524 %! interp1 (fliplr (xp),fliplr (yp),xi,style),100*eps) |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14359
diff
changeset
|
525 %!assert (ppval (interp1 (xp,yp,style,"pp"),xi), |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14359
diff
changeset
|
526 %! interp1 (xp,yp,xi,style,"extrap"),10*eps) |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14359
diff
changeset
|
527 %!error interp1 (1,1,1, style) |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14359
diff
changeset
|
528 %!assert (interp1 (xp,[yp',yp'],xi,style), |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14359
diff
changeset
|
529 %! interp1 (xp,[yp',yp'],xi,["*",style]),100*eps) |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14359
diff
changeset
|
530 %!test style = ["*",style]; |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14359
diff
changeset
|
531 %!assert (interp1 (xp, yp, [min(xp)-1, max(xp)+1],style), [NA, NA]) |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14359
diff
changeset
|
532 %!assert (interp1 (xp,yp,xp,style), yp, 100*eps) |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14359
diff
changeset
|
533 %!assert (interp1 (xp,yp,xp',style), yp', 100*eps) |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14359
diff
changeset
|
534 %!assert (interp1 (xp',yp',xp',style), yp', 100*eps) |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14359
diff
changeset
|
535 %!assert (interp1 (xp',yp',xp,style), yp, 100*eps) |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14359
diff
changeset
|
536 %!assert (isempty (interp1 (xp',yp',[],style))) |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14359
diff
changeset
|
537 %!assert (isempty (interp1 (xp,yp,[],style))) |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14359
diff
changeset
|
538 %!assert (interp1 (xp,[yp',yp'],xi(:),style),... |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14359
diff
changeset
|
539 %! [interp1(xp,yp,xi(:),style),interp1(xp,yp,xi(:),style)]) |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14359
diff
changeset
|
540 %!assert (interp1 (xp,yp,xi,style),... |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14359
diff
changeset
|
541 %! interp1 (fliplr (xp),fliplr (yp),xi,style),100*eps) |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14359
diff
changeset
|
542 %!assert (ppval (interp1 (xp,yp,style,"pp"),xi), |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14359
diff
changeset
|
543 %! interp1 (xp,yp,xi,style,"extrap"),10*eps) |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14359
diff
changeset
|
544 %!error interp1 (1,1,1, style) |
6374 | 545 ## ENDBLOCK |
546 ## ENDBLOCKTEST | |
5837 | 547 |
548 %!# test linear extrapolation | |
14363
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14359
diff
changeset
|
549 %!assert (interp1 ([1:5],[3:2:11],[0,6],"linear","extrap"), [1, 13], eps) |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14359
diff
changeset
|
550 %!assert (interp1 (xp, yp, [-1, max(xp)+1],"linear",5), [5, 5]) |
5837 | 551 |
14363
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14359
diff
changeset
|
552 %!assert (interp1 (1:2,1:2,1.4,"nearest"), 1) |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14359
diff
changeset
|
553 %!assert (interp1 (1:2,1:2,1.4,"linear"), 1.4) |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14359
diff
changeset
|
554 %!assert (interp1 (1:4,1:4,1.4,"cubic"), 1.4) |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14359
diff
changeset
|
555 %!assert (interp1 (1:2,1:2,1.1, "spline"), 1.1) |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14359
diff
changeset
|
556 %!assert (interp1 (1:3,1:3,1.4,"spline"), 1.4) |
5837 | 557 |
14363
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14359
diff
changeset
|
558 %!assert (interp1 (1:2:4,1:2:4,1.4,"*nearest"), 1) |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14359
diff
changeset
|
559 %!assert (interp1 (1:2:4,1:2:4,[0,1,1.4,3,4],"*linear"), [NA,1,1.4,3,NA]) |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14359
diff
changeset
|
560 %!assert (interp1 (1:2:8,1:2:8,1.4,"*cubic"), 1.4) |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14359
diff
changeset
|
561 %!assert (interp1 (1:2,1:2,1.3, "*spline"), 1.3) |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14359
diff
changeset
|
562 %!assert (interp1 (1:2:6,1:2:6,1.4,"*spline"), 1.4) |
7671
4fbaba9abec1
implement compiled binary lookup
Jaroslav Hajek <highegg@gmail.com>
parents:
7017
diff
changeset
|
563 |
14363
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14359
diff
changeset
|
564 %!assert (interp1 ([3,2,1],[3,2,2],2.5), 2.5) |
9929
45c08d7c2c79
allow discontinuous interpolant in interp1
Jaroslav Hajek <highegg@gmail.com>
parents:
9769
diff
changeset
|
565 |
45c08d7c2c79
allow discontinuous interpolant in interp1
Jaroslav Hajek <highegg@gmail.com>
parents:
9769
diff
changeset
|
566 %!assert (interp1 ([1,2,2,3,4],[0,1,4,2,1],[-1,1.5,2,2.5,3.5], "linear", "extrap"), [-2,0.5,4,3,1.5]) |
12608
59e2460acae1
make piecewise polynomial (pp) functions more compatible
Kai Habel <kai.habel@gmx.de>
parents:
12459
diff
changeset
|
567 %!assert (interp1 ([4,4,3,2,0],[0,1,4,2,1],[1.5,4,4.5], "linear"), [1.75,1,NA]) |
10820
c44c786f87ba
interp1.m: When absent set X equal to the inices of Y.
Ben Abbott <bpabbott@mac.com>
parents:
10793
diff
changeset
|
568 %!assert (interp1 (0:4, 2.5), 1.5) |
14363
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14359
diff
changeset
|
569 |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14359
diff
changeset
|
570 %!error interp1 () |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14359
diff
changeset
|
571 %!error interp1 (1,1,1, "linear") |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14359
diff
changeset
|
572 %!error interp1 (1,1,1, "*nearest") |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14359
diff
changeset
|
573 %!error interp1 (1,1,1, "*linear") |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14359
diff
changeset
|
574 %!error interp1 (1:2,1:2,1, "bogus") |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14359
diff
changeset
|
575 |