Mercurial > hg > octave-nkf
annotate scripts/general/interp1.m @ 16816:12005245b645
doc: Periodic grammarcheck of documentation.
* doc/interpreter/basics.txi, doc/interpreter/container.txi,
doc/interpreter/contrib.txi, doc/interpreter/diagperm.txi,
doc/interpreter/errors.txi, doc/interpreter/install.txi,
doc/interpreter/sparse.txi, libinterp/corefcn/ellipj.cc,
libinterp/corefcn/mappers.cc, libinterp/corefcn/regexp.cc,
libinterp/corefcn/tril.cc, libinterp/dldfcn/__init_fltk__.cc,
libinterp/dldfcn/fftw.cc, libinterp/interpfcn/dirfns.cc,
libinterp/interpfcn/input.cc, libinterp/octave-value/ov-fcn-inline.cc,
libinterp/octave-value/ov-struct.cc, scripts/@ftp/cd.m,
scripts/general/interp1.m, scripts/general/num2str.m, scripts/image/ind2rgb.m,
scripts/image/rgb2ind.m, scripts/io/importdata.m, scripts/io/textread.m,
scripts/java/javamem.m, scripts/linear-algebra/condest.m,
scripts/linear-algebra/onenormest.m, scripts/miscellaneous/error_ids.m,
scripts/miscellaneous/getfield.m, scripts/miscellaneous/setfield.m,
scripts/plot/area.m, scripts/plot/pcolor.m, scripts/plot/stairs.m,
scripts/set/powerset.m, scripts/sparse/bicg.m, scripts/sparse/bicgstab.m,
scripts/sparse/cgs.m, scripts/specfun/ellipke.m,
scripts/special-matrix/gallery.m, scripts/strings/strjoin.m,
scripts/strings/strsplit.m, scripts/testfun/__have_feature__.m,
scripts/testfun/__printf_assert__.m, scripts/testfun/__prog_output_assert__.m,
scripts/testfun/__run_test_suite__.m: grammarcheck documentation.
author | Rik <rik@octave.org> |
---|---|
date | Sat, 22 Jun 2013 19:47:32 -0700 |
parents | 6437fa7263dd |
children | bb3a1ec7cc4b |
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 ## |
15218
94d512d712e3
Modified interp1.m file to check whether X has distinct values or not.
Ben Abbott <bpabbott@mac.com>
parents:
15193
diff
changeset
|
27 ## One-dimensional interpolation. Interpolates to determine the value of |
94d512d712e3
Modified interp1.m file to check whether X has distinct values or not.
Ben Abbott <bpabbott@mac.com>
parents:
15193
diff
changeset
|
28 ## @var{yi} at the points, @var{xi}. If not specified, @var{x} is taken |
94d512d712e3
Modified interp1.m file to check whether X has distinct values or not.
Ben Abbott <bpabbott@mac.com>
parents:
15193
diff
changeset
|
29 ## to be the indices of @var{y}. If @var{y} is an array, treat the columns |
7001 | 30 ## of @var{y} separately. |
5837 | 31 ## |
32 ## Method is one of: | |
33 ## | |
34 ## @table @asis | |
14359
7277fe922e99
doc: Use Octave preference for double quote in docstrings in scripts/
Rik <octave@nomad.inbox5.com>
parents:
14335
diff
changeset
|
35 ## @item "nearest" |
9070
e9dc2ed2ec0f
Cleanup documentation for poly.texi, interp.texi, geometry.texi
Rik <rdrider0-list@yahoo.com>
parents:
9051
diff
changeset
|
36 ## Return the nearest neighbor. |
10821
693e22af08ae
Grammarcheck documentation of m-files
Rik <octave@nomad.inbox5.com>
parents:
10820
diff
changeset
|
37 ## |
14359
7277fe922e99
doc: Use Octave preference for double quote in docstrings in scripts/
Rik <octave@nomad.inbox5.com>
parents:
14335
diff
changeset
|
38 ## @item "linear" |
9070
e9dc2ed2ec0f
Cleanup documentation for poly.texi, interp.texi, geometry.texi
Rik <rdrider0-list@yahoo.com>
parents:
9051
diff
changeset
|
39 ## Linear interpolation from nearest neighbors |
10821
693e22af08ae
Grammarcheck documentation of m-files
Rik <octave@nomad.inbox5.com>
parents:
10820
diff
changeset
|
40 ## |
14359
7277fe922e99
doc: Use Octave preference for double quote in docstrings in scripts/
Rik <octave@nomad.inbox5.com>
parents:
14335
diff
changeset
|
41 ## @item "pchip" |
11536
702dbd0c53f5
Add undocumented ppder, ppint, ppjumps functions to documentation.
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
42 ## Piecewise cubic Hermite interpolating polynomial |
10821
693e22af08ae
Grammarcheck documentation of m-files
Rik <octave@nomad.inbox5.com>
parents:
10820
diff
changeset
|
43 ## |
14359
7277fe922e99
doc: Use Octave preference for double quote in docstrings in scripts/
Rik <octave@nomad.inbox5.com>
parents:
14335
diff
changeset
|
44 ## @item "cubic" |
12608
59e2460acae1
make piecewise polynomial (pp) functions more compatible
Kai Habel <kai.habel@gmx.de>
parents:
12459
diff
changeset
|
45 ## Cubic interpolation (same as @code{pchip}) |
10821
693e22af08ae
Grammarcheck documentation of m-files
Rik <octave@nomad.inbox5.com>
parents:
10820
diff
changeset
|
46 ## |
14359
7277fe922e99
doc: Use Octave preference for double quote in docstrings in scripts/
Rik <octave@nomad.inbox5.com>
parents:
14335
diff
changeset
|
47 ## @item "spline" |
12175
2090995ca588
Correct en-dash,em-dash instances in docstrings.
Rik <octave@nomad.inbox5.com>
parents:
11587
diff
changeset
|
48 ## Cubic spline interpolation---smooth first and second derivatives |
5837 | 49 ## throughout the curve |
50 ## @end table | |
51 ## | |
52 ## Appending '*' to the start of the above method 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
|
53 ## 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
|
54 ## 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
|
55 ## and is never slower. The default method is "linear". |
5837 | 56 ## |
14359
7277fe922e99
doc: Use Octave preference for double quote in docstrings in scripts/
Rik <octave@nomad.inbox5.com>
parents:
14335
diff
changeset
|
57 ## If @var{extrap} is the string "extrap", then extrapolate values beyond |
5837 | 58 ## the endpoints. If @var{extrap} is a number, replace values beyond the |
6742 | 59 ## endpoints with that number. If @var{extrap} is missing, assume NA. |
5837 | 60 ## |
14359
7277fe922e99
doc: Use Octave preference for double quote in docstrings in scripts/
Rik <octave@nomad.inbox5.com>
parents:
14335
diff
changeset
|
61 ## 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
|
62 ## supplied and @code{interp1} returns the piecewise polynomial that |
5837 | 63 ## can later be used with @code{ppval} to evaluate the interpolation. |
64 ## 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
|
65 ## @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
|
66 ## @var{xi}, @var{method}, "extrap")}. |
5837 | 67 ## |
10711
fbd7843974fa
Periodic grammar check of documentation files to ensure common format.
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
68 ## 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
|
69 ## 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
|
70 ## 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
|
71 ## 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
|
72 ## 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
|
73 ## The continuity condition of the interpolant may be specified by using |
94d512d712e3
Modified interp1.m file to check whether X has distinct values or not.
Ben Abbott <bpabbott@mac.com>
parents:
15193
diff
changeset
|
74 ## the options, "-left" or "-right", to select a 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
|
75 ## or right-continuous interpolant, respectively. |
94d512d712e3
Modified interp1.m file to check whether X has distinct values or not.
Ben Abbott <bpabbott@mac.com>
parents:
15193
diff
changeset
|
76 ## Discontinuous interpolation is only allowed for "nearest" and "linear" |
94d512d712e3
Modified interp1.m file to check whether X has distinct values or not.
Ben Abbott <bpabbott@mac.com>
parents:
15193
diff
changeset
|
77 ## methods; in all other cases, the @var{x}-values must be unique. |
9929
45c08d7c2c79
allow discontinuous interpolant in interp1
Jaroslav Hajek <highegg@gmail.com>
parents:
9769
diff
changeset
|
78 ## |
5837 | 79 ## An example of the use of @code{interp1} is |
80 ## | |
81 ## @example | |
82 ## @group | |
8507 | 83 ## xf = [0:0.05:10]; |
84 ## yf = sin (2*pi*xf/5); | |
85 ## xp = [0:10]; | |
86 ## yp = sin (2*pi*xp/5); | |
87 ## lin = interp1 (xp, yp, xf); | |
88 ## spl = interp1 (xp, yp, xf, "spline"); | |
89 ## cub = interp1 (xp, yp, xf, "cubic"); | |
90 ## near = interp1 (xp, yp, xf, "nearest"); | |
91 ## plot (xf, yf, "r", xf, lin, "g", xf, spl, "b", | |
92 ## 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
|
93 ## legend ("original", "linear", "spline", "cubic", "nearest"); |
5837 | 94 ## @end group |
95 ## @end example | |
96 ## | |
97 ## @seealso{interpft} | |
98 ## @end deftypefn | |
99 | |
5838 | 100 ## Author: Paul Kienzle |
101 ## Date: 2000-03-25 | |
5837 | 102 ## added 'nearest' as suggested by Kai Habel |
103 ## 2000-07-17 Paul Kienzle | |
104 ## added '*' methods and matrix y | |
105 ## check for proper table lengths | |
106 ## 2002-01-23 Paul Kienzle | |
107 ## fixed extrapolation | |
108 | |
5838 | 109 function yi = interp1 (x, y, varargin) |
5837 | 110 |
10820
c44c786f87ba
interp1.m: When absent set X equal to the inices of Y.
Ben Abbott <bpabbott@mac.com>
parents:
10793
diff
changeset
|
111 if (nargin < 2 || nargin > 6) |
5837 | 112 print_usage (); |
113 endif | |
114 | |
115 method = "linear"; | |
6742 | 116 extrap = NA; |
5837 | 117 xi = []; |
12608
59e2460acae1
make piecewise polynomial (pp) functions more compatible
Kai Habel <kai.habel@gmx.de>
parents:
12459
diff
changeset
|
118 ispp = false; |
5837 | 119 firstnumeric = true; |
15218
94d512d712e3
Modified interp1.m file to check whether X has distinct values or not.
Ben Abbott <bpabbott@mac.com>
parents:
15193
diff
changeset
|
120 rightcontinuous = []; |
5837 | 121 |
122 if (nargin > 2) | |
5838 | 123 for i = 1:length (varargin) |
5837 | 124 arg = varargin{i}; |
5838 | 125 if (ischar (arg)) |
10549 | 126 arg = tolower (arg); |
127 if (strcmp ("extrap", arg)) | |
128 extrap = "extrap"; | |
129 elseif (strcmp ("pp", arg)) | |
12608
59e2460acae1
make piecewise polynomial (pp) functions more compatible
Kai Habel <kai.habel@gmx.de>
parents:
12459
diff
changeset
|
130 ispp = true; |
15218
94d512d712e3
Modified interp1.m file to check whether X has distinct values or not.
Ben Abbott <bpabbott@mac.com>
parents:
15193
diff
changeset
|
131 elseif (any (strcmp ({"right", "-right"}, arg))) |
94d512d712e3
Modified interp1.m file to check whether X has distinct values or not.
Ben Abbott <bpabbott@mac.com>
parents:
15193
diff
changeset
|
132 rightcontinuous = true; |
94d512d712e3
Modified interp1.m file to check whether X has distinct values or not.
Ben Abbott <bpabbott@mac.com>
parents:
15193
diff
changeset
|
133 elseif (any (strcmp ({"left", "-left"}, arg))) |
94d512d712e3
Modified interp1.m file to check whether X has distinct values or not.
Ben Abbott <bpabbott@mac.com>
parents:
15193
diff
changeset
|
134 rightcontinuous = false; |
10549 | 135 else |
136 method = arg; | |
137 endif | |
5837 | 138 else |
10549 | 139 if (firstnumeric) |
140 xi = arg; | |
141 firstnumeric = false; | |
142 else | |
143 extrap = arg; | |
144 endif | |
5837 | 145 endif |
146 endfor | |
147 endif | |
148 | |
12608
59e2460acae1
make piecewise polynomial (pp) functions more compatible
Kai Habel <kai.habel@gmx.de>
parents:
12459
diff
changeset
|
149 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
|
150 xi = y; |
c44c786f87ba
interp1.m: When absent set X equal to the inices of Y.
Ben Abbott <bpabbott@mac.com>
parents:
10793
diff
changeset
|
151 y = x; |
14868
5d3a684236b0
maint: Use Octave coding conventions for cuddling parentheses in scripts directory
Rik <octave@nomad.inbox5.com>
parents:
14492
diff
changeset
|
152 x = 1:numel (y); |
10820
c44c786f87ba
interp1.m: When absent set X equal to the inices of Y.
Ben Abbott <bpabbott@mac.com>
parents:
10793
diff
changeset
|
153 endif |
c44c786f87ba
interp1.m: When absent set X equal to the inices of Y.
Ben Abbott <bpabbott@mac.com>
parents:
10793
diff
changeset
|
154 |
5837 | 155 ## reshape matrices for convenience |
156 x = x(:); | |
9754
4219e5cf773d
improve interp1 and pchip
Jaroslav Hajek <highegg@gmail.com>
parents:
9070
diff
changeset
|
157 nx = rows (x); |
9769
9a1c4fe44af8
small interp1 simplification
Jaroslav Hajek <highegg@gmail.com>
parents:
9754
diff
changeset
|
158 szx = size (xi); |
9754
4219e5cf773d
improve interp1 and pchip
Jaroslav Hajek <highegg@gmail.com>
parents:
9070
diff
changeset
|
159 if (isvector (y)) |
5838 | 160 y = y(:); |
5837 | 161 endif |
13141
e81ddf9cacd5
maint: untabify and remove trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
12608
diff
changeset
|
162 |
5838 | 163 szy = size (y); |
9754
4219e5cf773d
improve interp1 and pchip
Jaroslav Hajek <highegg@gmail.com>
parents:
9070
diff
changeset
|
164 y = y(:,:); |
4219e5cf773d
improve interp1 and pchip
Jaroslav Hajek <highegg@gmail.com>
parents:
9070
diff
changeset
|
165 [ny, nc] = size (y); |
5837 | 166 xi = xi(:); |
167 | |
168 ## determine sizes | |
169 if (nx < 2 || ny < 2) | |
5838 | 170 error ("interp1: table too short"); |
5837 | 171 endif |
172 | |
9754
4219e5cf773d
improve interp1 and pchip
Jaroslav Hajek <highegg@gmail.com>
parents:
9070
diff
changeset
|
173 ## check whether x is sorted; sort if not. |
9929
45c08d7c2c79
allow discontinuous interpolant in interp1
Jaroslav Hajek <highegg@gmail.com>
parents:
9769
diff
changeset
|
174 if (! issorted (x, "either")) |
9754
4219e5cf773d
improve interp1 and pchip
Jaroslav Hajek <highegg@gmail.com>
parents:
9070
diff
changeset
|
175 [x, p] = sort (x); |
4219e5cf773d
improve interp1 and pchip
Jaroslav Hajek <highegg@gmail.com>
parents:
9070
diff
changeset
|
176 y = y(p,:); |
5837 | 177 endif |
5838 | 178 |
15218
94d512d712e3
Modified interp1.m file to check whether X has distinct values or not.
Ben Abbott <bpabbott@mac.com>
parents:
15193
diff
changeset
|
179 if (isempty (rightcontinuous)) |
94d512d712e3
Modified interp1.m file to check whether X has distinct values or not.
Ben Abbott <bpabbott@mac.com>
parents:
15193
diff
changeset
|
180 ## 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
|
181 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
|
182 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
|
183 else |
94d512d712e3
Modified interp1.m file to check whether X has distinct values or not.
Ben Abbott <bpabbott@mac.com>
parents:
15193
diff
changeset
|
184 rightcontinuous = true; |
94d512d712e3
Modified interp1.m file to check whether X has distinct values or not.
Ben Abbott <bpabbott@mac.com>
parents:
15193
diff
changeset
|
185 end |
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
|
186 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
|
187 |
15218
94d512d712e3
Modified interp1.m file to check whether X has distinct values or not.
Ben Abbott <bpabbott@mac.com>
parents:
15193
diff
changeset
|
188 if ((rightcontinuous && (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
|
189 || (~ rightcontinuous && (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
|
190 ## 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
|
191 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
|
192 y = flipud (y); |
94d512d712e3
Modified interp1.m file to check whether X has distinct values or not.
Ben Abbott <bpabbott@mac.com>
parents:
15193
diff
changeset
|
193 end |
94d512d712e3
Modified interp1.m file to check whether X has distinct values or not.
Ben Abbott <bpabbott@mac.com>
parents:
15193
diff
changeset
|
194 |
9754
4219e5cf773d
improve interp1 and pchip
Jaroslav Hajek <highegg@gmail.com>
parents:
9070
diff
changeset
|
195 starmethod = method(1) == "*"; |
4219e5cf773d
improve interp1 and pchip
Jaroslav Hajek <highegg@gmail.com>
parents:
9070
diff
changeset
|
196 |
4219e5cf773d
improve interp1 and pchip
Jaroslav Hajek <highegg@gmail.com>
parents:
9070
diff
changeset
|
197 if (starmethod) |
4219e5cf773d
improve interp1 and pchip
Jaroslav Hajek <highegg@gmail.com>
parents:
9070
diff
changeset
|
198 dx = x(2) - x(1); |
4219e5cf773d
improve interp1 and pchip
Jaroslav Hajek <highegg@gmail.com>
parents:
9070
diff
changeset
|
199 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
|
200 jumps = x(1:end-1) == x(2:end); |
9929
45c08d7c2c79
allow discontinuous interpolant in interp1
Jaroslav Hajek <highegg@gmail.com>
parents:
9769
diff
changeset
|
201 have_jumps = any (jumps); |
45c08d7c2c79
allow discontinuous interpolant in interp1
Jaroslav Hajek <highegg@gmail.com>
parents:
9769
diff
changeset
|
202 if (have_jumps) |
45c08d7c2c79
allow discontinuous interpolant in interp1
Jaroslav Hajek <highegg@gmail.com>
parents:
9769
diff
changeset
|
203 if (any (strcmp (method, {"nearest", "linear"}))) |
45c08d7c2c79
allow discontinuous interpolant in interp1
Jaroslav Hajek <highegg@gmail.com>
parents:
9769
diff
changeset
|
204 if (any (jumps(1:nx-2) & jumps(2:nx-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
|
205 error ("interp1: extra points in discontinuities"); |
9929
45c08d7c2c79
allow discontinuous interpolant in interp1
Jaroslav Hajek <highegg@gmail.com>
parents:
9769
diff
changeset
|
206 endif |
45c08d7c2c79
allow discontinuous interpolant in interp1
Jaroslav Hajek <highegg@gmail.com>
parents:
9769
diff
changeset
|
207 else |
15468
6437fa7263dd
use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents:
15218
diff
changeset
|
208 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
|
209 endif |
5837 | 210 endif |
211 endif | |
212 | |
9754
4219e5cf773d
improve interp1 and pchip
Jaroslav Hajek <highegg@gmail.com>
parents:
9070
diff
changeset
|
213 ## Proceed with interpolating by all methods. |
4219e5cf773d
improve interp1 and pchip
Jaroslav Hajek <highegg@gmail.com>
parents:
9070
diff
changeset
|
214 switch (method) |
4219e5cf773d
improve interp1 and pchip
Jaroslav Hajek <highegg@gmail.com>
parents:
9070
diff
changeset
|
215 case "nearest" |
12608
59e2460acae1
make piecewise polynomial (pp) functions more compatible
Kai Habel <kai.habel@gmx.de>
parents:
12459
diff
changeset
|
216 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
|
217 pp.orient = "first"; |
13141
e81ddf9cacd5
maint: untabify and remove trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
12608
diff
changeset
|
218 |
12608
59e2460acae1
make piecewise polynomial (pp) functions more compatible
Kai Habel <kai.habel@gmx.de>
parents:
12459
diff
changeset
|
219 if (ispp) |
59e2460acae1
make piecewise polynomial (pp) functions more compatible
Kai Habel <kai.habel@gmx.de>
parents:
12459
diff
changeset
|
220 yi = pp; |
5837 | 221 else |
12608
59e2460acae1
make piecewise polynomial (pp) functions more compatible
Kai Habel <kai.habel@gmx.de>
parents:
12459
diff
changeset
|
222 yi = ppval (pp, reshape (xi, szx)); |
5837 | 223 endif |
9754
4219e5cf773d
improve interp1 and pchip
Jaroslav Hajek <highegg@gmail.com>
parents:
9070
diff
changeset
|
224 case "*nearest" |
12608
59e2460acae1
make piecewise polynomial (pp) functions more compatible
Kai Habel <kai.habel@gmx.de>
parents:
12459
diff
changeset
|
225 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
|
226 pp.orient = "first"; |
59e2460acae1
make piecewise polynomial (pp) functions more compatible
Kai Habel <kai.habel@gmx.de>
parents:
12459
diff
changeset
|
227 if (ispp) |
59e2460acae1
make piecewise polynomial (pp) functions more compatible
Kai Habel <kai.habel@gmx.de>
parents:
12459
diff
changeset
|
228 yi = pp; |
5837 | 229 else |
14868
5d3a684236b0
maint: Use Octave coding conventions for cuddling parentheses in scripts directory
Rik <octave@nomad.inbox5.com>
parents:
14492
diff
changeset
|
230 yi = ppval (pp, reshape (xi, szx)); |
5837 | 231 endif |
9754
4219e5cf773d
improve interp1 and pchip
Jaroslav Hajek <highegg@gmail.com>
parents:
9070
diff
changeset
|
232 case "linear" |
4219e5cf773d
improve interp1 and pchip
Jaroslav Hajek <highegg@gmail.com>
parents:
9070
diff
changeset
|
233 dy = diff (y); |
13141
e81ddf9cacd5
maint: untabify and remove trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
12608
diff
changeset
|
234 dx = diff (x); |
12608
59e2460acae1
make piecewise polynomial (pp) functions more compatible
Kai Habel <kai.habel@gmx.de>
parents:
12459
diff
changeset
|
235 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
|
236 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
|
237 xx = x; |
59e2460acae1
make piecewise polynomial (pp) functions more compatible
Kai Habel <kai.habel@gmx.de>
parents:
12459
diff
changeset
|
238 |
59e2460acae1
make piecewise polynomial (pp) functions more compatible
Kai Habel <kai.habel@gmx.de>
parents:
12459
diff
changeset
|
239 if (have_jumps) |
59e2460acae1
make piecewise polynomial (pp) functions more compatible
Kai Habel <kai.habel@gmx.de>
parents:
12459
diff
changeset
|
240 ## Omit zero-size intervals. |
59e2460acae1
make piecewise polynomial (pp) functions more compatible
Kai Habel <kai.habel@gmx.de>
parents:
12459
diff
changeset
|
241 coefs(jumps, :) = []; |
59e2460acae1
make piecewise polynomial (pp) functions more compatible
Kai Habel <kai.habel@gmx.de>
parents:
12459
diff
changeset
|
242 xx(jumps) = []; |
59e2460acae1
make piecewise polynomial (pp) functions more compatible
Kai Habel <kai.habel@gmx.de>
parents:
12459
diff
changeset
|
243 endif |
59e2460acae1
make piecewise polynomial (pp) functions more compatible
Kai Habel <kai.habel@gmx.de>
parents:
12459
diff
changeset
|
244 |
59e2460acae1
make piecewise polynomial (pp) functions more compatible
Kai Habel <kai.habel@gmx.de>
parents:
12459
diff
changeset
|
245 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
|
246 pp.orient = "first"; |
59e2460acae1
make piecewise polynomial (pp) functions more compatible
Kai Habel <kai.habel@gmx.de>
parents:
12459
diff
changeset
|
247 |
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 yi = pp; |
5837 | 250 else |
14868
5d3a684236b0
maint: Use Octave coding conventions for cuddling parentheses in scripts directory
Rik <octave@nomad.inbox5.com>
parents:
14492
diff
changeset
|
251 yi = ppval (pp, reshape (xi, szx)); |
5837 | 252 endif |
12608
59e2460acae1
make piecewise polynomial (pp) functions more compatible
Kai Habel <kai.habel@gmx.de>
parents:
12459
diff
changeset
|
253 |
9754
4219e5cf773d
improve interp1 and pchip
Jaroslav Hajek <highegg@gmail.com>
parents:
9070
diff
changeset
|
254 case "*linear" |
4219e5cf773d
improve interp1 and pchip
Jaroslav Hajek <highegg@gmail.com>
parents:
9070
diff
changeset
|
255 dy = diff (y); |
12608
59e2460acae1
make piecewise polynomial (pp) functions more compatible
Kai Habel <kai.habel@gmx.de>
parents:
12459
diff
changeset
|
256 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
|
257 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
|
258 pp.orient = "first"; |
59e2460acae1
make piecewise polynomial (pp) functions more compatible
Kai Habel <kai.habel@gmx.de>
parents:
12459
diff
changeset
|
259 |
59e2460acae1
make piecewise polynomial (pp) functions more compatible
Kai Habel <kai.habel@gmx.de>
parents:
12459
diff
changeset
|
260 if (ispp) |
59e2460acae1
make piecewise polynomial (pp) functions more compatible
Kai Habel <kai.habel@gmx.de>
parents:
12459
diff
changeset
|
261 yi = pp; |
5837 | 262 else |
14868
5d3a684236b0
maint: Use Octave coding conventions for cuddling parentheses in scripts directory
Rik <octave@nomad.inbox5.com>
parents:
14492
diff
changeset
|
263 yi = ppval (pp, reshape (xi, szx)); |
12608
59e2460acae1
make piecewise polynomial (pp) functions more compatible
Kai Habel <kai.habel@gmx.de>
parents:
12459
diff
changeset
|
264 endif |
5837 | 265 |
12608
59e2460acae1
make piecewise polynomial (pp) functions more compatible
Kai Habel <kai.habel@gmx.de>
parents:
12459
diff
changeset
|
266 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
|
267 if (nx == 2 || starmethod) |
6374 | 268 x = linspace (x(1), x(nx), ny); |
5837 | 269 endif |
13141
e81ddf9cacd5
maint: untabify and remove trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
12608
diff
changeset
|
270 |
12608
59e2460acae1
make piecewise polynomial (pp) functions more compatible
Kai Habel <kai.habel@gmx.de>
parents:
12459
diff
changeset
|
271 if (ispp) |
59e2460acae1
make piecewise polynomial (pp) functions more compatible
Kai Habel <kai.habel@gmx.de>
parents:
12459
diff
changeset
|
272 y = shiftdim (reshape (y, szy), 1); |
59e2460acae1
make piecewise polynomial (pp) functions more compatible
Kai Habel <kai.habel@gmx.de>
parents:
12459
diff
changeset
|
273 yi = pchip (x, y); |
14492
7ce925166af6
Fix inconsistent orientation of output matrix for interp1.
Olaf Till <i7tiol@t-online.de>
parents:
14363
diff
changeset
|
274 yi.orient = "first"; |
9754
4219e5cf773d
improve interp1 and pchip
Jaroslav Hajek <highegg@gmail.com>
parents:
9070
diff
changeset
|
275 else |
12608
59e2460acae1
make piecewise polynomial (pp) functions more compatible
Kai Habel <kai.habel@gmx.de>
parents:
12459
diff
changeset
|
276 y = shiftdim (y, 1); |
59e2460acae1
make piecewise polynomial (pp) functions more compatible
Kai Habel <kai.habel@gmx.de>
parents:
12459
diff
changeset
|
277 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
|
278 if (! isvector (y)) |
7ce925166af6
Fix inconsistent orientation of output matrix for interp1.
Olaf Till <i7tiol@t-online.de>
parents:
14363
diff
changeset
|
279 yi = shiftdim (yi, 1); |
7ce925166af6
Fix inconsistent orientation of output matrix for interp1.
Olaf Till <i7tiol@t-online.de>
parents:
14363
diff
changeset
|
280 endif |
9754
4219e5cf773d
improve interp1 and pchip
Jaroslav Hajek <highegg@gmail.com>
parents:
9070
diff
changeset
|
281 endif |
4219e5cf773d
improve interp1 and pchip
Jaroslav Hajek <highegg@gmail.com>
parents:
9070
diff
changeset
|
282 case {"spline", "*spline"} |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11536
diff
changeset
|
283 if (nx == 2 || starmethod) |
14868
5d3a684236b0
maint: Use Octave coding conventions for cuddling parentheses in scripts directory
Rik <octave@nomad.inbox5.com>
parents:
14492
diff
changeset
|
284 x = linspace (x(1), x(nx), ny); |
5837 | 285 endif |
13141
e81ddf9cacd5
maint: untabify and remove trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
12608
diff
changeset
|
286 |
12608
59e2460acae1
make piecewise polynomial (pp) functions more compatible
Kai Habel <kai.habel@gmx.de>
parents:
12459
diff
changeset
|
287 if (ispp) |
59e2460acae1
make piecewise polynomial (pp) functions more compatible
Kai Habel <kai.habel@gmx.de>
parents:
12459
diff
changeset
|
288 y = shiftdim (reshape (y, szy), 1); |
59e2460acae1
make piecewise polynomial (pp) functions more compatible
Kai Habel <kai.habel@gmx.de>
parents:
12459
diff
changeset
|
289 yi = spline (x, y); |
14492
7ce925166af6
Fix inconsistent orientation of output matrix for interp1.
Olaf Till <i7tiol@t-online.de>
parents:
14363
diff
changeset
|
290 yi.orient = "first"; |
5837 | 291 else |
12608
59e2460acae1
make piecewise polynomial (pp) functions more compatible
Kai Habel <kai.habel@gmx.de>
parents:
12459
diff
changeset
|
292 y = shiftdim (y, 1); |
59e2460acae1
make piecewise polynomial (pp) functions more compatible
Kai Habel <kai.habel@gmx.de>
parents:
12459
diff
changeset
|
293 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
|
294 if (! isvector (y)) |
7ce925166af6
Fix inconsistent orientation of output matrix for interp1.
Olaf Till <i7tiol@t-online.de>
parents:
14363
diff
changeset
|
295 yi = shiftdim (yi, 1); |
7ce925166af6
Fix inconsistent orientation of output matrix for interp1.
Olaf Till <i7tiol@t-online.de>
parents:
14363
diff
changeset
|
296 endif |
5837 | 297 endif |
9754
4219e5cf773d
improve interp1 and pchip
Jaroslav Hajek <highegg@gmail.com>
parents:
9070
diff
changeset
|
298 otherwise |
5838 | 299 error ("interp1: invalid method '%s'", method); |
9754
4219e5cf773d
improve interp1 and pchip
Jaroslav Hajek <highegg@gmail.com>
parents:
9070
diff
changeset
|
300 endswitch |
5837 | 301 |
12608
59e2460acae1
make piecewise polynomial (pp) functions more compatible
Kai Habel <kai.habel@gmx.de>
parents:
12459
diff
changeset
|
302 if (! ispp) |
9754
4219e5cf773d
improve interp1 and pchip
Jaroslav Hajek <highegg@gmail.com>
parents:
9070
diff
changeset
|
303 if (! ischar (extrap)) |
4219e5cf773d
improve interp1 and pchip
Jaroslav Hajek <highegg@gmail.com>
parents:
9070
diff
changeset
|
304 ## 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
|
305 ## unless extrap == "extrap". |
4219e5cf773d
improve interp1 and pchip
Jaroslav Hajek <highegg@gmail.com>
parents:
9070
diff
changeset
|
306 minx = min (x(1), x(nx)); |
4219e5cf773d
improve interp1 and pchip
Jaroslav Hajek <highegg@gmail.com>
parents:
9070
diff
changeset
|
307 maxx = max (x(1), x(nx)); |
4219e5cf773d
improve interp1 and pchip
Jaroslav Hajek <highegg@gmail.com>
parents:
9070
diff
changeset
|
308 |
4219e5cf773d
improve interp1 and pchip
Jaroslav Hajek <highegg@gmail.com>
parents:
9070
diff
changeset
|
309 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
|
310 if (size_equal (outliers, yi)) |
59e2460acae1
make piecewise polynomial (pp) functions more compatible
Kai Habel <kai.habel@gmx.de>
parents:
12459
diff
changeset
|
311 yi(outliers) = extrap; |
59e2460acae1
make piecewise polynomial (pp) functions more compatible
Kai Habel <kai.habel@gmx.de>
parents:
12459
diff
changeset
|
312 yi = reshape (yi, szx); |
59e2460acae1
make piecewise polynomial (pp) functions more compatible
Kai Habel <kai.habel@gmx.de>
parents:
12459
diff
changeset
|
313 elseif (!isvector (yi)) |
14492
7ce925166af6
Fix inconsistent orientation of output matrix for interp1.
Olaf Till <i7tiol@t-online.de>
parents:
14363
diff
changeset
|
314 yi(outliers, :) = extrap; |
12608
59e2460acae1
make piecewise polynomial (pp) functions more compatible
Kai Habel <kai.habel@gmx.de>
parents:
12459
diff
changeset
|
315 else |
59e2460acae1
make piecewise polynomial (pp) functions more compatible
Kai Habel <kai.habel@gmx.de>
parents:
12459
diff
changeset
|
316 yi(outliers.') = extrap; |
59e2460acae1
make piecewise polynomial (pp) functions more compatible
Kai Habel <kai.habel@gmx.de>
parents:
12459
diff
changeset
|
317 endif |
9754
4219e5cf773d
improve interp1 and pchip
Jaroslav Hajek <highegg@gmail.com>
parents:
9070
diff
changeset
|
318 endif |
5837 | 319 endif |
320 | |
321 endfunction | |
322 | |
14237
11949c9795a0
Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
323 |
5837 | 324 %!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
|
325 %! clf; |
14363
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14359
diff
changeset
|
326 %! 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
|
327 %! 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
|
328 %! 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
|
329 %! 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
|
330 %! 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
|
331 %! 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
|
332 %! 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
|
333 %! legend ("original", "nearest", "linear", "pchip", "spline"); |
5837 | 334 %! %-------------------------------------------------------- |
335 %! % confirm that interpolated function matches the original | |
336 | |
337 %!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
|
338 %! clf; |
14363
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14359
diff
changeset
|
339 %! 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
|
340 %! 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
|
341 %! 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
|
342 %! 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
|
343 %! 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
|
344 %! 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
|
345 %! 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
|
346 %! legend ("*original", "*nearest", "*linear", "*cubic", "*spline"); |
5837 | 347 %! %-------------------------------------------------------- |
348 %! % confirm that interpolated function matches the original | |
349 | |
6721 | 350 %!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
|
351 %! clf; |
6721 | 352 %! t = 0 : 0.3 : pi; dt = t(2)-t(1); |
353 %! n = length (t); k = 100; dti = dt*n/k; | |
354 %! ti = t(1) + [0 : k-1]*dti; | |
355 %! 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
|
356 %! 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
|
357 %! 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
|
358 %! 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
|
359 %! 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
|
360 %! 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
|
361 %! title ("Second derivative of interpolated 'sin (4*t + 0.3) .* cos (3*t - 0.1)'"); |
6721 | 362 |
9929
45c08d7c2c79
allow discontinuous interpolant in interp1
Jaroslav Hajek <highegg@gmail.com>
parents:
9769
diff
changeset
|
363 %!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
|
364 %! clf; |
14363
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14359
diff
changeset
|
365 %! 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
|
366 %! 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
|
367 %! 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
|
368 %! 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
|
369 %! 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
|
370 %! legend ("original", "nearest", "linear"); |
9929
45c08d7c2c79
allow discontinuous interpolant in interp1
Jaroslav Hajek <highegg@gmail.com>
parents:
9769
diff
changeset
|
371 %! %-------------------------------------------------------- |
45c08d7c2c79
allow discontinuous interpolant in interp1
Jaroslav Hajek <highegg@gmail.com>
parents:
9769
diff
changeset
|
372 %! % confirm that interpolated function matches the original |
45c08d7c2c79
allow discontinuous interpolant in interp1
Jaroslav Hajek <highegg@gmail.com>
parents:
9769
diff
changeset
|
373 |
15218
94d512d712e3
Modified interp1.m file to check whether X has distinct values or not.
Ben Abbott <bpabbott@mac.com>
parents:
15193
diff
changeset
|
374 %!demo |
94d512d712e3
Modified interp1.m file to check whether X has distinct values or not.
Ben Abbott <bpabbott@mac.com>
parents:
15193
diff
changeset
|
375 %! clf; |
94d512d712e3
Modified interp1.m file to check whether X has distinct values or not.
Ben Abbott <bpabbott@mac.com>
parents:
15193
diff
changeset
|
376 %! 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
|
377 %! 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
|
378 %! 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
|
379 %! 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
|
380 %! 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
|
381 %! 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
|
382 %! 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
|
383 %! g = plot (x, interp1 (x2, y2, x), 'r', x2, y2, '*r'); |
94d512d712e3
Modified interp1.m file to check whether X has distinct values or not.
Ben Abbott <bpabbott@mac.com>
parents:
15193
diff
changeset
|
384 %! xlim ([1 3]) |
94d512d712e3
Modified interp1.m file to check whether X has distinct values or not.
Ben Abbott <bpabbott@mac.com>
parents:
15193
diff
changeset
|
385 %! legend ([h(1), g(1)], {'left-continous', '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
|
386 %! 'location', 'east') |
94d512d712e3
Modified interp1.m file to check whether X has distinct values or not.
Ben Abbott <bpabbott@mac.com>
parents:
15193
diff
changeset
|
387 %! 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
|
388 %! %-------------------------------------------------------- |
94d512d712e3
Modified interp1.m file to check whether X has distinct values or not.
Ben Abbott <bpabbott@mac.com>
parents:
15193
diff
changeset
|
389 %! % red curve is left-continuos and blue is right-continuous at x = 2 |
94d512d712e3
Modified interp1.m file to check whether X has distinct values or not.
Ben Abbott <bpabbott@mac.com>
parents:
15193
diff
changeset
|
390 |
12608
59e2460acae1
make piecewise polynomial (pp) functions more compatible
Kai Habel <kai.habel@gmx.de>
parents:
12459
diff
changeset
|
391 ##FIXME: add test for n-d arguments here |
9929
45c08d7c2c79
allow discontinuous interpolant in interp1
Jaroslav Hajek <highegg@gmail.com>
parents:
9769
diff
changeset
|
392 |
6374 | 393 ## For each type of interpolated test, confirm that the interpolated |
394 ## 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
|
395 ## from the knots are requested, but only "nearest" and "linear" |
6374 | 396 ## confirm they are the correct values. |
397 | |
5837 | 398 %!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
|
399 %! 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
|
400 %! yp = sin (2*pi*xp/5); |
6374 | 401 %! xi = [-1, 0, 2.2, 4, 6.6, 10, 11]; |
402 | |
403 ## The following BLOCK/ENDBLOCK section is repeated for each style | |
404 ## nearest, linear, cubic, spline, pchip | |
405 ## The test for ppval of cubic has looser tolerance, but otherwise | |
406 ## the tests are identical. | |
407 ## 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
|
408 ## be sure to add them to both sections of each block. One test, |
6374 | 409 ## style vs. *style, occurs only in the first section. |
410 ## 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
|
411 |
5837 | 412 %!test style = "nearest"; |
6374 | 413 ## BLOCK |
14363
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14359
diff
changeset
|
414 %!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
|
415 %!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
|
416 %!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
|
417 %!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
|
418 %!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
|
419 %!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
|
420 %!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
|
421 %!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
|
422 %! [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
|
423 %!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
|
424 %! 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
|
425 %!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
|
426 %! 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
|
427 %!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
|
428 %!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
|
429 %! 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
|
430 %!test style = ["*",style]; |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14359
diff
changeset
|
431 %!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
|
432 %!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
|
433 %!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
|
434 %!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
|
435 %!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
|
436 %!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
|
437 %!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
|
438 %!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
|
439 %! [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
|
440 %!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
|
441 %! 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
|
442 %!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
|
443 %! 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
|
444 %!error interp1 (1,1,1, style) |
6374 | 445 ## 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
|
446 |
14363
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14359
diff
changeset
|
447 %!test style = "linear"; |
6374 | 448 ## BLOCK |
14363
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, [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
|
450 %!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
|
451 %!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
|
452 %!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
|
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 (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
|
455 %!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
|
456 %!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
|
457 %! [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
|
458 %!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
|
459 %! 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
|
460 %!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
|
461 %! 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
|
462 %!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
|
463 %!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
|
464 %! 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
|
465 %!test style = ['*',style]; |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14359
diff
changeset
|
466 %!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
|
467 %!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
|
468 %!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
|
469 %!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
|
470 %!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
|
471 %!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
|
472 %!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
|
473 %!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
|
474 %! [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
|
475 %!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
|
476 %! 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
|
477 %!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
|
478 %! 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
|
479 %!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
|
480 %!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
|
481 %!error interp1 (1,1,1, style) |
6374 | 482 ## 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
|
483 |
14363
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14359
diff
changeset
|
484 %!test style = "cubic"; |
6374 | 485 ## BLOCK |
14363
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, [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
|
487 %!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
|
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 (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
|
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 (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,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
|
495 %!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
|
496 %! 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
|
497 %!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
|
498 %! 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
|
499 %!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
|
500 %!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
|
501 %! 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
|
502 %!test style = ["*",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, [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
|
504 %!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
|
505 %!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
|
506 %!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
|
507 %!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
|
508 %!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
|
509 %!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
|
510 %!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
|
511 %! [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
|
512 %!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
|
513 %! 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
|
514 %!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
|
515 %! 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
|
516 %!error interp1 (1,1,1, style) |
6374 | 517 ## 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
|
518 |
14363
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14359
diff
changeset
|
519 %!test style = "pchip"; |
6374 | 520 ## BLOCK |
14363
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, [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
|
522 %!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
|
523 %!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
|
524 %!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
|
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 (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
|
527 %!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
|
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,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
|
530 %!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
|
531 %! 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
|
532 %!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
|
533 %! 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
|
534 %!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
|
535 %!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
|
536 %! 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
|
537 %!test style = ["*",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, [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
|
539 %!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
|
540 %!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
|
541 %!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
|
542 %!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
|
543 %!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
|
544 %!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
|
545 %!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
|
546 %! [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
|
547 %!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
|
548 %! 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
|
549 %!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
|
550 %! 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
|
551 %!error interp1 (1,1,1, style) |
6374 | 552 ## 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
|
553 |
14363
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14359
diff
changeset
|
554 %!test style = "spline"; |
6374 | 555 ## BLOCK |
14363
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, [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
|
557 %!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
|
558 %!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
|
559 %!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
|
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 (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
|
562 %!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
|
563 %!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
|
564 %! [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
|
565 %!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
|
566 %! 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
|
567 %!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
|
568 %! 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
|
569 %!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
|
570 %!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
|
571 %! 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
|
572 %!test style = ["*",style]; |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14359
diff
changeset
|
573 %!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
|
574 %!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
|
575 %!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
|
576 %!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
|
577 %!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
|
578 %!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
|
579 %!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
|
580 %!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
|
581 %! [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
|
582 %!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
|
583 %! 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
|
584 %!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
|
585 %! 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
|
586 %!error interp1 (1,1,1, style) |
6374 | 587 ## ENDBLOCK |
588 ## ENDBLOCKTEST | |
5837 | 589 |
590 %!# test linear extrapolation | |
14363
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14359
diff
changeset
|
591 %!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
|
592 %!assert (interp1 (xp, yp, [-1, max(xp)+1],"linear",5), [5, 5]) |
5837 | 593 |
14363
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14359
diff
changeset
|
594 %!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
|
595 %!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
|
596 %!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
|
597 %!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
|
598 %!assert (interp1 (1:3,1:3,1.4,"spline"), 1.4) |
5837 | 599 |
14363
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14359
diff
changeset
|
600 %!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
|
601 %!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
|
602 %!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
|
603 %!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
|
604 %!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
|
605 |
14363
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14359
diff
changeset
|
606 %!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
|
607 |
45c08d7c2c79
allow discontinuous interpolant in interp1
Jaroslav Hajek <highegg@gmail.com>
parents:
9769
diff
changeset
|
608 %!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
|
609 %!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
|
610 %!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
|
611 |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14359
diff
changeset
|
612 %!error interp1 () |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14359
diff
changeset
|
613 %!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
|
614 %!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
|
615 %!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
|
616 %!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
|
617 |