Mercurial > hg > octave-nkf
annotate scripts/general/interp1.m @ 18486:1ad77b3e6bef stable
interp1.m: Demote error to warning about multiple discontinuties (bug #41386).
* interp1.m: Demote error to warning about multiple discontinuties
(bug #41386). Add %!warning test for new behavior.
author | Rik <rik@octave.org> |
---|---|
date | Fri, 31 Jan 2014 21:08:15 -0800 |
parents | 71d1a1450365 |
children | 0ede4dbb37f1 5fe907167520 |
rev | line source |
---|---|
17744
d63878346099
maint: Update copyright notices for release.
John W. Eaton <jwe@octave.org>
parents:
17307
diff
changeset
|
1 ## Copyright (C) 2000-2013 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}) | |
18485 | 25 ## @deftypefnx {Function File} {@var{yi} =} interp1 (@dots{}, "left") |
26 ## @deftypefnx {Function File} {@var{yi} =} interp1 (@dots{}, "right") | |
14359
7277fe922e99
doc: Use Octave preference for double quote in docstrings in scripts/
Rik <octave@nomad.inbox5.com>
parents:
14335
diff
changeset
|
27 ## @deftypefnx {Function File} {@var{pp} =} interp1 (@dots{}, "pp") |
5837 | 28 ## |
18485 | 29 ## One-dimensional interpolation. |
30 ## | |
31 ## Interpolate input data to determine the value of @var{yi} at the points | |
32 ## @var{xi}. If not specified, @var{x} is taken to be the indices of @var{y}. | |
33 ## If @var{y} is a matrix or an N-dimensional array, the interpolation is | |
34 ## performed on each column of @var{y}. | |
5837 | 35 ## |
36 ## Method is one of: | |
37 ## | |
38 ## @table @asis | |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17174
diff
changeset
|
39 ## @item @qcode{"nearest"} |
18485 | 40 ## Return the nearest neighbor |
10821
693e22af08ae
Grammarcheck documentation of m-files
Rik <octave@nomad.inbox5.com>
parents:
10820
diff
changeset
|
41 ## |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17174
diff
changeset
|
42 ## @item @qcode{"linear"} |
9070
e9dc2ed2ec0f
Cleanup documentation for poly.texi, interp.texi, geometry.texi
Rik <rdrider0-list@yahoo.com>
parents:
9051
diff
changeset
|
43 ## Linear interpolation from nearest neighbors |
10821
693e22af08ae
Grammarcheck documentation of m-files
Rik <octave@nomad.inbox5.com>
parents:
10820
diff
changeset
|
44 ## |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17174
diff
changeset
|
45 ## @item @qcode{"pchip"} |
11536
702dbd0c53f5
Add undocumented ppder, ppint, ppjumps functions to documentation.
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
46 ## Piecewise cubic Hermite interpolating polynomial |
10821
693e22af08ae
Grammarcheck documentation of m-files
Rik <octave@nomad.inbox5.com>
parents:
10820
diff
changeset
|
47 ## |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17174
diff
changeset
|
48 ## @item @qcode{"cubic"} |
12608
59e2460acae1
make piecewise polynomial (pp) functions more compatible
Kai Habel <kai.habel@gmx.de>
parents:
12459
diff
changeset
|
49 ## Cubic interpolation (same as @code{pchip}) |
10821
693e22af08ae
Grammarcheck documentation of m-files
Rik <octave@nomad.inbox5.com>
parents:
10820
diff
changeset
|
50 ## |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17174
diff
changeset
|
51 ## @item @qcode{"spline"} |
12175
2090995ca588
Correct en-dash,em-dash instances in docstrings.
Rik <octave@nomad.inbox5.com>
parents:
11587
diff
changeset
|
52 ## Cubic spline interpolation---smooth first and second derivatives |
5837 | 53 ## throughout the curve |
54 ## @end table | |
55 ## | |
18485 | 56 ## Adding '*' to the start of any method above forces @code{interp1} |
15218
94d512d712e3
Modified interp1.m file to check whether X has distinct values or not.
Ben Abbott <bpabbott@mac.com>
parents:
15193
diff
changeset
|
57 ## to assume that @var{x} is uniformly spaced, and only @code{@var{x}(1)} |
94d512d712e3
Modified interp1.m file to check whether X has distinct values or not.
Ben Abbott <bpabbott@mac.com>
parents:
15193
diff
changeset
|
58 ## and @code{@var{x}(2)} are referenced. This is usually faster, |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17174
diff
changeset
|
59 ## and is never slower. The default method is @qcode{"linear"}. |
5837 | 60 ## |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17174
diff
changeset
|
61 ## If @var{extrap} is the string @qcode{"extrap"}, then extrapolate values |
18485 | 62 ## beyond the endpoints using the current @var{method}. If @var{extrap} is a |
63 ## number, then replace values beyond the endpoints with that number. When | |
64 ## unspecified, @var{extrap} defaults to NA. | |
5837 | 65 ## |
18485 | 66 ## If the string argument @qcode{"pp"} is specified, then @var{xi} should not |
67 ## be supplied and @code{interp1} returns a piecewise polynomial object. This | |
68 ## object can later be used with @code{ppval} to evaluate the interpolation. | |
5837 | 69 ## There is an equivalence, such that @code{ppval (interp1 (@var{x}, |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17174
diff
changeset
|
70 ## @var{y}, @var{method}, @qcode{"pp"}), @var{xi}) == interp1 (@var{x}, @var{y}, |
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17174
diff
changeset
|
71 ## @var{xi}, @var{method}, @qcode{"extrap"})}. |
5837 | 72 ## |
10711
fbd7843974fa
Periodic grammar check of documentation files to ensure common format.
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
73 ## Duplicate points in @var{x} specify a discontinuous interpolant. There |
15218
94d512d712e3
Modified interp1.m file to check whether X has distinct values or not.
Ben Abbott <bpabbott@mac.com>
parents:
15193
diff
changeset
|
74 ## may be at most 2 consecutive points with the same value. |
94d512d712e3
Modified interp1.m file to check whether X has distinct values or not.
Ben Abbott <bpabbott@mac.com>
parents:
15193
diff
changeset
|
75 ## If @var{x} is increasing, the default discontinuous interpolant is |
16816
12005245b645
doc: Periodic grammarcheck of documentation.
Rik <rik@octave.org>
parents:
15468
diff
changeset
|
76 ## right-continuous. If @var{x} is decreasing, the default discontinuous |
15218
94d512d712e3
Modified interp1.m file to check whether X has distinct values or not.
Ben Abbott <bpabbott@mac.com>
parents:
15193
diff
changeset
|
77 ## interpolant is left-continuous. |
94d512d712e3
Modified interp1.m file to check whether X has distinct values or not.
Ben Abbott <bpabbott@mac.com>
parents:
15193
diff
changeset
|
78 ## The continuity condition of the interpolant may be specified by using |
18485 | 79 ## the options, @qcode{"left"} or @qcode{"right"}, to select a left-continuous |
15218
94d512d712e3
Modified interp1.m file to check whether X has distinct values or not.
Ben Abbott <bpabbott@mac.com>
parents:
15193
diff
changeset
|
80 ## or right-continuous interpolant, respectively. |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17174
diff
changeset
|
81 ## Discontinuous interpolation is only allowed for @qcode{"nearest"} and |
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17174
diff
changeset
|
82 ## @qcode{"linear"} methods; in all other cases, the @var{x}-values must be |
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17174
diff
changeset
|
83 ## unique. |
9929
45c08d7c2c79
allow discontinuous interpolant in interp1
Jaroslav Hajek <highegg@gmail.com>
parents:
9769
diff
changeset
|
84 ## |
5837 | 85 ## An example of the use of @code{interp1} is |
86 ## | |
87 ## @example | |
88 ## @group | |
8507 | 89 ## xf = [0:0.05:10]; |
90 ## yf = sin (2*pi*xf/5); | |
91 ## xp = [0:10]; | |
92 ## yp = sin (2*pi*xp/5); | |
93 ## lin = interp1 (xp, yp, xf); | |
94 ## spl = interp1 (xp, yp, xf, "spline"); | |
95 ## cub = interp1 (xp, yp, xf, "cubic"); | |
96 ## near = interp1 (xp, yp, xf, "nearest"); | |
97 ## plot (xf, yf, "r", xf, lin, "g", xf, spl, "b", | |
98 ## 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
|
99 ## legend ("original", "linear", "spline", "cubic", "nearest"); |
5837 | 100 ## @end group |
101 ## @end example | |
102 ## | |
18485 | 103 ## @seealso{interpft, interp2, interp3, interpn} |
5837 | 104 ## @end deftypefn |
105 | |
5838 | 106 ## Author: Paul Kienzle |
107 ## Date: 2000-03-25 | |
5837 | 108 ## added 'nearest' as suggested by Kai Habel |
109 ## 2000-07-17 Paul Kienzle | |
110 ## added '*' methods and matrix y | |
111 ## check for proper table lengths | |
112 ## 2002-01-23 Paul Kienzle | |
113 ## fixed extrapolation | |
114 | |
5838 | 115 function yi = interp1 (x, y, varargin) |
5837 | 116 |
10820
c44c786f87ba
interp1.m: When absent set X equal to the inices of Y.
Ben Abbott <bpabbott@mac.com>
parents:
10793
diff
changeset
|
117 if (nargin < 2 || nargin > 6) |
5837 | 118 print_usage (); |
119 endif | |
120 | |
121 method = "linear"; | |
6742 | 122 extrap = NA; |
5837 | 123 xi = []; |
12608
59e2460acae1
make piecewise polynomial (pp) functions more compatible
Kai Habel <kai.habel@gmx.de>
parents:
12459
diff
changeset
|
124 ispp = false; |
5837 | 125 firstnumeric = true; |
18485 | 126 rightcontinuous = NaN; |
5837 | 127 |
128 if (nargin > 2) | |
5838 | 129 for i = 1:length (varargin) |
5837 | 130 arg = varargin{i}; |
5838 | 131 if (ischar (arg)) |
10549 | 132 arg = tolower (arg); |
133 if (strcmp ("extrap", arg)) | |
134 extrap = "extrap"; | |
135 elseif (strcmp ("pp", arg)) | |
12608
59e2460acae1
make piecewise polynomial (pp) functions more compatible
Kai Habel <kai.habel@gmx.de>
parents:
12459
diff
changeset
|
136 ispp = true; |
18485 | 137 elseif (strcmp (arg, "right") || strcmp (arg, "-right")) |
15218
94d512d712e3
Modified interp1.m file to check whether X has distinct values or not.
Ben Abbott <bpabbott@mac.com>
parents:
15193
diff
changeset
|
138 rightcontinuous = true; |
18485 | 139 elseif (strcmp (arg, "left") || strcmp (arg, "-left")) |
15218
94d512d712e3
Modified interp1.m file to check whether X has distinct values or not.
Ben Abbott <bpabbott@mac.com>
parents:
15193
diff
changeset
|
140 rightcontinuous = false; |
10549 | 141 else |
142 method = arg; | |
143 endif | |
5837 | 144 else |
10549 | 145 if (firstnumeric) |
146 xi = arg; | |
147 firstnumeric = false; | |
148 else | |
149 extrap = arg; | |
150 endif | |
5837 | 151 endif |
152 endfor | |
153 endif | |
154 | |
12608
59e2460acae1
make piecewise polynomial (pp) functions more compatible
Kai Habel <kai.habel@gmx.de>
parents:
12459
diff
changeset
|
155 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
|
156 xi = y; |
c44c786f87ba
interp1.m: When absent set X equal to the inices of Y.
Ben Abbott <bpabbott@mac.com>
parents:
10793
diff
changeset
|
157 y = x; |
17088
c8586e6fc60d
interp1.m: Fix interpolation on ND-arrays (bug #35860)
Mike Miller <mtmiller@ieee.org>
parents:
17087
diff
changeset
|
158 if (isvector (y)) |
c8586e6fc60d
interp1.m: Fix interpolation on ND-arrays (bug #35860)
Mike Miller <mtmiller@ieee.org>
parents:
17087
diff
changeset
|
159 x = 1:numel (y); |
c8586e6fc60d
interp1.m: Fix interpolation on ND-arrays (bug #35860)
Mike Miller <mtmiller@ieee.org>
parents:
17087
diff
changeset
|
160 else |
c8586e6fc60d
interp1.m: Fix interpolation on ND-arrays (bug #35860)
Mike Miller <mtmiller@ieee.org>
parents:
17087
diff
changeset
|
161 x = 1:rows (y); |
c8586e6fc60d
interp1.m: Fix interpolation on ND-arrays (bug #35860)
Mike Miller <mtmiller@ieee.org>
parents:
17087
diff
changeset
|
162 endif |
10820
c44c786f87ba
interp1.m: When absent set X equal to the inices of Y.
Ben Abbott <bpabbott@mac.com>
parents:
10793
diff
changeset
|
163 endif |
c44c786f87ba
interp1.m: When absent set X equal to the inices of Y.
Ben Abbott <bpabbott@mac.com>
parents:
10793
diff
changeset
|
164 |
5837 | 165 ## reshape matrices for convenience |
166 x = x(:); | |
9754
4219e5cf773d
improve interp1 and pchip
Jaroslav Hajek <highegg@gmail.com>
parents:
9070
diff
changeset
|
167 nx = rows (x); |
9769
9a1c4fe44af8
small interp1 simplification
Jaroslav Hajek <highegg@gmail.com>
parents:
9754
diff
changeset
|
168 szx = size (xi); |
9754
4219e5cf773d
improve interp1 and pchip
Jaroslav Hajek <highegg@gmail.com>
parents:
9070
diff
changeset
|
169 if (isvector (y)) |
5838 | 170 y = y(:); |
5837 | 171 endif |
13141
e81ddf9cacd5
maint: untabify and remove trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
12608
diff
changeset
|
172 |
5838 | 173 szy = size (y); |
9754
4219e5cf773d
improve interp1 and pchip
Jaroslav Hajek <highegg@gmail.com>
parents:
9070
diff
changeset
|
174 y = y(:,:); |
4219e5cf773d
improve interp1 and pchip
Jaroslav Hajek <highegg@gmail.com>
parents:
9070
diff
changeset
|
175 [ny, nc] = size (y); |
5837 | 176 xi = xi(:); |
177 | |
178 ## determine sizes | |
179 if (nx < 2 || ny < 2) | |
5838 | 180 error ("interp1: table too short"); |
5837 | 181 endif |
182 | |
9754
4219e5cf773d
improve interp1 and pchip
Jaroslav Hajek <highegg@gmail.com>
parents:
9070
diff
changeset
|
183 ## check whether x is sorted; sort if not. |
9929
45c08d7c2c79
allow discontinuous interpolant in interp1
Jaroslav Hajek <highegg@gmail.com>
parents:
9769
diff
changeset
|
184 if (! issorted (x, "either")) |
9754
4219e5cf773d
improve interp1 and pchip
Jaroslav Hajek <highegg@gmail.com>
parents:
9070
diff
changeset
|
185 [x, p] = sort (x); |
4219e5cf773d
improve interp1 and pchip
Jaroslav Hajek <highegg@gmail.com>
parents:
9070
diff
changeset
|
186 y = y(p,:); |
5837 | 187 endif |
5838 | 188 |
18485 | 189 if (isnan (rightcontinuous)) |
15218
94d512d712e3
Modified interp1.m file to check whether X has distinct values or not.
Ben Abbott <bpabbott@mac.com>
parents:
15193
diff
changeset
|
190 ## If not specified, set the continuity condition |
94d512d712e3
Modified interp1.m file to check whether X has distinct values or not.
Ben Abbott <bpabbott@mac.com>
parents:
15193
diff
changeset
|
191 if (x(end) < x(1)) |
94d512d712e3
Modified interp1.m file to check whether X has distinct values or not.
Ben Abbott <bpabbott@mac.com>
parents:
15193
diff
changeset
|
192 rightcontinuous = false; |
94d512d712e3
Modified interp1.m file to check whether X has distinct values or not.
Ben Abbott <bpabbott@mac.com>
parents:
15193
diff
changeset
|
193 else |
94d512d712e3
Modified interp1.m file to check whether X has distinct values or not.
Ben Abbott <bpabbott@mac.com>
parents:
15193
diff
changeset
|
194 rightcontinuous = true; |
17306
09543e9c8f40
Use explicit form of end (endif, endfor, etc.) in core m-files.
Rik <rik@octave.org>
parents:
17281
diff
changeset
|
195 endif |
15193
2d5e4d283688
Modified interp1.m file to check whether X has distinct values or not.
Vivek Dogra <vivek.dogra.iitd@gmail.com>
parents:
14868
diff
changeset
|
196 endif |
2d5e4d283688
Modified interp1.m file to check whether X has distinct values or not.
Vivek Dogra <vivek.dogra.iitd@gmail.com>
parents:
14868
diff
changeset
|
197 |
15218
94d512d712e3
Modified interp1.m file to check whether X has distinct values or not.
Ben Abbott <bpabbott@mac.com>
parents:
15193
diff
changeset
|
198 if ((rightcontinuous && (x(end) < x(1))) |
17307
4448cc742880
Use '!' not operator rather than '~' in core m-files.
Rik <rik@octave.org>
parents:
17306
diff
changeset
|
199 || (! rightcontinuous && (x(end) > x(1)))) |
15218
94d512d712e3
Modified interp1.m file to check whether X has distinct values or not.
Ben Abbott <bpabbott@mac.com>
parents:
15193
diff
changeset
|
200 ## Switch between left-continuous and right-continuous |
94d512d712e3
Modified interp1.m file to check whether X has distinct values or not.
Ben Abbott <bpabbott@mac.com>
parents:
15193
diff
changeset
|
201 x = flipud (x); |
94d512d712e3
Modified interp1.m file to check whether X has distinct values or not.
Ben Abbott <bpabbott@mac.com>
parents:
15193
diff
changeset
|
202 y = flipud (y); |
17306
09543e9c8f40
Use explicit form of end (endif, endfor, etc.) in core m-files.
Rik <rik@octave.org>
parents:
17281
diff
changeset
|
203 endif |
15218
94d512d712e3
Modified interp1.m file to check whether X has distinct values or not.
Ben Abbott <bpabbott@mac.com>
parents:
15193
diff
changeset
|
204 |
9754
4219e5cf773d
improve interp1 and pchip
Jaroslav Hajek <highegg@gmail.com>
parents:
9070
diff
changeset
|
205 starmethod = method(1) == "*"; |
4219e5cf773d
improve interp1 and pchip
Jaroslav Hajek <highegg@gmail.com>
parents:
9070
diff
changeset
|
206 |
4219e5cf773d
improve interp1 and pchip
Jaroslav Hajek <highegg@gmail.com>
parents:
9070
diff
changeset
|
207 if (starmethod) |
4219e5cf773d
improve interp1 and pchip
Jaroslav Hajek <highegg@gmail.com>
parents:
9070
diff
changeset
|
208 dx = x(2) - x(1); |
4219e5cf773d
improve interp1 and pchip
Jaroslav Hajek <highegg@gmail.com>
parents:
9070
diff
changeset
|
209 else |
15218
94d512d712e3
Modified interp1.m file to check whether X has distinct values or not.
Ben Abbott <bpabbott@mac.com>
parents:
15193
diff
changeset
|
210 jumps = x(1:end-1) == x(2:end); |
9929
45c08d7c2c79
allow discontinuous interpolant in interp1
Jaroslav Hajek <highegg@gmail.com>
parents:
9769
diff
changeset
|
211 have_jumps = any (jumps); |
45c08d7c2c79
allow discontinuous interpolant in interp1
Jaroslav Hajek <highegg@gmail.com>
parents:
9769
diff
changeset
|
212 if (have_jumps) |
18485 | 213 if (strcmp (method, "linear") || strcmp (method, ("nearest"))) |
9929
45c08d7c2c79
allow discontinuous interpolant in interp1
Jaroslav Hajek <highegg@gmail.com>
parents:
9769
diff
changeset
|
214 if (any (jumps(1:nx-2) & jumps(2:nx-1))) |
18486
1ad77b3e6bef
interp1.m: Demote error to warning about multiple discontinuties (bug #41386).
Rik <rik@octave.org>
parents:
18485
diff
changeset
|
215 warning ("interp1: multiple discontinuities at the same X value"); |
9929
45c08d7c2c79
allow discontinuous interpolant in interp1
Jaroslav Hajek <highegg@gmail.com>
parents:
9769
diff
changeset
|
216 endif |
45c08d7c2c79
allow discontinuous interpolant in interp1
Jaroslav Hajek <highegg@gmail.com>
parents:
9769
diff
changeset
|
217 else |
15468
6437fa7263dd
use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents:
15218
diff
changeset
|
218 error ("interp1: discontinuities not supported for method '%s'", method); |
9929
45c08d7c2c79
allow discontinuous interpolant in interp1
Jaroslav Hajek <highegg@gmail.com>
parents:
9769
diff
changeset
|
219 endif |
5837 | 220 endif |
221 endif | |
222 | |
9754
4219e5cf773d
improve interp1 and pchip
Jaroslav Hajek <highegg@gmail.com>
parents:
9070
diff
changeset
|
223 ## Proceed with interpolating by all methods. |
4219e5cf773d
improve interp1 and pchip
Jaroslav Hajek <highegg@gmail.com>
parents:
9070
diff
changeset
|
224 switch (method) |
18485 | 225 |
17174
c3c1ebfaa7dc
maint: Use common indentation for switch statement.
Rik <rik@octave.org>
parents:
17088
diff
changeset
|
226 case "nearest" |
c3c1ebfaa7dc
maint: Use common indentation for switch statement.
Rik <rik@octave.org>
parents:
17088
diff
changeset
|
227 pp = mkpp ([x(1); (x(1:nx-1)+x(2:nx))/2; x(nx)], |
c3c1ebfaa7dc
maint: Use common indentation for switch statement.
Rik <rik@octave.org>
parents:
17088
diff
changeset
|
228 shiftdim (y, 1), szy(2:end)); |
c3c1ebfaa7dc
maint: Use common indentation for switch statement.
Rik <rik@octave.org>
parents:
17088
diff
changeset
|
229 pp.orient = "first"; |
13141
e81ddf9cacd5
maint: untabify and remove trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
12608
diff
changeset
|
230 |
17174
c3c1ebfaa7dc
maint: Use common indentation for switch statement.
Rik <rik@octave.org>
parents:
17088
diff
changeset
|
231 if (ispp) |
c3c1ebfaa7dc
maint: Use common indentation for switch statement.
Rik <rik@octave.org>
parents:
17088
diff
changeset
|
232 yi = pp; |
c3c1ebfaa7dc
maint: Use common indentation for switch statement.
Rik <rik@octave.org>
parents:
17088
diff
changeset
|
233 else |
c3c1ebfaa7dc
maint: Use common indentation for switch statement.
Rik <rik@octave.org>
parents:
17088
diff
changeset
|
234 yi = ppval (pp, reshape (xi, szx)); |
c3c1ebfaa7dc
maint: Use common indentation for switch statement.
Rik <rik@octave.org>
parents:
17088
diff
changeset
|
235 endif |
18485 | 236 |
17174
c3c1ebfaa7dc
maint: Use common indentation for switch statement.
Rik <rik@octave.org>
parents:
17088
diff
changeset
|
237 case "*nearest" |
c3c1ebfaa7dc
maint: Use common indentation for switch statement.
Rik <rik@octave.org>
parents:
17088
diff
changeset
|
238 pp = mkpp ([x(1), x(1)+[0.5:(nx-1)]*dx, x(nx)], |
c3c1ebfaa7dc
maint: Use common indentation for switch statement.
Rik <rik@octave.org>
parents:
17088
diff
changeset
|
239 shiftdim (y, 1), szy(2:end)); |
c3c1ebfaa7dc
maint: Use common indentation for switch statement.
Rik <rik@octave.org>
parents:
17088
diff
changeset
|
240 pp.orient = "first"; |
c3c1ebfaa7dc
maint: Use common indentation for switch statement.
Rik <rik@octave.org>
parents:
17088
diff
changeset
|
241 if (ispp) |
c3c1ebfaa7dc
maint: Use common indentation for switch statement.
Rik <rik@octave.org>
parents:
17088
diff
changeset
|
242 yi = pp; |
c3c1ebfaa7dc
maint: Use common indentation for switch statement.
Rik <rik@octave.org>
parents:
17088
diff
changeset
|
243 else |
c3c1ebfaa7dc
maint: Use common indentation for switch statement.
Rik <rik@octave.org>
parents:
17088
diff
changeset
|
244 yi = ppval (pp, reshape (xi, szx)); |
c3c1ebfaa7dc
maint: Use common indentation for switch statement.
Rik <rik@octave.org>
parents:
17088
diff
changeset
|
245 endif |
18485 | 246 |
17174
c3c1ebfaa7dc
maint: Use common indentation for switch statement.
Rik <rik@octave.org>
parents:
17088
diff
changeset
|
247 case "linear" |
18483
b06675ef40f2
interp1.m: Fix handling multi-column y-input with jumps (bug #40825).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents:
17744
diff
changeset
|
248 |
17174
c3c1ebfaa7dc
maint: Use common indentation for switch statement.
Rik <rik@octave.org>
parents:
17088
diff
changeset
|
249 xx = x; |
18483
b06675ef40f2
interp1.m: Fix handling multi-column y-input with jumps (bug #40825).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents:
17744
diff
changeset
|
250 yy = y; |
b06675ef40f2
interp1.m: Fix handling multi-column y-input with jumps (bug #40825).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents:
17744
diff
changeset
|
251 nxx = nx; |
17174
c3c1ebfaa7dc
maint: Use common indentation for switch statement.
Rik <rik@octave.org>
parents:
17088
diff
changeset
|
252 if (have_jumps) |
c3c1ebfaa7dc
maint: Use common indentation for switch statement.
Rik <rik@octave.org>
parents:
17088
diff
changeset
|
253 ## Omit zero-size intervals. |
18483
b06675ef40f2
interp1.m: Fix handling multi-column y-input with jumps (bug #40825).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents:
17744
diff
changeset
|
254 yy(jumps, :) = []; |
17174
c3c1ebfaa7dc
maint: Use common indentation for switch statement.
Rik <rik@octave.org>
parents:
17088
diff
changeset
|
255 xx(jumps) = []; |
18483
b06675ef40f2
interp1.m: Fix handling multi-column y-input with jumps (bug #40825).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents:
17744
diff
changeset
|
256 nxx = rows (xx); |
17174
c3c1ebfaa7dc
maint: Use common indentation for switch statement.
Rik <rik@octave.org>
parents:
17088
diff
changeset
|
257 endif |
12608
59e2460acae1
make piecewise polynomial (pp) functions more compatible
Kai Habel <kai.habel@gmx.de>
parents:
12459
diff
changeset
|
258 |
18483
b06675ef40f2
interp1.m: Fix handling multi-column y-input with jumps (bug #40825).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents:
17744
diff
changeset
|
259 dy = diff (yy); |
b06675ef40f2
interp1.m: Fix handling multi-column y-input with jumps (bug #40825).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents:
17744
diff
changeset
|
260 dx = diff (xx); |
b06675ef40f2
interp1.m: Fix handling multi-column y-input with jumps (bug #40825).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents:
17744
diff
changeset
|
261 dx = repmat (dx, [1 size(dy)(2:end)]); |
b06675ef40f2
interp1.m: Fix handling multi-column y-input with jumps (bug #40825).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents:
17744
diff
changeset
|
262 |
b06675ef40f2
interp1.m: Fix handling multi-column y-input with jumps (bug #40825).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents:
17744
diff
changeset
|
263 coefs = [(dy./dx).'(:), yy(1:nxx-1, :).'(:)]; |
b06675ef40f2
interp1.m: Fix handling multi-column y-input with jumps (bug #40825).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents:
17744
diff
changeset
|
264 |
17174
c3c1ebfaa7dc
maint: Use common indentation for switch statement.
Rik <rik@octave.org>
parents:
17088
diff
changeset
|
265 pp = mkpp (xx, coefs, szy(2:end)); |
c3c1ebfaa7dc
maint: Use common indentation for switch statement.
Rik <rik@octave.org>
parents:
17088
diff
changeset
|
266 pp.orient = "first"; |
12608
59e2460acae1
make piecewise polynomial (pp) functions more compatible
Kai Habel <kai.habel@gmx.de>
parents:
12459
diff
changeset
|
267 |
17174
c3c1ebfaa7dc
maint: Use common indentation for switch statement.
Rik <rik@octave.org>
parents:
17088
diff
changeset
|
268 if (ispp) |
c3c1ebfaa7dc
maint: Use common indentation for switch statement.
Rik <rik@octave.org>
parents:
17088
diff
changeset
|
269 yi = pp; |
c3c1ebfaa7dc
maint: Use common indentation for switch statement.
Rik <rik@octave.org>
parents:
17088
diff
changeset
|
270 else |
c3c1ebfaa7dc
maint: Use common indentation for switch statement.
Rik <rik@octave.org>
parents:
17088
diff
changeset
|
271 yi = ppval (pp, reshape (xi, szx)); |
c3c1ebfaa7dc
maint: Use common indentation for switch statement.
Rik <rik@octave.org>
parents:
17088
diff
changeset
|
272 endif |
12608
59e2460acae1
make piecewise polynomial (pp) functions more compatible
Kai Habel <kai.habel@gmx.de>
parents:
12459
diff
changeset
|
273 |
17174
c3c1ebfaa7dc
maint: Use common indentation for switch statement.
Rik <rik@octave.org>
parents:
17088
diff
changeset
|
274 case "*linear" |
c3c1ebfaa7dc
maint: Use common indentation for switch statement.
Rik <rik@octave.org>
parents:
17088
diff
changeset
|
275 dy = diff (y); |
c3c1ebfaa7dc
maint: Use common indentation for switch statement.
Rik <rik@octave.org>
parents:
17088
diff
changeset
|
276 coefs = [(dy/dx).'(:), y(1:nx-1, :).'(:)]; |
c3c1ebfaa7dc
maint: Use common indentation for switch statement.
Rik <rik@octave.org>
parents:
17088
diff
changeset
|
277 pp = mkpp (x, coefs, szy(2:end)); |
c3c1ebfaa7dc
maint: Use common indentation for switch statement.
Rik <rik@octave.org>
parents:
17088
diff
changeset
|
278 pp.orient = "first"; |
12608
59e2460acae1
make piecewise polynomial (pp) functions more compatible
Kai Habel <kai.habel@gmx.de>
parents:
12459
diff
changeset
|
279 |
17174
c3c1ebfaa7dc
maint: Use common indentation for switch statement.
Rik <rik@octave.org>
parents:
17088
diff
changeset
|
280 if (ispp) |
c3c1ebfaa7dc
maint: Use common indentation for switch statement.
Rik <rik@octave.org>
parents:
17088
diff
changeset
|
281 yi = pp; |
c3c1ebfaa7dc
maint: Use common indentation for switch statement.
Rik <rik@octave.org>
parents:
17088
diff
changeset
|
282 else |
c3c1ebfaa7dc
maint: Use common indentation for switch statement.
Rik <rik@octave.org>
parents:
17088
diff
changeset
|
283 yi = ppval (pp, reshape (xi, szx)); |
c3c1ebfaa7dc
maint: Use common indentation for switch statement.
Rik <rik@octave.org>
parents:
17088
diff
changeset
|
284 endif |
5837 | 285 |
17174
c3c1ebfaa7dc
maint: Use common indentation for switch statement.
Rik <rik@octave.org>
parents:
17088
diff
changeset
|
286 case {"pchip", "*pchip", "cubic", "*cubic"} |
c3c1ebfaa7dc
maint: Use common indentation for switch statement.
Rik <rik@octave.org>
parents:
17088
diff
changeset
|
287 if (nx == 2 || starmethod) |
c3c1ebfaa7dc
maint: Use common indentation for switch statement.
Rik <rik@octave.org>
parents:
17088
diff
changeset
|
288 x = linspace (x(1), x(nx), ny); |
c3c1ebfaa7dc
maint: Use common indentation for switch statement.
Rik <rik@octave.org>
parents:
17088
diff
changeset
|
289 endif |
13141
e81ddf9cacd5
maint: untabify and remove trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
12608
diff
changeset
|
290 |
17174
c3c1ebfaa7dc
maint: Use common indentation for switch statement.
Rik <rik@octave.org>
parents:
17088
diff
changeset
|
291 if (ispp) |
c3c1ebfaa7dc
maint: Use common indentation for switch statement.
Rik <rik@octave.org>
parents:
17088
diff
changeset
|
292 y = shiftdim (reshape (y, szy), 1); |
c3c1ebfaa7dc
maint: Use common indentation for switch statement.
Rik <rik@octave.org>
parents:
17088
diff
changeset
|
293 yi = pchip (x, y); |
c3c1ebfaa7dc
maint: Use common indentation for switch statement.
Rik <rik@octave.org>
parents:
17088
diff
changeset
|
294 yi.orient = "first"; |
c3c1ebfaa7dc
maint: Use common indentation for switch statement.
Rik <rik@octave.org>
parents:
17088
diff
changeset
|
295 else |
c3c1ebfaa7dc
maint: Use common indentation for switch statement.
Rik <rik@octave.org>
parents:
17088
diff
changeset
|
296 y = shiftdim (y, 1); |
c3c1ebfaa7dc
maint: Use common indentation for switch statement.
Rik <rik@octave.org>
parents:
17088
diff
changeset
|
297 yi = pchip (x, y, reshape (xi, szx)); |
c3c1ebfaa7dc
maint: Use common indentation for switch statement.
Rik <rik@octave.org>
parents:
17088
diff
changeset
|
298 if (! isvector (y)) |
c3c1ebfaa7dc
maint: Use common indentation for switch statement.
Rik <rik@octave.org>
parents:
17088
diff
changeset
|
299 yi = shiftdim (yi, 1); |
c3c1ebfaa7dc
maint: Use common indentation for switch statement.
Rik <rik@octave.org>
parents:
17088
diff
changeset
|
300 endif |
c3c1ebfaa7dc
maint: Use common indentation for switch statement.
Rik <rik@octave.org>
parents:
17088
diff
changeset
|
301 endif |
18485 | 302 |
17174
c3c1ebfaa7dc
maint: Use common indentation for switch statement.
Rik <rik@octave.org>
parents:
17088
diff
changeset
|
303 case {"spline", "*spline"} |
c3c1ebfaa7dc
maint: Use common indentation for switch statement.
Rik <rik@octave.org>
parents:
17088
diff
changeset
|
304 if (nx == 2 || starmethod) |
c3c1ebfaa7dc
maint: Use common indentation for switch statement.
Rik <rik@octave.org>
parents:
17088
diff
changeset
|
305 x = linspace (x(1), x(nx), ny); |
14492
7ce925166af6
Fix inconsistent orientation of output matrix for interp1.
Olaf Till <i7tiol@t-online.de>
parents:
14363
diff
changeset
|
306 endif |
13141
e81ddf9cacd5
maint: untabify and remove trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
12608
diff
changeset
|
307 |
17174
c3c1ebfaa7dc
maint: Use common indentation for switch statement.
Rik <rik@octave.org>
parents:
17088
diff
changeset
|
308 if (ispp) |
c3c1ebfaa7dc
maint: Use common indentation for switch statement.
Rik <rik@octave.org>
parents:
17088
diff
changeset
|
309 y = shiftdim (reshape (y, szy), 1); |
c3c1ebfaa7dc
maint: Use common indentation for switch statement.
Rik <rik@octave.org>
parents:
17088
diff
changeset
|
310 yi = spline (x, y); |
c3c1ebfaa7dc
maint: Use common indentation for switch statement.
Rik <rik@octave.org>
parents:
17088
diff
changeset
|
311 yi.orient = "first"; |
c3c1ebfaa7dc
maint: Use common indentation for switch statement.
Rik <rik@octave.org>
parents:
17088
diff
changeset
|
312 else |
c3c1ebfaa7dc
maint: Use common indentation for switch statement.
Rik <rik@octave.org>
parents:
17088
diff
changeset
|
313 y = shiftdim (y, 1); |
c3c1ebfaa7dc
maint: Use common indentation for switch statement.
Rik <rik@octave.org>
parents:
17088
diff
changeset
|
314 yi = spline (x, y, reshape (xi, szx)); |
c3c1ebfaa7dc
maint: Use common indentation for switch statement.
Rik <rik@octave.org>
parents:
17088
diff
changeset
|
315 if (! isvector (y)) |
c3c1ebfaa7dc
maint: Use common indentation for switch statement.
Rik <rik@octave.org>
parents:
17088
diff
changeset
|
316 yi = shiftdim (yi, 1); |
c3c1ebfaa7dc
maint: Use common indentation for switch statement.
Rik <rik@octave.org>
parents:
17088
diff
changeset
|
317 endif |
14492
7ce925166af6
Fix inconsistent orientation of output matrix for interp1.
Olaf Till <i7tiol@t-online.de>
parents:
14363
diff
changeset
|
318 endif |
18485 | 319 |
17174
c3c1ebfaa7dc
maint: Use common indentation for switch statement.
Rik <rik@octave.org>
parents:
17088
diff
changeset
|
320 otherwise |
c3c1ebfaa7dc
maint: Use common indentation for switch statement.
Rik <rik@octave.org>
parents:
17088
diff
changeset
|
321 error ("interp1: invalid method '%s'", method); |
18485 | 322 |
9754
4219e5cf773d
improve interp1 and pchip
Jaroslav Hajek <highegg@gmail.com>
parents:
9070
diff
changeset
|
323 endswitch |
5837 | 324 |
18485 | 325 if (! ispp && ! ischar (extrap)) |
326 ## determine which values are out of range and set them to extrap, | |
327 ## unless extrap == "extrap". | |
328 minx = min (x(1), x(nx)); | |
329 maxx = max (x(1), x(nx)); | |
9754
4219e5cf773d
improve interp1 and pchip
Jaroslav Hajek <highegg@gmail.com>
parents:
9070
diff
changeset
|
330 |
18485 | 331 outliers = xi < minx | ! (xi <= maxx); # this even catches NaNs |
332 if (size_equal (outliers, yi)) | |
333 yi(outliers) = extrap; | |
334 yi = reshape (yi, szx); | |
335 elseif (! isvector (yi)) | |
336 yi(outliers, :) = extrap; | |
337 else | |
338 yi(outliers.') = extrap; | |
9754
4219e5cf773d
improve interp1 and pchip
Jaroslav Hajek <highegg@gmail.com>
parents:
9070
diff
changeset
|
339 endif |
5837 | 340 endif |
341 | |
342 endfunction | |
343 | |
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 |
5837 | 345 %!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
|
346 %! clf; |
14363
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14359
diff
changeset
|
347 %! 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
|
348 %! 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
|
349 %! 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
|
350 %! 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
|
351 %! 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
|
352 %! 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
|
353 %! 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
|
354 %! legend ("original", "nearest", "linear", "pchip", "spline"); |
5837 | 355 %! %-------------------------------------------------------- |
356 %! % confirm that interpolated function matches the original | |
357 | |
358 %!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
|
359 %! clf; |
14363
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14359
diff
changeset
|
360 %! 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
|
361 %! 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
|
362 %! 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
|
363 %! 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
|
364 %! 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
|
365 %! 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
|
366 %! 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
|
367 %! legend ("*original", "*nearest", "*linear", "*cubic", "*spline"); |
5837 | 368 %! %-------------------------------------------------------- |
369 %! % confirm that interpolated function matches the original | |
370 | |
6721 | 371 %!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
|
372 %! clf; |
6721 | 373 %! t = 0 : 0.3 : pi; dt = t(2)-t(1); |
374 %! n = length (t); k = 100; dti = dt*n/k; | |
375 %! ti = t(1) + [0 : k-1]*dti; | |
376 %! 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
|
377 %! 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
|
378 %! 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
|
379 %! 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
|
380 %! 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
|
381 %! 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
|
382 %! title ("Second derivative of interpolated 'sin (4*t + 0.3) .* cos (3*t - 0.1)'"); |
6721 | 383 |
9929
45c08d7c2c79
allow discontinuous interpolant in interp1
Jaroslav Hajek <highegg@gmail.com>
parents:
9769
diff
changeset
|
384 %!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
|
385 %! clf; |
14363
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14359
diff
changeset
|
386 %! 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
|
387 %! 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
|
388 %! 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
|
389 %! 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
|
390 %! 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
|
391 %! legend ("original", "nearest", "linear"); |
9929
45c08d7c2c79
allow discontinuous interpolant in interp1
Jaroslav Hajek <highegg@gmail.com>
parents:
9769
diff
changeset
|
392 %! %-------------------------------------------------------- |
45c08d7c2c79
allow discontinuous interpolant in interp1
Jaroslav Hajek <highegg@gmail.com>
parents:
9769
diff
changeset
|
393 %! % confirm that interpolated function matches the original |
45c08d7c2c79
allow discontinuous interpolant in interp1
Jaroslav Hajek <highegg@gmail.com>
parents:
9769
diff
changeset
|
394 |
15218
94d512d712e3
Modified interp1.m file to check whether X has distinct values or not.
Ben Abbott <bpabbott@mac.com>
parents:
15193
diff
changeset
|
395 %!demo |
94d512d712e3
Modified interp1.m file to check whether X has distinct values or not.
Ben Abbott <bpabbott@mac.com>
parents:
15193
diff
changeset
|
396 %! clf; |
94d512d712e3
Modified interp1.m file to check whether X has distinct values or not.
Ben Abbott <bpabbott@mac.com>
parents:
15193
diff
changeset
|
397 %! x = 0:0.5:3; |
94d512d712e3
Modified interp1.m file to check whether X has distinct values or not.
Ben Abbott <bpabbott@mac.com>
parents:
15193
diff
changeset
|
398 %! x1 = [3 2 2 1]; |
94d512d712e3
Modified interp1.m file to check whether X has distinct values or not.
Ben Abbott <bpabbott@mac.com>
parents:
15193
diff
changeset
|
399 %! x2 = [1 2 2 3]; |
94d512d712e3
Modified interp1.m file to check whether X has distinct values or not.
Ben Abbott <bpabbott@mac.com>
parents:
15193
diff
changeset
|
400 %! y1 = [1 1 0 0]; |
94d512d712e3
Modified interp1.m file to check whether X has distinct values or not.
Ben Abbott <bpabbott@mac.com>
parents:
15193
diff
changeset
|
401 %! y2 = [0 0 1 1]; |
94d512d712e3
Modified interp1.m file to check whether X has distinct values or not.
Ben Abbott <bpabbott@mac.com>
parents:
15193
diff
changeset
|
402 %! h = plot (x, interp1 (x1, y1, x), 'b', x1, y1, 'sb'); |
94d512d712e3
Modified interp1.m file to check whether X has distinct values or not.
Ben Abbott <bpabbott@mac.com>
parents:
15193
diff
changeset
|
403 %! hold on |
94d512d712e3
Modified interp1.m file to check whether X has distinct values or not.
Ben Abbott <bpabbott@mac.com>
parents:
15193
diff
changeset
|
404 %! g = plot (x, interp1 (x2, y2, x), 'r', x2, y2, '*r'); |
18485 | 405 %! axis ([0.5 3.5 -0.5 1.5]) |
406 %! legend ([h(1), g(1)], {'left-continuous', 'right-continuous'}, ... | |
407 %! 'location', 'northwest') | |
15218
94d512d712e3
Modified interp1.m file to check whether X has distinct values or not.
Ben Abbott <bpabbott@mac.com>
parents:
15193
diff
changeset
|
408 %! legend boxoff |
94d512d712e3
Modified interp1.m file to check whether X has distinct values or not.
Ben Abbott <bpabbott@mac.com>
parents:
15193
diff
changeset
|
409 %! %-------------------------------------------------------- |
18485 | 410 %! % red curve is left-continuous and blue is right-continuous at x = 2 |
15218
94d512d712e3
Modified interp1.m file to check whether X has distinct values or not.
Ben Abbott <bpabbott@mac.com>
parents:
15193
diff
changeset
|
411 |
12608
59e2460acae1
make piecewise polynomial (pp) functions more compatible
Kai Habel <kai.habel@gmx.de>
parents:
12459
diff
changeset
|
412 ##FIXME: add test for n-d arguments here |
9929
45c08d7c2c79
allow discontinuous interpolant in interp1
Jaroslav Hajek <highegg@gmail.com>
parents:
9769
diff
changeset
|
413 |
6374 | 414 ## For each type of interpolated test, confirm that the interpolated |
415 ## 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
|
416 ## from the knots are requested, but only "nearest" and "linear" |
6374 | 417 ## confirm they are the correct values. |
418 | |
5837 | 419 %!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
|
420 %! 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
|
421 %! yp = sin (2*pi*xp/5); |
6374 | 422 %! xi = [-1, 0, 2.2, 4, 6.6, 10, 11]; |
423 | |
424 ## The following BLOCK/ENDBLOCK section is repeated for each style | |
425 ## nearest, linear, cubic, spline, pchip | |
426 ## The test for ppval of cubic has looser tolerance, but otherwise | |
427 ## the tests are identical. | |
428 ## 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
|
429 ## be sure to add them to both sections of each block. One test, |
6374 | 430 ## style vs. *style, occurs only in the first section. |
431 ## 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
|
432 |
5837 | 433 %!test style = "nearest"; |
6374 | 434 ## BLOCK |
14363
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, [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
|
436 %!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
|
437 %!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
|
438 %!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
|
439 %!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
|
440 %!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
|
441 %!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
|
442 %!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
|
443 %! [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
|
444 %!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
|
445 %! 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
|
446 %!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
|
447 %! 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
|
448 %!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
|
449 %!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
|
450 %! 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
|
451 %!test style = ["*",style]; |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14359
diff
changeset
|
452 %!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
|
453 %!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
|
454 %!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
|
455 %!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
|
456 %!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
|
457 %!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
|
458 %!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
|
459 %!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
|
460 %! [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
|
461 %!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
|
462 %! 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
|
463 %!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
|
464 %! 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
|
465 %!error interp1 (1,1,1, style) |
6374 | 466 ## 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
|
467 |
14363
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14359
diff
changeset
|
468 %!test style = "linear"; |
6374 | 469 ## BLOCK |
14363
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, [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
|
471 %!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
|
472 %!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
|
473 %!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
|
474 %!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
|
475 %!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
|
476 %!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
|
477 %!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
|
478 %! [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
|
479 %!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
|
480 %! 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
|
481 %!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
|
482 %! 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
|
483 %!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
|
484 %!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
|
485 %! 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
|
486 %!test style = ['*',style]; |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14359
diff
changeset
|
487 %!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
|
488 %!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
|
489 %!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
|
490 %!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
|
491 %!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
|
492 %!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
|
493 %!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
|
494 %!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
|
495 %! [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
|
496 %!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
|
497 %! 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
|
498 %!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
|
499 %! interp1 (xp,yp,xi,style,"extrap"),10*eps) |
15218
94d512d712e3
Modified interp1.m file to check whether X has distinct values or not.
Ben Abbott <bpabbott@mac.com>
parents:
15193
diff
changeset
|
500 %!assert (interp1 ([1 2 2 3], [1 2 3 4], 2), 3); |
94d512d712e3
Modified interp1.m file to check whether X has distinct values or not.
Ben Abbott <bpabbott@mac.com>
parents:
15193
diff
changeset
|
501 %!assert (interp1 ([3 2 2 1], [4 3 2 1], 2), 2); |
14363
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14359
diff
changeset
|
502 %!error interp1 (1,1,1, style) |
6374 | 503 ## 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
|
504 |
14363
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14359
diff
changeset
|
505 %!test style = "cubic"; |
6374 | 506 ## BLOCK |
14363
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14359
diff
changeset
|
507 %!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
|
508 %!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
|
509 %!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
|
510 %!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
|
511 %!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
|
512 %!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
|
513 %!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
|
514 %!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
|
515 %! [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
|
516 %!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
|
517 %! 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
|
518 %!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
|
519 %! 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
|
520 %!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
|
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',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
|
523 %!test style = ["*",style]; |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14359
diff
changeset
|
524 %!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
|
525 %!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
|
526 %!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
|
527 %!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
|
528 %!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
|
529 %!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
|
530 %!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
|
531 %!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
|
532 %! [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
|
533 %!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
|
534 %! 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
|
535 %!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
|
536 %! 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
|
537 %!error interp1 (1,1,1, style) |
6374 | 538 ## 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
|
539 |
14363
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14359
diff
changeset
|
540 %!test style = "pchip"; |
6374 | 541 ## BLOCK |
14363
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14359
diff
changeset
|
542 %!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
|
543 %!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
|
544 %!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
|
545 %!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
|
546 %!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
|
547 %!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
|
548 %!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
|
549 %!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
|
550 %! [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
|
551 %!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
|
552 %! 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
|
553 %!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
|
554 %! 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
|
555 %!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
|
556 %!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
|
557 %! 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
|
558 %!test style = ["*",style]; |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14359
diff
changeset
|
559 %!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
|
560 %!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
|
561 %!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
|
562 %!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
|
563 %!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
|
564 %!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
|
565 %!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
|
566 %!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
|
567 %! [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
|
568 %!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
|
569 %! 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
|
570 %!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
|
571 %! 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
|
572 %!error interp1 (1,1,1, style) |
6374 | 573 ## 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
|
574 |
14363
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14359
diff
changeset
|
575 %!test style = "spline"; |
6374 | 576 ## BLOCK |
14363
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14359
diff
changeset
|
577 %!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
|
578 %!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
|
579 %!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
|
580 %!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
|
581 %!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
|
582 %!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
|
583 %!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
|
584 %!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
|
585 %! [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
|
586 %!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
|
587 %! 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
|
588 %!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
|
589 %! 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
|
590 %!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
|
591 %!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
|
592 %! 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
|
593 %!test style = ["*",style]; |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14359
diff
changeset
|
594 %!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
|
595 %!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
|
596 %!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
|
597 %!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
|
598 %!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
|
599 %!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
|
600 %!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
|
601 %!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
|
602 %! [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
|
603 %!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
|
604 %! 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
|
605 %!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
|
606 %! 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
|
607 %!error interp1 (1,1,1, style) |
6374 | 608 ## ENDBLOCK |
609 ## ENDBLOCKTEST | |
5837 | 610 |
18485 | 611 ## test extrapolation (linear) |
14363
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14359
diff
changeset
|
612 %!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
|
613 %!assert (interp1 (xp, yp, [-1, max(xp)+1],"linear",5), [5, 5]) |
5837 | 614 |
18485 | 615 ## Basic sanity checks |
14363
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14359
diff
changeset
|
616 %!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
|
617 %!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
|
618 %!assert (interp1 (1:4,1:4,1.4,"cubic"), 1.4) |
18485 | 619 %!assert (interp1 (1:2,1:2,1.1,"spline"), 1.1) |
14363
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14359
diff
changeset
|
620 %!assert (interp1 (1:3,1:3,1.4,"spline"), 1.4) |
5837 | 621 |
14363
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14359
diff
changeset
|
622 %!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
|
623 %!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
|
624 %!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
|
625 %!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
|
626 %!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
|
627 |
14363
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14359
diff
changeset
|
628 %!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
|
629 |
12608
59e2460acae1
make piecewise polynomial (pp) functions more compatible
Kai Habel <kai.habel@gmx.de>
parents:
12459
diff
changeset
|
630 %!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
|
631 %!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
|
632 |
18485 | 633 ## Left and Right discontinuities |
634 %!assert (interp1 ([1,2,2,3,4],[0,1,4,2,1],[-1,1.5,2,2.5,3.5], "linear", "extrap", "right"), [-8,2,4,3,1.5]) | |
635 %!assert (interp1 ([1,2,2,3,4],[0,1,4,2,1],[-1,1.5,2,2.5,3.5], "linear", "extrap", "left"), [-2,0.5,1,1.5,1.5]) | |
636 | |
637 %% Test input validation | |
14363
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14359
diff
changeset
|
638 %!error interp1 () |
18485 | 639 %!error interp1 (1,2,3,4,5,6,7) |
640 %!error <table too short> interp1 (1,1,1, "linear") | |
641 %!error <table too short> interp1 (1,1,1, "*nearest") | |
642 %!error <table too short> interp1 (1,1,1, "*linear") | |
18486
1ad77b3e6bef
interp1.m: Demote error to warning about multiple discontinuties (bug #41386).
Rik <rik@octave.org>
parents:
18485
diff
changeset
|
643 %!warning <multiple discontinuities> interp1 ([1 1 1 2], [1 2 3 4], 1); |
18485 | 644 %!error <discontinuities not supported> interp1 ([1 1],[1 2],1, "pchip") |
645 %!error <discontinuities not supported> interp1 ([1 1],[1 2],1, "cubic") | |
646 %!error <discontinuities not supported> interp1 ([1 1],[1 2],1, "spline") | |
647 %!error <invalid method> interp1 (1:2,1:2,1, "bogus") | |
14363
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14359
diff
changeset
|
648 |