Mercurial > octave
annotate scripts/general/interp1.m @ 29359:7854d5752dd2
maint: merge stable to default.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Wed, 10 Feb 2021 10:10:40 -0500 |
parents | 90fea9cc9caa 0a5b15007766 |
children | 8c7685d70cf3 |
rev | line source |
---|---|
27923
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
1 ######################################################################## |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
2 ## |
29358
0a5b15007766
update Octave Project Developers copyright for the new year
John W. Eaton <jwe@octave.org>
parents:
27984
diff
changeset
|
3 ## Copyright (C) 2000-2021 The Octave Project Developers |
27918
b442ec6dda5c
use centralized file for copyright info for individual contributors
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
4 ## |
27923
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
5 ## See the file COPYRIGHT.md in the top-level directory of this |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
6 ## distribution or <https://octave.org/copyright/>. |
5837 | 7 ## |
8 ## This file is part of Octave. | |
9 ## | |
24534
194eb4bd202b
maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents:
23513
diff
changeset
|
10 ## Octave is free software: you can redistribute it and/or modify it |
5837 | 11 ## under the terms of the GNU General Public License as published by |
24534
194eb4bd202b
maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents:
23513
diff
changeset
|
12 ## the Free Software Foundation, either version 3 of the License, or |
22755
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
13 ## (at your option) any later version. |
5837 | 14 ## |
15 ## Octave is distributed in the hope that it will be useful, but | |
16 ## WITHOUT ANY WARRANTY; without even the implied warranty of | |
22755
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
17 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
18 ## GNU General Public License for more details. |
5837 | 19 ## |
20 ## You should have received a copy of the GNU General Public License | |
7016 | 21 ## along with Octave; see the file COPYING. If not, see |
24534
194eb4bd202b
maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents:
23513
diff
changeset
|
22 ## <https://www.gnu.org/licenses/>. |
27923
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
23 ## |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
24 ######################################################################## |
5837 | 25 |
26 ## -*- texinfo -*- | |
20852
516bb87ea72e
2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents:
20835
diff
changeset
|
27 ## @deftypefn {} {@var{yi} =} interp1 (@var{x}, @var{y}, @var{xi}) |
516bb87ea72e
2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents:
20835
diff
changeset
|
28 ## @deftypefnx {} {@var{yi} =} interp1 (@var{y}, @var{xi}) |
516bb87ea72e
2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents:
20835
diff
changeset
|
29 ## @deftypefnx {} {@var{yi} =} interp1 (@dots{}, @var{method}) |
516bb87ea72e
2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents:
20835
diff
changeset
|
30 ## @deftypefnx {} {@var{yi} =} interp1 (@dots{}, @var{extrap}) |
516bb87ea72e
2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents:
20835
diff
changeset
|
31 ## @deftypefnx {} {@var{yi} =} interp1 (@dots{}, "left") |
516bb87ea72e
2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents:
20835
diff
changeset
|
32 ## @deftypefnx {} {@var{yi} =} interp1 (@dots{}, "right") |
516bb87ea72e
2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents:
20835
diff
changeset
|
33 ## @deftypefnx {} {@var{pp} =} interp1 (@dots{}, "pp") |
5837 | 34 ## |
18417 | 35 ## One-dimensional interpolation. |
36 ## | |
37 ## Interpolate input data to determine the value of @var{yi} at the points | |
18606
0ede4dbb37f1
Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents:
18418
diff
changeset
|
38 ## @var{xi}. If not specified, @var{x} is taken to be the indices of @var{y} |
0ede4dbb37f1
Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents:
18418
diff
changeset
|
39 ## (@code{1:length (@var{y})}). If @var{y} is a matrix or an N-dimensional |
0ede4dbb37f1
Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents:
18418
diff
changeset
|
40 ## array, the interpolation is performed on each column of @var{y}. |
5837 | 41 ## |
18606
0ede4dbb37f1
Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents:
18418
diff
changeset
|
42 ## The interpolation @var{method} is one of: |
5837 | 43 ## |
44 ## @table @asis | |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17174
diff
changeset
|
45 ## @item @qcode{"nearest"} |
18606
0ede4dbb37f1
Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents:
18418
diff
changeset
|
46 ## Return the nearest neighbor. |
10821
693e22af08ae
Grammarcheck documentation of m-files
Rik <octave@nomad.inbox5.com>
parents:
10820
diff
changeset
|
47 ## |
19294
b80b396e7d54
interp1.m: Add new methods "previous" and "next" (bug #43377).
Nir Krakauer <nkrakauer@ccny.cuny.edu>
parents:
18642
diff
changeset
|
48 ## @item @qcode{"previous"} |
b80b396e7d54
interp1.m: Add new methods "previous" and "next" (bug #43377).
Nir Krakauer <nkrakauer@ccny.cuny.edu>
parents:
18642
diff
changeset
|
49 ## Return the previous neighbor. |
10821
693e22af08ae
Grammarcheck documentation of m-files
Rik <octave@nomad.inbox5.com>
parents:
10820
diff
changeset
|
50 ## |
19294
b80b396e7d54
interp1.m: Add new methods "previous" and "next" (bug #43377).
Nir Krakauer <nkrakauer@ccny.cuny.edu>
parents:
18642
diff
changeset
|
51 ## @item @qcode{"next"} |
b80b396e7d54
interp1.m: Add new methods "previous" and "next" (bug #43377).
Nir Krakauer <nkrakauer@ccny.cuny.edu>
parents:
18642
diff
changeset
|
52 ## Return the next neighbor. |
b80b396e7d54
interp1.m: Add new methods "previous" and "next" (bug #43377).
Nir Krakauer <nkrakauer@ccny.cuny.edu>
parents:
18642
diff
changeset
|
53 ## |
18606
0ede4dbb37f1
Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents:
18418
diff
changeset
|
54 ## @item @qcode{"linear"} (default) |
0ede4dbb37f1
Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents:
18418
diff
changeset
|
55 ## Linear interpolation from nearest neighbors. |
10821
693e22af08ae
Grammarcheck documentation of m-files
Rik <octave@nomad.inbox5.com>
parents:
10820
diff
changeset
|
56 ## |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17174
diff
changeset
|
57 ## @item @qcode{"pchip"} |
18606
0ede4dbb37f1
Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents:
18418
diff
changeset
|
58 ## Piecewise cubic Hermite interpolating polynomial---shape-preserving |
0ede4dbb37f1
Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents:
18418
diff
changeset
|
59 ## interpolation with smooth first derivative. |
10821
693e22af08ae
Grammarcheck documentation of m-files
Rik <octave@nomad.inbox5.com>
parents:
10820
diff
changeset
|
60 ## |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17174
diff
changeset
|
61 ## @item @qcode{"cubic"} |
18606
0ede4dbb37f1
Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents:
18418
diff
changeset
|
62 ## Cubic interpolation (same as @qcode{"pchip"}). |
10821
693e22af08ae
Grammarcheck documentation of m-files
Rik <octave@nomad.inbox5.com>
parents:
10820
diff
changeset
|
63 ## |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17174
diff
changeset
|
64 ## @item @qcode{"spline"} |
12175
2090995ca588
Correct en-dash,em-dash instances in docstrings.
Rik <octave@nomad.inbox5.com>
parents:
11587
diff
changeset
|
65 ## Cubic spline interpolation---smooth first and second derivatives |
18606
0ede4dbb37f1
Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents:
18418
diff
changeset
|
66 ## throughout the curve. |
5837 | 67 ## @end table |
68 ## | |
18417 | 69 ## 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
|
70 ## 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
|
71 ## 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
|
72 ## and is never slower. The default method is @qcode{"linear"}. |
5837 | 73 ## |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17174
diff
changeset
|
74 ## If @var{extrap} is the string @qcode{"extrap"}, then extrapolate values |
18417 | 75 ## beyond the endpoints using the current @var{method}. If @var{extrap} is a |
76 ## number, then replace values beyond the endpoints with that number. When | |
18606
0ede4dbb37f1
Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents:
18418
diff
changeset
|
77 ## unspecified, @var{extrap} defaults to @code{NA}. |
5837 | 78 ## |
18417 | 79 ## If the string argument @qcode{"pp"} is specified, then @var{xi} should not |
19593
446c46af4b42
strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents:
19383
diff
changeset
|
80 ## be supplied and @code{interp1} returns a piecewise polynomial object. This |
18417 | 81 ## object can later be used with @code{ppval} to evaluate the interpolation. |
5837 | 82 ## There is an equivalence, such that @code{ppval (interp1 (@var{x}, |
21546
f7f97d7e9294
doc: Wrap m-file docstrings to 79 characters + newline (80 total).
Rik <rik@octave.org>
parents:
21317
diff
changeset
|
83 ## @var{y}, @var{method}, @qcode{"pp"}), @var{xi}) == interp1 (@var{x}, |
f7f97d7e9294
doc: Wrap m-file docstrings to 79 characters + newline (80 total).
Rik <rik@octave.org>
parents:
21317
diff
changeset
|
84 ## @var{y}, @var{xi}, @var{method}, @qcode{"extrap"})}. |
5837 | 85 ## |
10711
fbd7843974fa
Periodic grammar check of documentation files to ensure common format.
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
86 ## 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
|
87 ## 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
|
88 ## 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
|
89 ## 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
|
90 ## 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
|
91 ## The continuity condition of the interpolant may be specified by using |
19294
b80b396e7d54
interp1.m: Add new methods "previous" and "next" (bug #43377).
Nir Krakauer <nkrakauer@ccny.cuny.edu>
parents:
18642
diff
changeset
|
92 ## 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
|
93 ## 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
|
94 ## 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
|
95 ## @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
|
96 ## unique. |
9929
45c08d7c2c79
allow discontinuous interpolant in interp1
Jaroslav Hajek <highegg@gmail.com>
parents:
9769
diff
changeset
|
97 ## |
5837 | 98 ## An example of the use of @code{interp1} is |
99 ## | |
100 ## @example | |
101 ## @group | |
8507 | 102 ## xf = [0:0.05:10]; |
103 ## yf = sin (2*pi*xf/5); | |
104 ## xp = [0:10]; | |
105 ## yp = sin (2*pi*xp/5); | |
106 ## lin = interp1 (xp, yp, xf); | |
18606
0ede4dbb37f1
Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents:
18418
diff
changeset
|
107 ## near = interp1 (xp, yp, xf, "nearest"); |
0ede4dbb37f1
Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents:
18418
diff
changeset
|
108 ## pch = interp1 (xp, yp, xf, "pchip"); |
8507 | 109 ## spl = interp1 (xp, yp, xf, "spline"); |
19597
db92e7e28e1f
strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents:
19596
diff
changeset
|
110 ## plot (xf,yf,"r", xf,near,"g", xf,lin,"b", xf,pch,"c", xf,spl,"m", |
18606
0ede4dbb37f1
Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents:
18418
diff
changeset
|
111 ## xp,yp,"r*"); |
0ede4dbb37f1
Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents:
18418
diff
changeset
|
112 ## legend ("original", "nearest", "linear", "pchip", "spline"); |
5837 | 113 ## @end group |
114 ## @end example | |
115 ## | |
18606
0ede4dbb37f1
Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents:
18418
diff
changeset
|
116 ## @seealso{pchip, spline, interpft, interp2, interp3, interpn} |
5837 | 117 ## @end deftypefn |
118 | |
5838 | 119 function yi = interp1 (x, y, varargin) |
5837 | 120 |
10820
c44c786f87ba
interp1.m: When absent set X equal to the inices of Y.
Ben Abbott <bpabbott@mac.com>
parents:
10793
diff
changeset
|
121 if (nargin < 2 || nargin > 6) |
5837 | 122 print_usage (); |
123 endif | |
124 | |
125 method = "linear"; | |
6742 | 126 extrap = NA; |
5837 | 127 xi = []; |
12608
59e2460acae1
make piecewise polynomial (pp) functions more compatible
Kai Habel <kai.habel@gmx.de>
parents:
12459
diff
changeset
|
128 ispp = false; |
5837 | 129 firstnumeric = true; |
18417 | 130 rightcontinuous = NaN; |
5837 | 131 |
132 if (nargin > 2) | |
5838 | 133 for i = 1:length (varargin) |
5837 | 134 arg = varargin{i}; |
5838 | 135 if (ischar (arg)) |
10549 | 136 arg = tolower (arg); |
18606
0ede4dbb37f1
Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents:
18418
diff
changeset
|
137 switch (arg) |
0ede4dbb37f1
Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents:
18418
diff
changeset
|
138 case "extrap" |
0ede4dbb37f1
Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents:
18418
diff
changeset
|
139 extrap = "extrap"; |
0ede4dbb37f1
Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents:
18418
diff
changeset
|
140 case "pp" |
0ede4dbb37f1
Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents:
18418
diff
changeset
|
141 ispp = true; |
0ede4dbb37f1
Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents:
18418
diff
changeset
|
142 case {"right", "-right"} |
0ede4dbb37f1
Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents:
18418
diff
changeset
|
143 rightcontinuous = true; |
0ede4dbb37f1
Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents:
18418
diff
changeset
|
144 case {"left", "-left"} |
0ede4dbb37f1
Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents:
18418
diff
changeset
|
145 rightcontinuous = false; |
0ede4dbb37f1
Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents:
18418
diff
changeset
|
146 otherwise |
0ede4dbb37f1
Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents:
18418
diff
changeset
|
147 method = arg; |
0ede4dbb37f1
Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents:
18418
diff
changeset
|
148 endswitch |
5837 | 149 else |
10549 | 150 if (firstnumeric) |
151 xi = arg; | |
152 firstnumeric = false; | |
153 else | |
154 extrap = arg; | |
155 endif | |
5837 | 156 endif |
157 endfor | |
158 endif | |
159 | |
12608
59e2460acae1
make piecewise polynomial (pp) functions more compatible
Kai Habel <kai.habel@gmx.de>
parents:
12459
diff
changeset
|
160 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
|
161 xi = y; |
c44c786f87ba
interp1.m: When absent set X equal to the inices of Y.
Ben Abbott <bpabbott@mac.com>
parents:
10793
diff
changeset
|
162 y = x; |
17088
c8586e6fc60d
interp1.m: Fix interpolation on ND-arrays (bug #35860)
Mike Miller <mtmiller@ieee.org>
parents:
17087
diff
changeset
|
163 if (isvector (y)) |
c8586e6fc60d
interp1.m: Fix interpolation on ND-arrays (bug #35860)
Mike Miller <mtmiller@ieee.org>
parents:
17087
diff
changeset
|
164 x = 1:numel (y); |
c8586e6fc60d
interp1.m: Fix interpolation on ND-arrays (bug #35860)
Mike Miller <mtmiller@ieee.org>
parents:
17087
diff
changeset
|
165 else |
c8586e6fc60d
interp1.m: Fix interpolation on ND-arrays (bug #35860)
Mike Miller <mtmiller@ieee.org>
parents:
17087
diff
changeset
|
166 x = 1:rows (y); |
c8586e6fc60d
interp1.m: Fix interpolation on ND-arrays (bug #35860)
Mike Miller <mtmiller@ieee.org>
parents:
17087
diff
changeset
|
167 endif |
10820
c44c786f87ba
interp1.m: When absent set X equal to the inices of Y.
Ben Abbott <bpabbott@mac.com>
parents:
10793
diff
changeset
|
168 endif |
c44c786f87ba
interp1.m: When absent set X equal to the inices of Y.
Ben Abbott <bpabbott@mac.com>
parents:
10793
diff
changeset
|
169 |
5837 | 170 ## reshape matrices for convenience |
171 x = x(:); | |
9754
4219e5cf773d
improve interp1 and pchip
Jaroslav Hajek <highegg@gmail.com>
parents:
9070
diff
changeset
|
172 nx = rows (x); |
9769
9a1c4fe44af8
small interp1 simplification
Jaroslav Hajek <highegg@gmail.com>
parents:
9754
diff
changeset
|
173 szx = size (xi); |
9754
4219e5cf773d
improve interp1 and pchip
Jaroslav Hajek <highegg@gmail.com>
parents:
9070
diff
changeset
|
174 if (isvector (y)) |
5838 | 175 y = y(:); |
5837 | 176 endif |
13141
e81ddf9cacd5
maint: untabify and remove trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
12608
diff
changeset
|
177 |
5838 | 178 szy = size (y); |
9754
4219e5cf773d
improve interp1 and pchip
Jaroslav Hajek <highegg@gmail.com>
parents:
9070
diff
changeset
|
179 y = y(:,:); |
4219e5cf773d
improve interp1 and pchip
Jaroslav Hajek <highegg@gmail.com>
parents:
9070
diff
changeset
|
180 [ny, nc] = size (y); |
5837 | 181 xi = xi(:); |
182 | |
183 ## determine sizes | |
184 if (nx < 2 || ny < 2) | |
18606
0ede4dbb37f1
Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents:
18418
diff
changeset
|
185 error ("interp1: minimum of 2 points required in each dimension"); |
5837 | 186 endif |
187 | |
9754
4219e5cf773d
improve interp1 and pchip
Jaroslav Hajek <highegg@gmail.com>
parents:
9070
diff
changeset
|
188 ## check whether x is sorted; sort if not. |
9929
45c08d7c2c79
allow discontinuous interpolant in interp1
Jaroslav Hajek <highegg@gmail.com>
parents:
9769
diff
changeset
|
189 if (! issorted (x, "either")) |
9754
4219e5cf773d
improve interp1 and pchip
Jaroslav Hajek <highegg@gmail.com>
parents:
9070
diff
changeset
|
190 [x, p] = sort (x); |
4219e5cf773d
improve interp1 and pchip
Jaroslav Hajek <highegg@gmail.com>
parents:
9070
diff
changeset
|
191 y = y(p,:); |
5837 | 192 endif |
5838 | 193 |
19294
b80b396e7d54
interp1.m: Add new methods "previous" and "next" (bug #43377).
Nir Krakauer <nkrakauer@ccny.cuny.edu>
parents:
18642
diff
changeset
|
194 if (any (strcmp (method, {"previous", "*previous", "next", "*next"}))) |
b80b396e7d54
interp1.m: Add new methods "previous" and "next" (bug #43377).
Nir Krakauer <nkrakauer@ccny.cuny.edu>
parents:
18642
diff
changeset
|
195 rightcontinuous = NaN; # needed for these methods to work |
19597
db92e7e28e1f
strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents:
19596
diff
changeset
|
196 endif |
19294
b80b396e7d54
interp1.m: Add new methods "previous" and "next" (bug #43377).
Nir Krakauer <nkrakauer@ccny.cuny.edu>
parents:
18642
diff
changeset
|
197 |
18417 | 198 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
|
199 ## 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
|
200 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
|
201 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
|
202 else |
94d512d712e3
Modified interp1.m file to check whether X has distinct values or not.
Ben Abbott <bpabbott@mac.com>
parents:
15193
diff
changeset
|
203 rightcontinuous = true; |
17306
09543e9c8f40
Use explicit form of end (endif, endfor, etc.) in core m-files.
Rik <rik@octave.org>
parents:
17281
diff
changeset
|
204 endif |
18642
a07814a8ffb0
interp1.m: Small formatting changes only.
Rik <rik@octave.org>
parents:
18635
diff
changeset
|
205 elseif ((rightcontinuous && (x(end) < x(1))) |
a07814a8ffb0
interp1.m: Small formatting changes only.
Rik <rik@octave.org>
parents:
18635
diff
changeset
|
206 || (! 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
|
207 ## 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
|
208 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
|
209 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
|
210 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
|
211 |
19294
b80b396e7d54
interp1.m: Add new methods "previous" and "next" (bug #43377).
Nir Krakauer <nkrakauer@ccny.cuny.edu>
parents:
18642
diff
changeset
|
212 ## Because of the way mkpp works, it's easiest to implement "next" |
b80b396e7d54
interp1.m: Add new methods "previous" and "next" (bug #43377).
Nir Krakauer <nkrakauer@ccny.cuny.edu>
parents:
18642
diff
changeset
|
213 ## by running "previous" with vectors flipped. |
b80b396e7d54
interp1.m: Add new methods "previous" and "next" (bug #43377).
Nir Krakauer <nkrakauer@ccny.cuny.edu>
parents:
18642
diff
changeset
|
214 if (strcmp (method, "next")) |
b80b396e7d54
interp1.m: Add new methods "previous" and "next" (bug #43377).
Nir Krakauer <nkrakauer@ccny.cuny.edu>
parents:
18642
diff
changeset
|
215 x = flipud (x); |
b80b396e7d54
interp1.m: Add new methods "previous" and "next" (bug #43377).
Nir Krakauer <nkrakauer@ccny.cuny.edu>
parents:
18642
diff
changeset
|
216 y = flipud (y); |
b80b396e7d54
interp1.m: Add new methods "previous" and "next" (bug #43377).
Nir Krakauer <nkrakauer@ccny.cuny.edu>
parents:
18642
diff
changeset
|
217 method = "previous"; |
b80b396e7d54
interp1.m: Add new methods "previous" and "next" (bug #43377).
Nir Krakauer <nkrakauer@ccny.cuny.edu>
parents:
18642
diff
changeset
|
218 elseif (strcmp (method, "*next")) |
b80b396e7d54
interp1.m: Add new methods "previous" and "next" (bug #43377).
Nir Krakauer <nkrakauer@ccny.cuny.edu>
parents:
18642
diff
changeset
|
219 x = flipud (x); |
b80b396e7d54
interp1.m: Add new methods "previous" and "next" (bug #43377).
Nir Krakauer <nkrakauer@ccny.cuny.edu>
parents:
18642
diff
changeset
|
220 y = flipud (y); |
19597
db92e7e28e1f
strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents:
19596
diff
changeset
|
221 method = "*previous"; |
19294
b80b396e7d54
interp1.m: Add new methods "previous" and "next" (bug #43377).
Nir Krakauer <nkrakauer@ccny.cuny.edu>
parents:
18642
diff
changeset
|
222 endif |
b80b396e7d54
interp1.m: Add new methods "previous" and "next" (bug #43377).
Nir Krakauer <nkrakauer@ccny.cuny.edu>
parents:
18642
diff
changeset
|
223 |
9754
4219e5cf773d
improve interp1 and pchip
Jaroslav Hajek <highegg@gmail.com>
parents:
9070
diff
changeset
|
224 starmethod = method(1) == "*"; |
4219e5cf773d
improve interp1 and pchip
Jaroslav Hajek <highegg@gmail.com>
parents:
9070
diff
changeset
|
225 |
4219e5cf773d
improve interp1 and pchip
Jaroslav Hajek <highegg@gmail.com>
parents:
9070
diff
changeset
|
226 if (starmethod) |
4219e5cf773d
improve interp1 and pchip
Jaroslav Hajek <highegg@gmail.com>
parents:
9070
diff
changeset
|
227 dx = x(2) - x(1); |
4219e5cf773d
improve interp1 and pchip
Jaroslav Hajek <highegg@gmail.com>
parents:
9070
diff
changeset
|
228 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
|
229 jumps = x(1:end-1) == x(2:end); |
9929
45c08d7c2c79
allow discontinuous interpolant in interp1
Jaroslav Hajek <highegg@gmail.com>
parents:
9769
diff
changeset
|
230 have_jumps = any (jumps); |
45c08d7c2c79
allow discontinuous interpolant in interp1
Jaroslav Hajek <highegg@gmail.com>
parents:
9769
diff
changeset
|
231 if (have_jumps) |
18417 | 232 if (strcmp (method, "linear") || strcmp (method, ("nearest"))) |
9929
45c08d7c2c79
allow discontinuous interpolant in interp1
Jaroslav Hajek <highegg@gmail.com>
parents:
9769
diff
changeset
|
233 if (any (jumps(1:nx-2) & jumps(2:nx-1))) |
18418
1ad77b3e6bef
interp1.m: Demote error to warning about multiple discontinuties (bug #41386).
Rik <rik@octave.org>
parents:
18417
diff
changeset
|
234 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
|
235 endif |
45c08d7c2c79
allow discontinuous interpolant in interp1
Jaroslav Hajek <highegg@gmail.com>
parents:
9769
diff
changeset
|
236 else |
22760
c4d80b9d2898
maint: Capitalize variable names appearing in error() messages of m-files.
Rik <rik@octave.org>
parents:
22755
diff
changeset
|
237 error ("interp1: discontinuities not supported for METHOD '%s'", |
18642
a07814a8ffb0
interp1.m: Small formatting changes only.
Rik <rik@octave.org>
parents:
18635
diff
changeset
|
238 method); |
9929
45c08d7c2c79
allow discontinuous interpolant in interp1
Jaroslav Hajek <highegg@gmail.com>
parents:
9769
diff
changeset
|
239 endif |
5837 | 240 endif |
241 endif | |
242 | |
9754
4219e5cf773d
improve interp1 and pchip
Jaroslav Hajek <highegg@gmail.com>
parents:
9070
diff
changeset
|
243 ## Proceed with interpolating by all methods. |
4219e5cf773d
improve interp1 and pchip
Jaroslav Hajek <highegg@gmail.com>
parents:
9070
diff
changeset
|
244 switch (method) |
18417 | 245 |
17174
c3c1ebfaa7dc
maint: Use common indentation for switch statement.
Rik <rik@octave.org>
parents:
17088
diff
changeset
|
246 case "nearest" |
c3c1ebfaa7dc
maint: Use common indentation for switch statement.
Rik <rik@octave.org>
parents:
17088
diff
changeset
|
247 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
|
248 shiftdim (y, 1), szy(2:end)); |
c3c1ebfaa7dc
maint: Use common indentation for switch statement.
Rik <rik@octave.org>
parents:
17088
diff
changeset
|
249 pp.orient = "first"; |
13141
e81ddf9cacd5
maint: untabify and remove trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
12608
diff
changeset
|
250 |
17174
c3c1ebfaa7dc
maint: Use common indentation for switch statement.
Rik <rik@octave.org>
parents:
17088
diff
changeset
|
251 if (ispp) |
c3c1ebfaa7dc
maint: Use common indentation for switch statement.
Rik <rik@octave.org>
parents:
17088
diff
changeset
|
252 yi = pp; |
c3c1ebfaa7dc
maint: Use common indentation for switch statement.
Rik <rik@octave.org>
parents:
17088
diff
changeset
|
253 else |
c3c1ebfaa7dc
maint: Use common indentation for switch statement.
Rik <rik@octave.org>
parents:
17088
diff
changeset
|
254 yi = ppval (pp, reshape (xi, szx)); |
c3c1ebfaa7dc
maint: Use common indentation for switch statement.
Rik <rik@octave.org>
parents:
17088
diff
changeset
|
255 endif |
18417 | 256 |
17174
c3c1ebfaa7dc
maint: Use common indentation for switch statement.
Rik <rik@octave.org>
parents:
17088
diff
changeset
|
257 case "*nearest" |
c3c1ebfaa7dc
maint: Use common indentation for switch statement.
Rik <rik@octave.org>
parents:
17088
diff
changeset
|
258 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
|
259 shiftdim (y, 1), szy(2:end)); |
c3c1ebfaa7dc
maint: Use common indentation for switch statement.
Rik <rik@octave.org>
parents:
17088
diff
changeset
|
260 pp.orient = "first"; |
18642
a07814a8ffb0
interp1.m: Small formatting changes only.
Rik <rik@octave.org>
parents:
18635
diff
changeset
|
261 |
17174
c3c1ebfaa7dc
maint: Use common indentation for switch statement.
Rik <rik@octave.org>
parents:
17088
diff
changeset
|
262 if (ispp) |
c3c1ebfaa7dc
maint: Use common indentation for switch statement.
Rik <rik@octave.org>
parents:
17088
diff
changeset
|
263 yi = pp; |
c3c1ebfaa7dc
maint: Use common indentation for switch statement.
Rik <rik@octave.org>
parents:
17088
diff
changeset
|
264 else |
c3c1ebfaa7dc
maint: Use common indentation for switch statement.
Rik <rik@octave.org>
parents:
17088
diff
changeset
|
265 yi = ppval (pp, reshape (xi, szx)); |
c3c1ebfaa7dc
maint: Use common indentation for switch statement.
Rik <rik@octave.org>
parents:
17088
diff
changeset
|
266 endif |
18417 | 267 |
19294
b80b396e7d54
interp1.m: Add new methods "previous" and "next" (bug #43377).
Nir Krakauer <nkrakauer@ccny.cuny.edu>
parents:
18642
diff
changeset
|
268 case "previous" |
b80b396e7d54
interp1.m: Add new methods "previous" and "next" (bug #43377).
Nir Krakauer <nkrakauer@ccny.cuny.edu>
parents:
18642
diff
changeset
|
269 pp = mkpp ([x(1:nx); 2*x(nx)-x(nx-1)], |
b80b396e7d54
interp1.m: Add new methods "previous" and "next" (bug #43377).
Nir Krakauer <nkrakauer@ccny.cuny.edu>
parents:
18642
diff
changeset
|
270 shiftdim (y, 1), szy(2:end)); |
b80b396e7d54
interp1.m: Add new methods "previous" and "next" (bug #43377).
Nir Krakauer <nkrakauer@ccny.cuny.edu>
parents:
18642
diff
changeset
|
271 pp.orient = "first"; |
b80b396e7d54
interp1.m: Add new methods "previous" and "next" (bug #43377).
Nir Krakauer <nkrakauer@ccny.cuny.edu>
parents:
18642
diff
changeset
|
272 |
b80b396e7d54
interp1.m: Add new methods "previous" and "next" (bug #43377).
Nir Krakauer <nkrakauer@ccny.cuny.edu>
parents:
18642
diff
changeset
|
273 if (ispp) |
b80b396e7d54
interp1.m: Add new methods "previous" and "next" (bug #43377).
Nir Krakauer <nkrakauer@ccny.cuny.edu>
parents:
18642
diff
changeset
|
274 yi = pp; |
b80b396e7d54
interp1.m: Add new methods "previous" and "next" (bug #43377).
Nir Krakauer <nkrakauer@ccny.cuny.edu>
parents:
18642
diff
changeset
|
275 else |
b80b396e7d54
interp1.m: Add new methods "previous" and "next" (bug #43377).
Nir Krakauer <nkrakauer@ccny.cuny.edu>
parents:
18642
diff
changeset
|
276 yi = ppval (pp, reshape (xi, szx)); |
b80b396e7d54
interp1.m: Add new methods "previous" and "next" (bug #43377).
Nir Krakauer <nkrakauer@ccny.cuny.edu>
parents:
18642
diff
changeset
|
277 endif |
b80b396e7d54
interp1.m: Add new methods "previous" and "next" (bug #43377).
Nir Krakauer <nkrakauer@ccny.cuny.edu>
parents:
18642
diff
changeset
|
278 |
b80b396e7d54
interp1.m: Add new methods "previous" and "next" (bug #43377).
Nir Krakauer <nkrakauer@ccny.cuny.edu>
parents:
18642
diff
changeset
|
279 case "*previous" |
b80b396e7d54
interp1.m: Add new methods "previous" and "next" (bug #43377).
Nir Krakauer <nkrakauer@ccny.cuny.edu>
parents:
18642
diff
changeset
|
280 pp = mkpp (x(1)+[0:nx]*dx, |
b80b396e7d54
interp1.m: Add new methods "previous" and "next" (bug #43377).
Nir Krakauer <nkrakauer@ccny.cuny.edu>
parents:
18642
diff
changeset
|
281 shiftdim (y, 1), szy(2:end)); |
b80b396e7d54
interp1.m: Add new methods "previous" and "next" (bug #43377).
Nir Krakauer <nkrakauer@ccny.cuny.edu>
parents:
18642
diff
changeset
|
282 pp.orient = "first"; |
b80b396e7d54
interp1.m: Add new methods "previous" and "next" (bug #43377).
Nir Krakauer <nkrakauer@ccny.cuny.edu>
parents:
18642
diff
changeset
|
283 |
17174
c3c1ebfaa7dc
maint: Use common indentation for switch statement.
Rik <rik@octave.org>
parents:
17088
diff
changeset
|
284 if (ispp) |
c3c1ebfaa7dc
maint: Use common indentation for switch statement.
Rik <rik@octave.org>
parents:
17088
diff
changeset
|
285 yi = pp; |
c3c1ebfaa7dc
maint: Use common indentation for switch statement.
Rik <rik@octave.org>
parents:
17088
diff
changeset
|
286 else |
c3c1ebfaa7dc
maint: Use common indentation for switch statement.
Rik <rik@octave.org>
parents:
17088
diff
changeset
|
287 yi = ppval (pp, reshape (xi, szx)); |
c3c1ebfaa7dc
maint: Use common indentation for switch statement.
Rik <rik@octave.org>
parents:
17088
diff
changeset
|
288 endif |
18417 | 289 |
17174
c3c1ebfaa7dc
maint: Use common indentation for switch statement.
Rik <rik@octave.org>
parents:
17088
diff
changeset
|
290 case "linear" |
18415
b06675ef40f2
interp1.m: Fix handling multi-column y-input with jumps (bug #40825).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents:
17744
diff
changeset
|
291 |
17174
c3c1ebfaa7dc
maint: Use common indentation for switch statement.
Rik <rik@octave.org>
parents:
17088
diff
changeset
|
292 xx = x; |
18633
5fe907167520
interp1.m: fix function for inputs w/multiple discontinuities (bug #41980).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents:
18418
diff
changeset
|
293 nxx = nx; |
18415
b06675ef40f2
interp1.m: Fix handling multi-column y-input with jumps (bug #40825).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents:
17744
diff
changeset
|
294 yy = y; |
18633
5fe907167520
interp1.m: fix function for inputs w/multiple discontinuities (bug #41980).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents:
18418
diff
changeset
|
295 dy = diff (yy); |
17174
c3c1ebfaa7dc
maint: Use common indentation for switch statement.
Rik <rik@octave.org>
parents:
17088
diff
changeset
|
296 if (have_jumps) |
c3c1ebfaa7dc
maint: Use common indentation for switch statement.
Rik <rik@octave.org>
parents:
17088
diff
changeset
|
297 ## Omit zero-size intervals. |
c3c1ebfaa7dc
maint: Use common indentation for switch statement.
Rik <rik@octave.org>
parents:
17088
diff
changeset
|
298 xx(jumps) = []; |
18415
b06675ef40f2
interp1.m: Fix handling multi-column y-input with jumps (bug #40825).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents:
17744
diff
changeset
|
299 nxx = rows (xx); |
18633
5fe907167520
interp1.m: fix function for inputs w/multiple discontinuities (bug #41980).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents:
18418
diff
changeset
|
300 yy(jumps, :) = []; |
5fe907167520
interp1.m: fix function for inputs w/multiple discontinuities (bug #41980).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents:
18418
diff
changeset
|
301 dy(jumps, :) = []; |
17174
c3c1ebfaa7dc
maint: Use common indentation for switch statement.
Rik <rik@octave.org>
parents:
17088
diff
changeset
|
302 endif |
12608
59e2460acae1
make piecewise polynomial (pp) functions more compatible
Kai Habel <kai.habel@gmx.de>
parents:
12459
diff
changeset
|
303 |
18415
b06675ef40f2
interp1.m: Fix handling multi-column y-input with jumps (bug #40825).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents:
17744
diff
changeset
|
304 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
|
305 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
|
306 |
18633
5fe907167520
interp1.m: fix function for inputs w/multiple discontinuities (bug #41980).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents:
18418
diff
changeset
|
307 coefs = [(dy./dx).', yy(1:nxx-1, :).']; |
18415
b06675ef40f2
interp1.m: Fix handling multi-column y-input with jumps (bug #40825).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents:
17744
diff
changeset
|
308 |
17174
c3c1ebfaa7dc
maint: Use common indentation for switch statement.
Rik <rik@octave.org>
parents:
17088
diff
changeset
|
309 pp = mkpp (xx, coefs, szy(2:end)); |
c3c1ebfaa7dc
maint: Use common indentation for switch statement.
Rik <rik@octave.org>
parents:
17088
diff
changeset
|
310 pp.orient = "first"; |
12608
59e2460acae1
make piecewise polynomial (pp) functions more compatible
Kai Habel <kai.habel@gmx.de>
parents:
12459
diff
changeset
|
311 |
17174
c3c1ebfaa7dc
maint: Use common indentation for switch statement.
Rik <rik@octave.org>
parents:
17088
diff
changeset
|
312 if (ispp) |
c3c1ebfaa7dc
maint: Use common indentation for switch statement.
Rik <rik@octave.org>
parents:
17088
diff
changeset
|
313 yi = pp; |
c3c1ebfaa7dc
maint: Use common indentation for switch statement.
Rik <rik@octave.org>
parents:
17088
diff
changeset
|
314 else |
c3c1ebfaa7dc
maint: Use common indentation for switch statement.
Rik <rik@octave.org>
parents:
17088
diff
changeset
|
315 yi = ppval (pp, reshape (xi, szx)); |
c3c1ebfaa7dc
maint: Use common indentation for switch statement.
Rik <rik@octave.org>
parents:
17088
diff
changeset
|
316 endif |
12608
59e2460acae1
make piecewise polynomial (pp) functions more compatible
Kai Habel <kai.habel@gmx.de>
parents:
12459
diff
changeset
|
317 |
17174
c3c1ebfaa7dc
maint: Use common indentation for switch statement.
Rik <rik@octave.org>
parents:
17088
diff
changeset
|
318 case "*linear" |
c3c1ebfaa7dc
maint: Use common indentation for switch statement.
Rik <rik@octave.org>
parents:
17088
diff
changeset
|
319 dy = diff (y); |
c3c1ebfaa7dc
maint: Use common indentation for switch statement.
Rik <rik@octave.org>
parents:
17088
diff
changeset
|
320 coefs = [(dy/dx).'(:), y(1:nx-1, :).'(:)]; |
c3c1ebfaa7dc
maint: Use common indentation for switch statement.
Rik <rik@octave.org>
parents:
17088
diff
changeset
|
321 pp = mkpp (x, coefs, szy(2:end)); |
c3c1ebfaa7dc
maint: Use common indentation for switch statement.
Rik <rik@octave.org>
parents:
17088
diff
changeset
|
322 pp.orient = "first"; |
12608
59e2460acae1
make piecewise polynomial (pp) functions more compatible
Kai Habel <kai.habel@gmx.de>
parents:
12459
diff
changeset
|
323 |
17174
c3c1ebfaa7dc
maint: Use common indentation for switch statement.
Rik <rik@octave.org>
parents:
17088
diff
changeset
|
324 if (ispp) |
c3c1ebfaa7dc
maint: Use common indentation for switch statement.
Rik <rik@octave.org>
parents:
17088
diff
changeset
|
325 yi = pp; |
c3c1ebfaa7dc
maint: Use common indentation for switch statement.
Rik <rik@octave.org>
parents:
17088
diff
changeset
|
326 else |
c3c1ebfaa7dc
maint: Use common indentation for switch statement.
Rik <rik@octave.org>
parents:
17088
diff
changeset
|
327 yi = ppval (pp, reshape (xi, szx)); |
c3c1ebfaa7dc
maint: Use common indentation for switch statement.
Rik <rik@octave.org>
parents:
17088
diff
changeset
|
328 endif |
5837 | 329 |
17174
c3c1ebfaa7dc
maint: Use common indentation for switch statement.
Rik <rik@octave.org>
parents:
17088
diff
changeset
|
330 case {"pchip", "*pchip", "cubic", "*cubic"} |
c3c1ebfaa7dc
maint: Use common indentation for switch statement.
Rik <rik@octave.org>
parents:
17088
diff
changeset
|
331 if (nx == 2 || starmethod) |
c3c1ebfaa7dc
maint: Use common indentation for switch statement.
Rik <rik@octave.org>
parents:
17088
diff
changeset
|
332 x = linspace (x(1), x(nx), ny); |
c3c1ebfaa7dc
maint: Use common indentation for switch statement.
Rik <rik@octave.org>
parents:
17088
diff
changeset
|
333 endif |
13141
e81ddf9cacd5
maint: untabify and remove trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
12608
diff
changeset
|
334 |
17174
c3c1ebfaa7dc
maint: Use common indentation for switch statement.
Rik <rik@octave.org>
parents:
17088
diff
changeset
|
335 if (ispp) |
c3c1ebfaa7dc
maint: Use common indentation for switch statement.
Rik <rik@octave.org>
parents:
17088
diff
changeset
|
336 y = shiftdim (reshape (y, szy), 1); |
c3c1ebfaa7dc
maint: Use common indentation for switch statement.
Rik <rik@octave.org>
parents:
17088
diff
changeset
|
337 yi = pchip (x, y); |
c3c1ebfaa7dc
maint: Use common indentation for switch statement.
Rik <rik@octave.org>
parents:
17088
diff
changeset
|
338 yi.orient = "first"; |
c3c1ebfaa7dc
maint: Use common indentation for switch statement.
Rik <rik@octave.org>
parents:
17088
diff
changeset
|
339 else |
c3c1ebfaa7dc
maint: Use common indentation for switch statement.
Rik <rik@octave.org>
parents:
17088
diff
changeset
|
340 y = shiftdim (y, 1); |
c3c1ebfaa7dc
maint: Use common indentation for switch statement.
Rik <rik@octave.org>
parents:
17088
diff
changeset
|
341 yi = pchip (x, y, reshape (xi, szx)); |
c3c1ebfaa7dc
maint: Use common indentation for switch statement.
Rik <rik@octave.org>
parents:
17088
diff
changeset
|
342 if (! isvector (y)) |
c3c1ebfaa7dc
maint: Use common indentation for switch statement.
Rik <rik@octave.org>
parents:
17088
diff
changeset
|
343 yi = shiftdim (yi, 1); |
c3c1ebfaa7dc
maint: Use common indentation for switch statement.
Rik <rik@octave.org>
parents:
17088
diff
changeset
|
344 endif |
c3c1ebfaa7dc
maint: Use common indentation for switch statement.
Rik <rik@octave.org>
parents:
17088
diff
changeset
|
345 endif |
18417 | 346 |
17174
c3c1ebfaa7dc
maint: Use common indentation for switch statement.
Rik <rik@octave.org>
parents:
17088
diff
changeset
|
347 case {"spline", "*spline"} |
c3c1ebfaa7dc
maint: Use common indentation for switch statement.
Rik <rik@octave.org>
parents:
17088
diff
changeset
|
348 if (nx == 2 || starmethod) |
c3c1ebfaa7dc
maint: Use common indentation for switch statement.
Rik <rik@octave.org>
parents:
17088
diff
changeset
|
349 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
|
350 endif |
13141
e81ddf9cacd5
maint: untabify and remove trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
12608
diff
changeset
|
351 |
17174
c3c1ebfaa7dc
maint: Use common indentation for switch statement.
Rik <rik@octave.org>
parents:
17088
diff
changeset
|
352 if (ispp) |
c3c1ebfaa7dc
maint: Use common indentation for switch statement.
Rik <rik@octave.org>
parents:
17088
diff
changeset
|
353 y = shiftdim (reshape (y, szy), 1); |
c3c1ebfaa7dc
maint: Use common indentation for switch statement.
Rik <rik@octave.org>
parents:
17088
diff
changeset
|
354 yi = spline (x, y); |
c3c1ebfaa7dc
maint: Use common indentation for switch statement.
Rik <rik@octave.org>
parents:
17088
diff
changeset
|
355 yi.orient = "first"; |
c3c1ebfaa7dc
maint: Use common indentation for switch statement.
Rik <rik@octave.org>
parents:
17088
diff
changeset
|
356 else |
c3c1ebfaa7dc
maint: Use common indentation for switch statement.
Rik <rik@octave.org>
parents:
17088
diff
changeset
|
357 y = shiftdim (y, 1); |
c3c1ebfaa7dc
maint: Use common indentation for switch statement.
Rik <rik@octave.org>
parents:
17088
diff
changeset
|
358 yi = spline (x, y, reshape (xi, szx)); |
c3c1ebfaa7dc
maint: Use common indentation for switch statement.
Rik <rik@octave.org>
parents:
17088
diff
changeset
|
359 if (! isvector (y)) |
c3c1ebfaa7dc
maint: Use common indentation for switch statement.
Rik <rik@octave.org>
parents:
17088
diff
changeset
|
360 yi = shiftdim (yi, 1); |
c3c1ebfaa7dc
maint: Use common indentation for switch statement.
Rik <rik@octave.org>
parents:
17088
diff
changeset
|
361 endif |
14492
7ce925166af6
Fix inconsistent orientation of output matrix for interp1.
Olaf Till <i7tiol@t-online.de>
parents:
14363
diff
changeset
|
362 endif |
18417 | 363 |
17174
c3c1ebfaa7dc
maint: Use common indentation for switch statement.
Rik <rik@octave.org>
parents:
17088
diff
changeset
|
364 otherwise |
22765
01aae08a0105
maint: Rename variables to match documentation in m-files.
Rik <rik@octave.org>
parents:
22760
diff
changeset
|
365 error ("interp1: invalid METHOD '%s'", method); |
18417 | 366 |
9754
4219e5cf773d
improve interp1 and pchip
Jaroslav Hajek <highegg@gmail.com>
parents:
9070
diff
changeset
|
367 endswitch |
5837 | 368 |
18606
0ede4dbb37f1
Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents:
18418
diff
changeset
|
369 if (! ispp && isnumeric (extrap)) |
18417 | 370 ## determine which values are out of range and set them to extrap, |
371 ## unless extrap == "extrap". | |
372 minx = min (x(1), x(nx)); | |
373 maxx = max (x(1), x(nx)); | |
9754
4219e5cf773d
improve interp1 and pchip
Jaroslav Hajek <highegg@gmail.com>
parents:
9070
diff
changeset
|
374 |
19383
ef649fe230f5
interp1.m: Fix shape of output matrix when there are extrapolated values (bug #43745).
Nir Krakauer <nkrakauer@ccny.cuny.edu>
parents:
18633
diff
changeset
|
375 xi = reshape (xi, szx); |
23512
22fd2ad85218
interp1.m: Return NA for all columns which are out of bounds (bug #51030).
Rik <rik@octave.org>
parents:
23219
diff
changeset
|
376 outliers = (xi < minx) | ! (xi <= maxx); # this even catches NaNs |
18417 | 377 if (size_equal (outliers, yi)) |
378 yi(outliers) = extrap; | |
379 yi = reshape (yi, szx); | |
23512
22fd2ad85218
interp1.m: Return NA for all columns which are out of bounds (bug #51030).
Rik <rik@octave.org>
parents:
23219
diff
changeset
|
380 elseif (! isscalar (yi)) |
18417 | 381 yi(outliers, :) = extrap; |
382 else | |
23512
22fd2ad85218
interp1.m: Return NA for all columns which are out of bounds (bug #51030).
Rik <rik@octave.org>
parents:
23219
diff
changeset
|
383 warning ("interp1: Unreachable state. Please submit data that produced this warning to bugs.octave.org"); |
18417 | 384 yi(outliers.') = extrap; |
9754
4219e5cf773d
improve interp1 and pchip
Jaroslav Hajek <highegg@gmail.com>
parents:
9070
diff
changeset
|
385 endif |
19383
ef649fe230f5
interp1.m: Fix shape of output matrix when there are extrapolated values (bug #43745).
Nir Krakauer <nkrakauer@ccny.cuny.edu>
parents:
18633
diff
changeset
|
386 |
5837 | 387 endif |
388 | |
389 endfunction | |
390 | |
14237
11949c9795a0
Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
391 |
5837 | 392 %!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
|
393 %! clf; |
14363
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14359
diff
changeset
|
394 %! 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
|
395 %! xp = 0:10; yp = sin (2*pi*xp/5); |
18606
0ede4dbb37f1
Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents:
18418
diff
changeset
|
396 %! lin = interp1 (xp,yp,xf, 'linear'); |
0ede4dbb37f1
Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents:
18418
diff
changeset
|
397 %! spl = interp1 (xp,yp,xf, 'spline'); |
0ede4dbb37f1
Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents:
18418
diff
changeset
|
398 %! pch = interp1 (xp,yp,xf, 'pchip'); |
0ede4dbb37f1
Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents:
18418
diff
changeset
|
399 %! near= interp1 (xp,yp,xf, 'nearest'); |
0ede4dbb37f1
Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents:
18418
diff
changeset
|
400 %! plot (xf,yf,'r',xf,near,'g',xf,lin,'b',xf,pch,'c',xf,spl,'m',xp,yp,'r*'); |
0ede4dbb37f1
Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents:
18418
diff
changeset
|
401 %! legend ('original', 'nearest', 'linear', 'pchip', 'spline'); |
0ede4dbb37f1
Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents:
18418
diff
changeset
|
402 %! title ('Interpolation of continuous function sin (x) w/various methods'); |
5837 | 403 %! %-------------------------------------------------------- |
404 %! % confirm that interpolated function matches the original | |
405 | |
406 %!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
|
407 %! clf; |
14363
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14359
diff
changeset
|
408 %! 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
|
409 %! xp = 0:10; yp = sin (2*pi*xp/5); |
18606
0ede4dbb37f1
Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents:
18418
diff
changeset
|
410 %! lin = interp1 (xp,yp,xf, '*linear'); |
0ede4dbb37f1
Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents:
18418
diff
changeset
|
411 %! spl = interp1 (xp,yp,xf, '*spline'); |
0ede4dbb37f1
Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents:
18418
diff
changeset
|
412 %! pch = interp1 (xp,yp,xf, '*pchip'); |
0ede4dbb37f1
Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents:
18418
diff
changeset
|
413 %! near= interp1 (xp,yp,xf, '*nearest'); |
0ede4dbb37f1
Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents:
18418
diff
changeset
|
414 %! plot (xf,yf,'r',xf,near,'g',xf,lin,'b',xf,pch,'c',xf,spl,'m',xp,yp,'r*'); |
0ede4dbb37f1
Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents:
18418
diff
changeset
|
415 %! legend ('*original', '*nearest', '*linear', '*pchip', '*spline'); |
0ede4dbb37f1
Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents:
18418
diff
changeset
|
416 %! title ('Interpolation of continuous function sin (x) w/various *methods'); |
5837 | 417 %! %-------------------------------------------------------- |
418 %! % confirm that interpolated function matches the original | |
419 | |
6721 | 420 %!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
|
421 %! clf; |
18606
0ede4dbb37f1
Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents:
18418
diff
changeset
|
422 %! fstep = @(x) x > 1; |
0ede4dbb37f1
Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents:
18418
diff
changeset
|
423 %! xf = 0:0.05:2; yf = fstep (xf); |
0ede4dbb37f1
Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents:
18418
diff
changeset
|
424 %! xp = linspace (0,2,10); yp = fstep (xp); |
0ede4dbb37f1
Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents:
18418
diff
changeset
|
425 %! pch = interp1 (xp,yp,xf, 'pchip'); |
0ede4dbb37f1
Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents:
18418
diff
changeset
|
426 %! spl = interp1 (xp,yp,xf, 'spline'); |
0ede4dbb37f1
Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents:
18418
diff
changeset
|
427 %! plot (xf,yf,'r',xf,pch,'b',xf,spl,'m',xp,yp,'r*'); |
0ede4dbb37f1
Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents:
18418
diff
changeset
|
428 %! title ({'Interpolation of step function with discontinuity at x==1', ... |
0ede4dbb37f1
Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents:
18418
diff
changeset
|
429 %! 'Note: "pchip" is shape-preserving, "spline" (continuous 1st, 2nd derivatives) is not'}); |
0ede4dbb37f1
Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents:
18418
diff
changeset
|
430 %! legend ('original', 'pchip', 'spline'); |
0ede4dbb37f1
Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents:
18418
diff
changeset
|
431 |
0ede4dbb37f1
Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents:
18418
diff
changeset
|
432 %!demo |
0ede4dbb37f1
Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents:
18418
diff
changeset
|
433 %! clf; |
6721 | 434 %! t = 0 : 0.3 : pi; dt = t(2)-t(1); |
435 %! n = length (t); k = 100; dti = dt*n/k; | |
436 %! ti = t(1) + [0 : k-1]*dti; | |
437 %! y = sin (4*t + 0.3) .* cos (3*t - 0.1); | |
18606
0ede4dbb37f1
Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents:
18418
diff
changeset
|
438 %! ddys = diff (diff (interp1 (t,y,ti, 'spline'))./dti)./dti; |
0ede4dbb37f1
Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents:
18418
diff
changeset
|
439 %! ddyp = diff (diff (interp1 (t,y,ti, 'pchip')) ./dti)./dti; |
0ede4dbb37f1
Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents:
18418
diff
changeset
|
440 %! ddyc = diff (diff (interp1 (t,y,ti, 'cubic')) ./dti)./dti; |
0ede4dbb37f1
Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents:
18418
diff
changeset
|
441 %! plot (ti(2:end-1),ddys,'b*', ti(2:end-1),ddyp,'c^', ti(2:end-1),ddyc,'g+'); |
0ede4dbb37f1
Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents:
18418
diff
changeset
|
442 %! title ({'Second derivative of interpolated "sin (4*t + 0.3) .* cos (3*t - 0.1)"', ... |
27956
2310164737b3
fix many spelling errors (bug #57613)
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
443 %! 'Note: "spline" has continuous 2nd derivative, others do not'}); |
18606
0ede4dbb37f1
Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents:
18418
diff
changeset
|
444 %! legend ('spline', 'pchip', 'cubic'); |
6721 | 445 |
9929
45c08d7c2c79
allow discontinuous interpolant in interp1
Jaroslav Hajek <highegg@gmail.com>
parents:
9769
diff
changeset
|
446 %!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
|
447 %! clf; |
14363
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14359
diff
changeset
|
448 %! 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
|
449 %! xp = [0:.5:4.5,4.99,5:.5:10]; yp = sin (2*pi*xp/5) - (xp >= 5); |
18606
0ede4dbb37f1
Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents:
18418
diff
changeset
|
450 %! lin = interp1 (xp,yp,xf, 'linear'); |
0ede4dbb37f1
Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents:
18418
diff
changeset
|
451 %! near= interp1 (xp,yp,xf, 'nearest'); |
0ede4dbb37f1
Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents:
18418
diff
changeset
|
452 %! plot (xf,yf,'r', xf,near,'g', xf,lin,'b', xp,yp,'r*'); |
0ede4dbb37f1
Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents:
18418
diff
changeset
|
453 %! legend ('original', 'nearest', 'linear'); |
9929
45c08d7c2c79
allow discontinuous interpolant in interp1
Jaroslav Hajek <highegg@gmail.com>
parents:
9769
diff
changeset
|
454 %! %-------------------------------------------------------- |
45c08d7c2c79
allow discontinuous interpolant in interp1
Jaroslav Hajek <highegg@gmail.com>
parents:
9769
diff
changeset
|
455 %! % confirm that interpolated function matches the original |
45c08d7c2c79
allow discontinuous interpolant in interp1
Jaroslav Hajek <highegg@gmail.com>
parents:
9769
diff
changeset
|
456 |
15218
94d512d712e3
Modified interp1.m file to check whether X has distinct values or not.
Ben Abbott <bpabbott@mac.com>
parents:
15193
diff
changeset
|
457 %!demo |
94d512d712e3
Modified interp1.m file to check whether X has distinct values or not.
Ben Abbott <bpabbott@mac.com>
parents:
15193
diff
changeset
|
458 %! clf; |
94d512d712e3
Modified interp1.m file to check whether X has distinct values or not.
Ben Abbott <bpabbott@mac.com>
parents:
15193
diff
changeset
|
459 %! 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
|
460 %! 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
|
461 %! 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
|
462 %! 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
|
463 %! 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
|
464 %! 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
|
465 %! 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
|
466 %! g = plot (x, interp1 (x2, y2, x), 'r', x2, y2, '*r'); |
21580
ecce63c99c3f
maint: Add semicolons to terminate code in %! blocks.
Rik <rik@octave.org>
parents:
21546
diff
changeset
|
467 %! axis ([0.5 3.5 -0.5 1.5]); |
18417 | 468 %! legend ([h(1), g(1)], {'left-continuous', 'right-continuous'}, ... |
469 %! '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
|
470 %! 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
|
471 %! %-------------------------------------------------------- |
18417 | 472 %! % 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
|
473 |
18606
0ede4dbb37f1
Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents:
18418
diff
changeset
|
474 ##FIXME: add test for N-d arguments here |
9929
45c08d7c2c79
allow discontinuous interpolant in interp1
Jaroslav Hajek <highegg@gmail.com>
parents:
9769
diff
changeset
|
475 |
6374 | 476 ## For each type of interpolated test, confirm that the interpolated |
477 ## 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
|
478 ## from the knots are requested, but only "nearest" and "linear" |
6374 | 479 ## confirm they are the correct values. |
480 | |
5837 | 481 %!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
|
482 %! 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
|
483 %! yp = sin (2*pi*xp/5); |
6374 | 484 %! xi = [-1, 0, 2.2, 4, 6.6, 10, 11]; |
485 | |
486 ## The following BLOCK/ENDBLOCK section is repeated for each style | |
19294
b80b396e7d54
interp1.m: Add new methods "previous" and "next" (bug #43377).
Nir Krakauer <nkrakauer@ccny.cuny.edu>
parents:
18642
diff
changeset
|
487 ## nearest, previous, next, linear, cubic, spline, pchip |
6374 | 488 ## The test for ppval of cubic has looser tolerance, but otherwise |
489 ## the tests are identical. | |
490 ## 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
|
491 ## be sure to add them to both sections of each block. One test, |
6374 | 492 ## style vs. *style, occurs only in the first section. |
493 ## 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
|
494 |
5837 | 495 %!test style = "nearest"; |
6374 | 496 ## BLOCK |
14363
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14359
diff
changeset
|
497 %!assert (interp1 (xp, yp, [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
|
498 %!assert (interp1 (xp,yp,xp,style), yp, 100*eps) |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14359
diff
changeset
|
499 %!assert (interp1 (xp,yp,xp',style), yp', 100*eps) |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14359
diff
changeset
|
500 %!assert (interp1 (xp',yp',xp',style), yp', 100*eps) |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14359
diff
changeset
|
501 %!assert (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
|
502 %!assert (isempty (interp1 (xp',yp',[],style))) |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14359
diff
changeset
|
503 %!assert (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
|
504 %!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
|
505 %! [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
|
506 %!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
|
507 %! 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
|
508 %!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
|
509 %! 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
|
510 %!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
|
511 %!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
|
512 %! 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
|
513 %!test style = ["*",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, [min(xp)-1, max(xp)+1],style), [NA, NA]) |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14359
diff
changeset
|
515 %!assert (interp1 (xp,yp,xp,style), yp, 100*eps) |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14359
diff
changeset
|
516 %!assert (interp1 (xp,yp,xp',style), yp', 100*eps) |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14359
diff
changeset
|
517 %!assert (interp1 (xp',yp',xp',style), yp', 100*eps) |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14359
diff
changeset
|
518 %!assert (interp1 (xp',yp',xp,style), yp, 100*eps) |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14359
diff
changeset
|
519 %!assert (isempty (interp1 (xp',yp',[],style))) |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14359
diff
changeset
|
520 %!assert (isempty (interp1 (xp,yp,[],style))) |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14359
diff
changeset
|
521 %!assert (interp1 (xp,[yp',yp'],xi(:),style),... |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14359
diff
changeset
|
522 %! [interp1(xp,yp,xi(:),style),interp1(xp,yp,xi(:),style)]) |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14359
diff
changeset
|
523 %!assert (interp1 (xp,yp,xi,style),... |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14359
diff
changeset
|
524 %! interp1 (fliplr (xp),fliplr (yp),xi,style),100*eps) |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14359
diff
changeset
|
525 %!assert (ppval (interp1 (xp,yp,style,"pp"),xi), |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14359
diff
changeset
|
526 %! interp1 (xp,yp,xi,style,"extrap"),10*eps) |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14359
diff
changeset
|
527 %!error interp1 (1,1,1, style) |
6374 | 528 ## 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
|
529 |
19294
b80b396e7d54
interp1.m: Add new methods "previous" and "next" (bug #43377).
Nir Krakauer <nkrakauer@ccny.cuny.edu>
parents:
18642
diff
changeset
|
530 %!test style = "previous"; |
b80b396e7d54
interp1.m: Add new methods "previous" and "next" (bug #43377).
Nir Krakauer <nkrakauer@ccny.cuny.edu>
parents:
18642
diff
changeset
|
531 ## BLOCK |
b80b396e7d54
interp1.m: Add new methods "previous" and "next" (bug #43377).
Nir Krakauer <nkrakauer@ccny.cuny.edu>
parents:
18642
diff
changeset
|
532 %!assert (interp1 (xp, yp, [min(xp)-1, max(xp)+1],style), [NA, NA]) |
b80b396e7d54
interp1.m: Add new methods "previous" and "next" (bug #43377).
Nir Krakauer <nkrakauer@ccny.cuny.edu>
parents:
18642
diff
changeset
|
533 %!assert (interp1 (xp,yp,xp,style), yp, 100*eps) |
b80b396e7d54
interp1.m: Add new methods "previous" and "next" (bug #43377).
Nir Krakauer <nkrakauer@ccny.cuny.edu>
parents:
18642
diff
changeset
|
534 %!assert (interp1 (xp,yp,xp',style), yp', 100*eps) |
b80b396e7d54
interp1.m: Add new methods "previous" and "next" (bug #43377).
Nir Krakauer <nkrakauer@ccny.cuny.edu>
parents:
18642
diff
changeset
|
535 %!assert (interp1 (xp',yp',xp',style), yp', 100*eps) |
b80b396e7d54
interp1.m: Add new methods "previous" and "next" (bug #43377).
Nir Krakauer <nkrakauer@ccny.cuny.edu>
parents:
18642
diff
changeset
|
536 %!assert (interp1 (xp',yp',xp,style), yp, 100*eps) |
b80b396e7d54
interp1.m: Add new methods "previous" and "next" (bug #43377).
Nir Krakauer <nkrakauer@ccny.cuny.edu>
parents:
18642
diff
changeset
|
537 %!assert (isempty (interp1 (xp',yp',[],style))) |
b80b396e7d54
interp1.m: Add new methods "previous" and "next" (bug #43377).
Nir Krakauer <nkrakauer@ccny.cuny.edu>
parents:
18642
diff
changeset
|
538 %!assert (isempty (interp1 (xp,yp,[],style))) |
b80b396e7d54
interp1.m: Add new methods "previous" and "next" (bug #43377).
Nir Krakauer <nkrakauer@ccny.cuny.edu>
parents:
18642
diff
changeset
|
539 %!assert (interp1 (xp,[yp',yp'],xi(:),style),... |
b80b396e7d54
interp1.m: Add new methods "previous" and "next" (bug #43377).
Nir Krakauer <nkrakauer@ccny.cuny.edu>
parents:
18642
diff
changeset
|
540 %! [interp1(xp,yp,xi(:),style),interp1(xp,yp,xi(:),style)]) |
b80b396e7d54
interp1.m: Add new methods "previous" and "next" (bug #43377).
Nir Krakauer <nkrakauer@ccny.cuny.edu>
parents:
18642
diff
changeset
|
541 ## This test is expected to fail, so commented out. |
b80b396e7d54
interp1.m: Add new methods "previous" and "next" (bug #43377).
Nir Krakauer <nkrakauer@ccny.cuny.edu>
parents:
18642
diff
changeset
|
542 ## "previous" and "next" options are not symmetric w.r.t to flipping xp,yp |
19597
db92e7e28e1f
strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents:
19596
diff
changeset
|
543 #%!assert (interp1 (xp,yp,xi,style),... |
19294
b80b396e7d54
interp1.m: Add new methods "previous" and "next" (bug #43377).
Nir Krakauer <nkrakauer@ccny.cuny.edu>
parents:
18642
diff
changeset
|
544 #%! interp1 (fliplr (xp),fliplr (yp),xi,style),100*eps) |
b80b396e7d54
interp1.m: Add new methods "previous" and "next" (bug #43377).
Nir Krakauer <nkrakauer@ccny.cuny.edu>
parents:
18642
diff
changeset
|
545 %!assert (ppval (interp1 (xp,yp,style,"pp"),xi), |
b80b396e7d54
interp1.m: Add new methods "previous" and "next" (bug #43377).
Nir Krakauer <nkrakauer@ccny.cuny.edu>
parents:
18642
diff
changeset
|
546 %! interp1 (xp,yp,xi,style,"extrap"),10*eps) |
b80b396e7d54
interp1.m: Add new methods "previous" and "next" (bug #43377).
Nir Krakauer <nkrakauer@ccny.cuny.edu>
parents:
18642
diff
changeset
|
547 %!error interp1 (1,1,1, style) |
b80b396e7d54
interp1.m: Add new methods "previous" and "next" (bug #43377).
Nir Krakauer <nkrakauer@ccny.cuny.edu>
parents:
18642
diff
changeset
|
548 %!assert (interp1 (xp,[yp',yp'],xi,style), |
b80b396e7d54
interp1.m: Add new methods "previous" and "next" (bug #43377).
Nir Krakauer <nkrakauer@ccny.cuny.edu>
parents:
18642
diff
changeset
|
549 %! interp1 (xp,[yp',yp'],xi,["*",style]),100*eps) |
b80b396e7d54
interp1.m: Add new methods "previous" and "next" (bug #43377).
Nir Krakauer <nkrakauer@ccny.cuny.edu>
parents:
18642
diff
changeset
|
550 %!test style = ["*",style]; |
b80b396e7d54
interp1.m: Add new methods "previous" and "next" (bug #43377).
Nir Krakauer <nkrakauer@ccny.cuny.edu>
parents:
18642
diff
changeset
|
551 %!assert (interp1 (xp, yp, [min(xp)-1, max(xp)+1],style), [NA, NA]) |
b80b396e7d54
interp1.m: Add new methods "previous" and "next" (bug #43377).
Nir Krakauer <nkrakauer@ccny.cuny.edu>
parents:
18642
diff
changeset
|
552 %!assert (interp1 (xp,yp,xp,style), yp, 100*eps) |
b80b396e7d54
interp1.m: Add new methods "previous" and "next" (bug #43377).
Nir Krakauer <nkrakauer@ccny.cuny.edu>
parents:
18642
diff
changeset
|
553 %!assert (interp1 (xp,yp,xp',style), yp', 100*eps) |
b80b396e7d54
interp1.m: Add new methods "previous" and "next" (bug #43377).
Nir Krakauer <nkrakauer@ccny.cuny.edu>
parents:
18642
diff
changeset
|
554 %!assert (interp1 (xp',yp',xp',style), yp', 100*eps) |
b80b396e7d54
interp1.m: Add new methods "previous" and "next" (bug #43377).
Nir Krakauer <nkrakauer@ccny.cuny.edu>
parents:
18642
diff
changeset
|
555 %!assert (interp1 (xp',yp',xp,style), yp, 100*eps) |
b80b396e7d54
interp1.m: Add new methods "previous" and "next" (bug #43377).
Nir Krakauer <nkrakauer@ccny.cuny.edu>
parents:
18642
diff
changeset
|
556 %!assert (isempty (interp1 (xp',yp',[],style))) |
b80b396e7d54
interp1.m: Add new methods "previous" and "next" (bug #43377).
Nir Krakauer <nkrakauer@ccny.cuny.edu>
parents:
18642
diff
changeset
|
557 %!assert (isempty (interp1 (xp,yp,[],style))) |
b80b396e7d54
interp1.m: Add new methods "previous" and "next" (bug #43377).
Nir Krakauer <nkrakauer@ccny.cuny.edu>
parents:
18642
diff
changeset
|
558 %!assert (interp1 (xp,[yp',yp'],xi(:),style),... |
b80b396e7d54
interp1.m: Add new methods "previous" and "next" (bug #43377).
Nir Krakauer <nkrakauer@ccny.cuny.edu>
parents:
18642
diff
changeset
|
559 %! [interp1(xp,yp,xi(:),style),interp1(xp,yp,xi(:),style)]) |
19833
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
560 #%!assert (interp1 (xp,yp,xi,style),... |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
561 #%! interp1 (fliplr (xp),fliplr (yp),xi,style),100*eps) |
19294
b80b396e7d54
interp1.m: Add new methods "previous" and "next" (bug #43377).
Nir Krakauer <nkrakauer@ccny.cuny.edu>
parents:
18642
diff
changeset
|
562 %!assert (ppval (interp1 (xp,yp,style,"pp"),xi), |
b80b396e7d54
interp1.m: Add new methods "previous" and "next" (bug #43377).
Nir Krakauer <nkrakauer@ccny.cuny.edu>
parents:
18642
diff
changeset
|
563 %! interp1 (xp,yp,xi,style,"extrap"),10*eps) |
b80b396e7d54
interp1.m: Add new methods "previous" and "next" (bug #43377).
Nir Krakauer <nkrakauer@ccny.cuny.edu>
parents:
18642
diff
changeset
|
564 %!error interp1 (1,1,1, style) |
b80b396e7d54
interp1.m: Add new methods "previous" and "next" (bug #43377).
Nir Krakauer <nkrakauer@ccny.cuny.edu>
parents:
18642
diff
changeset
|
565 ## ENDBLOCK |
b80b396e7d54
interp1.m: Add new methods "previous" and "next" (bug #43377).
Nir Krakauer <nkrakauer@ccny.cuny.edu>
parents:
18642
diff
changeset
|
566 |
b80b396e7d54
interp1.m: Add new methods "previous" and "next" (bug #43377).
Nir Krakauer <nkrakauer@ccny.cuny.edu>
parents:
18642
diff
changeset
|
567 %!test style = "next"; |
b80b396e7d54
interp1.m: Add new methods "previous" and "next" (bug #43377).
Nir Krakauer <nkrakauer@ccny.cuny.edu>
parents:
18642
diff
changeset
|
568 ## BLOCK |
b80b396e7d54
interp1.m: Add new methods "previous" and "next" (bug #43377).
Nir Krakauer <nkrakauer@ccny.cuny.edu>
parents:
18642
diff
changeset
|
569 %!assert (interp1 (xp, yp, [min(xp)-1, max(xp)+1],style), [NA, NA]) |
b80b396e7d54
interp1.m: Add new methods "previous" and "next" (bug #43377).
Nir Krakauer <nkrakauer@ccny.cuny.edu>
parents:
18642
diff
changeset
|
570 %!assert (interp1 (xp,yp,xp,style), yp, 100*eps) |
b80b396e7d54
interp1.m: Add new methods "previous" and "next" (bug #43377).
Nir Krakauer <nkrakauer@ccny.cuny.edu>
parents:
18642
diff
changeset
|
571 %!assert (interp1 (xp,yp,xp',style), yp', 100*eps) |
b80b396e7d54
interp1.m: Add new methods "previous" and "next" (bug #43377).
Nir Krakauer <nkrakauer@ccny.cuny.edu>
parents:
18642
diff
changeset
|
572 %!assert (interp1 (xp',yp',xp',style), yp', 100*eps) |
b80b396e7d54
interp1.m: Add new methods "previous" and "next" (bug #43377).
Nir Krakauer <nkrakauer@ccny.cuny.edu>
parents:
18642
diff
changeset
|
573 %!assert (interp1 (xp',yp',xp,style), yp, 100*eps) |
b80b396e7d54
interp1.m: Add new methods "previous" and "next" (bug #43377).
Nir Krakauer <nkrakauer@ccny.cuny.edu>
parents:
18642
diff
changeset
|
574 %!assert (isempty (interp1 (xp',yp',[],style))) |
b80b396e7d54
interp1.m: Add new methods "previous" and "next" (bug #43377).
Nir Krakauer <nkrakauer@ccny.cuny.edu>
parents:
18642
diff
changeset
|
575 %!assert (isempty (interp1 (xp,yp,[],style))) |
b80b396e7d54
interp1.m: Add new methods "previous" and "next" (bug #43377).
Nir Krakauer <nkrakauer@ccny.cuny.edu>
parents:
18642
diff
changeset
|
576 %!assert (interp1 (xp,[yp',yp'],xi(:),style),... |
b80b396e7d54
interp1.m: Add new methods "previous" and "next" (bug #43377).
Nir Krakauer <nkrakauer@ccny.cuny.edu>
parents:
18642
diff
changeset
|
577 %! [interp1(xp,yp,xi(:),style),interp1(xp,yp,xi(:),style)]) |
19833
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
578 #%!assert (interp1 (xp,yp,xi,style),... |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
579 #%! interp1 (fliplr (xp),fliplr (yp),xi,style),100*eps) |
19294
b80b396e7d54
interp1.m: Add new methods "previous" and "next" (bug #43377).
Nir Krakauer <nkrakauer@ccny.cuny.edu>
parents:
18642
diff
changeset
|
580 %!assert (ppval (interp1 (xp,yp,style,"pp"),xi), |
b80b396e7d54
interp1.m: Add new methods "previous" and "next" (bug #43377).
Nir Krakauer <nkrakauer@ccny.cuny.edu>
parents:
18642
diff
changeset
|
581 %! interp1 (xp,yp,xi,style,"extrap"),10*eps) |
b80b396e7d54
interp1.m: Add new methods "previous" and "next" (bug #43377).
Nir Krakauer <nkrakauer@ccny.cuny.edu>
parents:
18642
diff
changeset
|
582 %!error interp1 (1,1,1, style) |
b80b396e7d54
interp1.m: Add new methods "previous" and "next" (bug #43377).
Nir Krakauer <nkrakauer@ccny.cuny.edu>
parents:
18642
diff
changeset
|
583 %!assert (interp1 (xp,[yp',yp'],xi,style), |
b80b396e7d54
interp1.m: Add new methods "previous" and "next" (bug #43377).
Nir Krakauer <nkrakauer@ccny.cuny.edu>
parents:
18642
diff
changeset
|
584 %! interp1 (xp,[yp',yp'],xi,["*",style]),100*eps) |
b80b396e7d54
interp1.m: Add new methods "previous" and "next" (bug #43377).
Nir Krakauer <nkrakauer@ccny.cuny.edu>
parents:
18642
diff
changeset
|
585 %!test style = ["*",style]; |
b80b396e7d54
interp1.m: Add new methods "previous" and "next" (bug #43377).
Nir Krakauer <nkrakauer@ccny.cuny.edu>
parents:
18642
diff
changeset
|
586 %!assert (interp1 (xp, yp, [min(xp)-1, max(xp)+1],style), [NA, NA]) |
b80b396e7d54
interp1.m: Add new methods "previous" and "next" (bug #43377).
Nir Krakauer <nkrakauer@ccny.cuny.edu>
parents:
18642
diff
changeset
|
587 %!assert (interp1 (xp,yp,xp,style), yp, 100*eps) |
b80b396e7d54
interp1.m: Add new methods "previous" and "next" (bug #43377).
Nir Krakauer <nkrakauer@ccny.cuny.edu>
parents:
18642
diff
changeset
|
588 %!assert (interp1 (xp,yp,xp',style), yp', 100*eps) |
b80b396e7d54
interp1.m: Add new methods "previous" and "next" (bug #43377).
Nir Krakauer <nkrakauer@ccny.cuny.edu>
parents:
18642
diff
changeset
|
589 %!assert (interp1 (xp',yp',xp',style), yp', 100*eps) |
b80b396e7d54
interp1.m: Add new methods "previous" and "next" (bug #43377).
Nir Krakauer <nkrakauer@ccny.cuny.edu>
parents:
18642
diff
changeset
|
590 %!assert (interp1 (xp',yp',xp,style), yp, 100*eps) |
b80b396e7d54
interp1.m: Add new methods "previous" and "next" (bug #43377).
Nir Krakauer <nkrakauer@ccny.cuny.edu>
parents:
18642
diff
changeset
|
591 %!assert (isempty (interp1 (xp',yp',[],style))) |
b80b396e7d54
interp1.m: Add new methods "previous" and "next" (bug #43377).
Nir Krakauer <nkrakauer@ccny.cuny.edu>
parents:
18642
diff
changeset
|
592 %!assert (isempty (interp1 (xp,yp,[],style))) |
b80b396e7d54
interp1.m: Add new methods "previous" and "next" (bug #43377).
Nir Krakauer <nkrakauer@ccny.cuny.edu>
parents:
18642
diff
changeset
|
593 %!assert (interp1 (xp,[yp',yp'],xi(:),style),... |
b80b396e7d54
interp1.m: Add new methods "previous" and "next" (bug #43377).
Nir Krakauer <nkrakauer@ccny.cuny.edu>
parents:
18642
diff
changeset
|
594 %! [interp1(xp,yp,xi(:),style),interp1(xp,yp,xi(:),style)]) |
19833
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
595 #%!assert (interp1 (xp,yp,xi,style),... |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
596 #%! interp1 (fliplr (xp),fliplr (yp),xi,style),100*eps) |
19294
b80b396e7d54
interp1.m: Add new methods "previous" and "next" (bug #43377).
Nir Krakauer <nkrakauer@ccny.cuny.edu>
parents:
18642
diff
changeset
|
597 %!assert (ppval (interp1 (xp,yp,style,"pp"),xi), |
b80b396e7d54
interp1.m: Add new methods "previous" and "next" (bug #43377).
Nir Krakauer <nkrakauer@ccny.cuny.edu>
parents:
18642
diff
changeset
|
598 %! interp1 (xp,yp,xi,style,"extrap"),10*eps) |
b80b396e7d54
interp1.m: Add new methods "previous" and "next" (bug #43377).
Nir Krakauer <nkrakauer@ccny.cuny.edu>
parents:
18642
diff
changeset
|
599 %!error interp1 (1,1,1, style) |
b80b396e7d54
interp1.m: Add new methods "previous" and "next" (bug #43377).
Nir Krakauer <nkrakauer@ccny.cuny.edu>
parents:
18642
diff
changeset
|
600 ## ENDBLOCK |
b80b396e7d54
interp1.m: Add new methods "previous" and "next" (bug #43377).
Nir Krakauer <nkrakauer@ccny.cuny.edu>
parents:
18642
diff
changeset
|
601 |
14363
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14359
diff
changeset
|
602 %!test style = "linear"; |
6374 | 603 ## BLOCK |
14363
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14359
diff
changeset
|
604 %!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
|
605 %!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
|
606 %!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
|
607 %!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
|
608 %!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
|
609 %!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
|
610 %!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
|
611 %!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
|
612 %! [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
|
613 %!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
|
614 %! 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
|
615 %!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
|
616 %! 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
|
617 %!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
|
618 %!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
|
619 %! 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
|
620 %!test style = ['*',style]; |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14359
diff
changeset
|
621 %!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
|
622 %!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
|
623 %!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
|
624 %!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
|
625 %!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
|
626 %!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
|
627 %!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
|
628 %!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
|
629 %! [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
|
630 %!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
|
631 %! 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
|
632 %!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
|
633 %! interp1 (xp,yp,xi,style,"extrap"),10*eps) |
21317
a4faec57f4c8
maint: remove semicolon after %!assert tests to follow Octave conventions.
Rik <rik@octave.org>
parents:
20852
diff
changeset
|
634 %!assert (interp1 ([1 2 2 3], [1 2 3 4], 2), 3) |
a4faec57f4c8
maint: remove semicolon after %!assert tests to follow Octave conventions.
Rik <rik@octave.org>
parents:
20852
diff
changeset
|
635 %!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
|
636 %!error interp1 (1,1,1, style) |
6374 | 637 ## 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
|
638 |
14363
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14359
diff
changeset
|
639 %!test style = "cubic"; |
6374 | 640 ## BLOCK |
14363
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14359
diff
changeset
|
641 %!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
|
642 %!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
|
643 %!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
|
644 %!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
|
645 %!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
|
646 %!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
|
647 %!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
|
648 %!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
|
649 %! [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
|
650 %!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
|
651 %! 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
|
652 %!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
|
653 %! 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
|
654 %!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
|
655 %!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
|
656 %! 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
|
657 %!test style = ["*",style]; |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14359
diff
changeset
|
658 %!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
|
659 %!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
|
660 %!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
|
661 %!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
|
662 %!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
|
663 %!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
|
664 %!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
|
665 %!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
|
666 %! [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
|
667 %!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
|
668 %! 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
|
669 %!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
|
670 %! 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
|
671 %!error interp1 (1,1,1, style) |
6374 | 672 ## 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
|
673 |
14363
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14359
diff
changeset
|
674 %!test style = "pchip"; |
6374 | 675 ## BLOCK |
14363
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14359
diff
changeset
|
676 %!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
|
677 %!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
|
678 %!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
|
679 %!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
|
680 %!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
|
681 %!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
|
682 %!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
|
683 %!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
|
684 %! [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
|
685 %!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
|
686 %! 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
|
687 %!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
|
688 %! 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
|
689 %!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
|
690 %!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
|
691 %! 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
|
692 %!test style = ["*",style]; |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14359
diff
changeset
|
693 %!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
|
694 %!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
|
695 %!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
|
696 %!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
|
697 %!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
|
698 %!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
|
699 %!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
|
700 %!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
|
701 %! [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
|
702 %!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
|
703 %! 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
|
704 %!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
|
705 %! 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
|
706 %!error interp1 (1,1,1, style) |
6374 | 707 ## 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
|
708 |
14363
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14359
diff
changeset
|
709 %!test style = "spline"; |
6374 | 710 ## BLOCK |
14363
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14359
diff
changeset
|
711 %!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
|
712 %!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
|
713 %!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
|
714 %!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
|
715 %!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
|
716 %!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
|
717 %!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
|
718 %!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
|
719 %! [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
|
720 %!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
|
721 %! 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
|
722 %!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
|
723 %! 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
|
724 %!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
|
725 %!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
|
726 %! 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
|
727 %!test style = ["*",style]; |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14359
diff
changeset
|
728 %!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
|
729 %!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
|
730 %!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
|
731 %!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
|
732 %!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
|
733 %!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
|
734 %!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
|
735 %!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
|
736 %! [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
|
737 %!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
|
738 %! 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
|
739 %!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
|
740 %! 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
|
741 %!error interp1 (1,1,1, style) |
6374 | 742 ## ENDBLOCK |
743 ## ENDBLOCKTEST | |
5837 | 744 |
19294
b80b396e7d54
interp1.m: Add new methods "previous" and "next" (bug #43377).
Nir Krakauer <nkrakauer@ccny.cuny.edu>
parents:
18642
diff
changeset
|
745 ## test extrapolation |
14363
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14359
diff
changeset
|
746 %!assert (interp1 ([1:5],[3:2:11],[0,6],"linear","extrap"), [1, 13], eps) |
19294
b80b396e7d54
interp1.m: Add new methods "previous" and "next" (bug #43377).
Nir Krakauer <nkrakauer@ccny.cuny.edu>
parents:
18642
diff
changeset
|
747 %!assert (interp1 ([1:5],[3:2:11],[0,6],"nearest","extrap"), [3, 11], eps) |
b80b396e7d54
interp1.m: Add new methods "previous" and "next" (bug #43377).
Nir Krakauer <nkrakauer@ccny.cuny.edu>
parents:
18642
diff
changeset
|
748 %!assert (interp1 ([1:5],[3:2:11],[0,6],"previous","extrap"), [3, 11], eps) |
b80b396e7d54
interp1.m: Add new methods "previous" and "next" (bug #43377).
Nir Krakauer <nkrakauer@ccny.cuny.edu>
parents:
18642
diff
changeset
|
749 %!assert (interp1 ([1:5],[3:2:11],[0,6],"next","extrap"), [3, 11], eps) |
14363
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14359
diff
changeset
|
750 %!assert (interp1 (xp, yp, [-1, max(xp)+1],"linear",5), [5, 5]) |
19383
ef649fe230f5
interp1.m: Fix shape of output matrix when there are extrapolated values (bug #43745).
Nir Krakauer <nkrakauer@ccny.cuny.edu>
parents:
18633
diff
changeset
|
751 %!assert (interp1 ([0,1],[1,0],[0.1,0.9;0.2,1.1]), [0.9 0.1; 0.8 NA], eps) |
ef649fe230f5
interp1.m: Fix shape of output matrix when there are extrapolated values (bug #43745).
Nir Krakauer <nkrakauer@ccny.cuny.edu>
parents:
18633
diff
changeset
|
752 %!assert (interp1 ([0,1],[1,0],[0.1,0.9;0.2,1]), [0.9 0.1; 0.8 0], eps) |
5837 | 753 |
18417 | 754 ## Basic sanity checks |
14363
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14359
diff
changeset
|
755 %!assert (interp1 (1:2,1:2,1.4,"nearest"), 1) |
19294
b80b396e7d54
interp1.m: Add new methods "previous" and "next" (bug #43377).
Nir Krakauer <nkrakauer@ccny.cuny.edu>
parents:
18642
diff
changeset
|
756 %!assert (interp1 (1:2,1:2,1.6,"previous"), 1) |
b80b396e7d54
interp1.m: Add new methods "previous" and "next" (bug #43377).
Nir Krakauer <nkrakauer@ccny.cuny.edu>
parents:
18642
diff
changeset
|
757 %!assert (interp1 (1:2,1:2,1.4,"next"), 2) |
14363
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14359
diff
changeset
|
758 %!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
|
759 %!assert (interp1 (1:4,1:4,1.4,"cubic"), 1.4) |
18417 | 760 %!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
|
761 %!assert (interp1 (1:3,1:3,1.4,"spline"), 1.4) |
5837 | 762 |
14363
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14359
diff
changeset
|
763 %!assert (interp1 (1:2:4,1:2:4,1.4,"*nearest"), 1) |
19294
b80b396e7d54
interp1.m: Add new methods "previous" and "next" (bug #43377).
Nir Krakauer <nkrakauer@ccny.cuny.edu>
parents:
18642
diff
changeset
|
764 %!assert (interp1 (1:2:4,1:2:4,2.2,"*previous"), 1) |
b80b396e7d54
interp1.m: Add new methods "previous" and "next" (bug #43377).
Nir Krakauer <nkrakauer@ccny.cuny.edu>
parents:
18642
diff
changeset
|
765 %!assert (interp1 (1:2:4,1:2:4,1.4,"*next"), 3) |
14363
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14359
diff
changeset
|
766 %!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
|
767 %!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
|
768 %!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
|
769 %!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
|
770 |
14363
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14359
diff
changeset
|
771 %!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
|
772 |
12608
59e2460acae1
make piecewise polynomial (pp) functions more compatible
Kai Habel <kai.habel@gmx.de>
parents:
12459
diff
changeset
|
773 %!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
|
774 %!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
|
775 |
18417 | 776 ## Left and Right discontinuities |
18633
5fe907167520
interp1.m: fix function for inputs w/multiple discontinuities (bug #41980).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents:
18418
diff
changeset
|
777 %!assert (interp1 ([1,2,2,3,4],[0,1,4,2,1],[-1,1.5,2,2.5,3.5], "linear", "extrap", "right"), [-2,0.5,4,3,1.5]) |
5fe907167520
interp1.m: fix function for inputs w/multiple discontinuities (bug #41980).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents:
18418
diff
changeset
|
778 %!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,3,1.5]) |
18417 | 779 |
19833
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
780 ## Test input validation |
28896
90fea9cc9caa
test: Add expected error message <Invalid call> to BIST tests for nargin.
Rik <rik@octave.org>
parents:
27984
diff
changeset
|
781 %!error <Invalid call> interp1 () |
90fea9cc9caa
test: Add expected error message <Invalid call> to BIST tests for nargin.
Rik <rik@octave.org>
parents:
27984
diff
changeset
|
782 %!error <Invalid call> interp1 (1) |
90fea9cc9caa
test: Add expected error message <Invalid call> to BIST tests for nargin.
Rik <rik@octave.org>
parents:
27984
diff
changeset
|
783 %!error <Invalid call> interp1 (1,2,3,4,5,6,7) |
18606
0ede4dbb37f1
Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents:
18418
diff
changeset
|
784 %!error <minimum of 2 points required> interp1 (1,1,1, "linear") |
0ede4dbb37f1
Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents:
18418
diff
changeset
|
785 %!error <minimum of 2 points required> interp1 (1,1,1, "*nearest") |
0ede4dbb37f1
Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents:
18418
diff
changeset
|
786 %!error <minimum of 2 points required> interp1 (1,1,1, "*linear") |
19294
b80b396e7d54
interp1.m: Add new methods "previous" and "next" (bug #43377).
Nir Krakauer <nkrakauer@ccny.cuny.edu>
parents:
18642
diff
changeset
|
787 %!error <minimum of 2 points required> interp1 (1,1,1, "previous") |
b80b396e7d54
interp1.m: Add new methods "previous" and "next" (bug #43377).
Nir Krakauer <nkrakauer@ccny.cuny.edu>
parents:
18642
diff
changeset
|
788 %!error <minimum of 2 points required> interp1 (1,1,1, "*previous") |
18418
1ad77b3e6bef
interp1.m: Demote error to warning about multiple discontinuties (bug #41386).
Rik <rik@octave.org>
parents:
18417
diff
changeset
|
789 %!warning <multiple discontinuities> interp1 ([1 1 1 2], [1 2 3 4], 1); |
19294
b80b396e7d54
interp1.m: Add new methods "previous" and "next" (bug #43377).
Nir Krakauer <nkrakauer@ccny.cuny.edu>
parents:
18642
diff
changeset
|
790 %!error <discontinuities not supported> interp1 ([1 1],[1 2],1, "next") |
18417 | 791 %!error <discontinuities not supported> interp1 ([1 1],[1 2],1, "pchip") |
792 %!error <discontinuities not supported> interp1 ([1 1],[1 2],1, "cubic") | |
793 %!error <discontinuities not supported> interp1 ([1 1],[1 2],1, "spline") | |
22765
01aae08a0105
maint: Rename variables to match documentation in m-files.
Rik <rik@octave.org>
parents:
22760
diff
changeset
|
794 %!error <invalid METHOD 'invalid'> interp1 (1:2,1:2,1, "invalid") |