annotate scripts/general/interp1.m @ 30564:796f54d4ddbf stable

update Octave Project Developers copyright for the new year In files that have the "Octave Project Developers" copyright notice, update for 2021. In all .txi and .texi files except gpl.txi and gpl.texi in the doc/liboctave and doc/interpreter directories, change the copyright to "Octave Project Developers", the same as used for other source files. Update copyright notices for 2022 (not done since 2019). For gpl.txi and gpl.texi, change the copyright notice to be "Free Software Foundation, Inc." and leave the date at 2007 only because this file only contains the text of the GPL, not anything created by the Octave Project Developers. Add Paul Thomas to contributors.in.
author John W. Eaton <jwe@octave.org>
date Tue, 28 Dec 2021 18:22:40 -0500
parents 8c7685d70cf3
children 79d6280fb00a
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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 ##
30564
796f54d4ddbf update Octave Project Developers copyright for the new year
John W. Eaton <jwe@octave.org>
parents: 29918
diff changeset
3 ## Copyright (C) 2000-2022 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
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
7 ##
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
8 ## This file is part of Octave.
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
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
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
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
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
14 ##
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
15 ## Octave is distributed in the hope that it will be useful, but
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
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
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
19 ##
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
20 ## You should have received a copy of the GNU General Public License
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 7001
diff changeset
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
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
25
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
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
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
34 ##
18417
71d1a1450365 interp1.m: Clean up function
Rik <rik@octave.org>
parents: 18415
diff changeset
35 ## One-dimensional interpolation.
71d1a1450365 interp1.m: Clean up function
Rik <rik@octave.org>
parents: 18415
diff changeset
36 ##
71d1a1450365 interp1.m: Clean up function
Rik <rik@octave.org>
parents: 18415
diff changeset
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
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
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
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
43 ##
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
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
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
67 ## @end table
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
68 ##
18417
71d1a1450365 interp1.m: Clean up function
Rik <rik@octave.org>
parents: 18415
diff changeset
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
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
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
71d1a1450365 interp1.m: Clean up function
Rik <rik@octave.org>
parents: 18415
diff changeset
75 ## beyond the endpoints using the current @var{method}. If @var{extrap} is a
71d1a1450365 interp1.m: Clean up function
Rik <rik@octave.org>
parents: 18415
diff changeset
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
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
78 ##
18417
71d1a1450365 interp1.m: Clean up function
Rik <rik@octave.org>
parents: 18415
diff changeset
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
71d1a1450365 interp1.m: Clean up function
Rik <rik@octave.org>
parents: 18415
diff changeset
81 ## object can later be used with @code{ppval} to evaluate the interpolation.
5837
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
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
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
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
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
98 ## An example of the use of @code{interp1} is
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
99 ##
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
100 ## @example
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
101 ## @group
8507
cadc73247d65 style fixes
John W. Eaton <jwe@octave.org>
parents: 7671
diff changeset
102 ## xf = [0:0.05:10];
cadc73247d65 style fixes
John W. Eaton <jwe@octave.org>
parents: 7671
diff changeset
103 ## yf = sin (2*pi*xf/5);
cadc73247d65 style fixes
John W. Eaton <jwe@octave.org>
parents: 7671
diff changeset
104 ## xp = [0:10];
cadc73247d65 style fixes
John W. Eaton <jwe@octave.org>
parents: 7671
diff changeset
105 ## yp = sin (2*pi*xp/5);
cadc73247d65 style fixes
John W. Eaton <jwe@octave.org>
parents: 7671
diff changeset
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
cadc73247d65 style fixes
John W. Eaton <jwe@octave.org>
parents: 7671
diff changeset
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
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
113 ## @end group
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
114 ## @end example
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
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
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
117 ## @end deftypefn
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
118
5838
376e02b2ce70 [project @ 2006-06-01 20:23:53 by jwe]
jwe
parents: 5837
diff changeset
119 function yi = interp1 (x, y, varargin)
5837
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
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
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
122 print_usage ();
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
123 endif
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
124
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
125 method = "linear";
6742
ebf96cc00ee9 [project @ 2007-06-18 16:27:52 by jwe]
jwe
parents: 6721
diff changeset
126 extrap = NA;
5837
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
127 xi = [];
12608
59e2460acae1 make piecewise polynomial (pp) functions more compatible
Kai Habel <kai.habel@gmx.de>
parents: 12459
diff changeset
128 ispp = false;
29917
09b36aa7088a interp1.m: Don't interpret later numeric input as "xi" (bug #60967).
Markus Mützel <markus.muetzel@gmx.de>
parents: 29358
diff changeset
129 have_xi = false;
18417
71d1a1450365 interp1.m: Clean up function
Rik <rik@octave.org>
parents: 18415
diff changeset
130 rightcontinuous = NaN;
5837
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
131
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
132 if (nargin > 2)
29917
09b36aa7088a interp1.m: Don't interpret later numeric input as "xi" (bug #60967).
Markus Mützel <markus.muetzel@gmx.de>
parents: 29358
diff changeset
133 for i_arg = 1:length (varargin)
09b36aa7088a interp1.m: Don't interpret later numeric input as "xi" (bug #60967).
Markus Mützel <markus.muetzel@gmx.de>
parents: 29358
diff changeset
134 arg = varargin{i_arg};
5838
376e02b2ce70 [project @ 2006-06-01 20:23:53 by jwe]
jwe
parents: 5837
diff changeset
135 if (ischar (arg))
10549
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9929
diff changeset
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
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
149 else
29917
09b36aa7088a interp1.m: Don't interpret later numeric input as "xi" (bug #60967).
Markus Mützel <markus.muetzel@gmx.de>
parents: 29358
diff changeset
150 if (i_arg == 1)
10549
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9929
diff changeset
151 xi = arg;
29917
09b36aa7088a interp1.m: Don't interpret later numeric input as "xi" (bug #60967).
Markus Mützel <markus.muetzel@gmx.de>
parents: 29358
diff changeset
152 have_xi = true;
10549
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9929
diff changeset
153 else
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9929
diff changeset
154 extrap = arg;
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9929
diff changeset
155 endif
5837
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
156 endif
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
157 endfor
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
158 endif
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
159
29917
09b36aa7088a interp1.m: Don't interpret later numeric input as "xi" (bug #60967).
Markus Mützel <markus.muetzel@gmx.de>
parents: 29358
diff changeset
160 if (! have_xi && ! 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
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
170 ## reshape matrices for convenience
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
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
376e02b2ce70 [project @ 2006-06-01 20:23:53 by jwe]
jwe
parents: 5837
diff changeset
175 y = y(:);
5837
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
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
376e02b2ce70 [project @ 2006-06-01 20:23:53 by jwe]
jwe
parents: 5837
diff changeset
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
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
181 xi = xi(:);
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
182
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
183 ## determine sizes
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
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
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
186 endif
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
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
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
192 endif
5838
376e02b2ce70 [project @ 2006-06-01 20:23:53 by jwe]
jwe
parents: 5837
diff changeset
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
71d1a1450365 interp1.m: Clean up function
Rik <rik@octave.org>
parents: 18415
diff changeset
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
71d1a1450365 interp1.m: Clean up function
Rik <rik@octave.org>
parents: 18415
diff changeset
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
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
240 endif
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
241 endif
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
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
71d1a1450365 interp1.m: Clean up function
Rik <rik@octave.org>
parents: 18415
diff changeset
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
71d1a1450365 interp1.m: Clean up function
Rik <rik@octave.org>
parents: 18415
diff changeset
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
71d1a1450365 interp1.m: Clean up function
Rik <rik@octave.org>
parents: 18415
diff changeset
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
71d1a1450365 interp1.m: Clean up function
Rik <rik@octave.org>
parents: 18415
diff changeset
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
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
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
71d1a1450365 interp1.m: Clean up function
Rik <rik@octave.org>
parents: 18415
diff changeset
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
71d1a1450365 interp1.m: Clean up function
Rik <rik@octave.org>
parents: 18415
diff changeset
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
71d1a1450365 interp1.m: Clean up function
Rik <rik@octave.org>
parents: 18415
diff changeset
366
9754
4219e5cf773d improve interp1 and pchip
Jaroslav Hajek <highegg@gmail.com>
parents: 9070
diff changeset
367 endswitch
5837
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
368
18606
0ede4dbb37f1 Overhaul interp1, interp2, interp3 functions.
Rik <rik@octave.org>
parents: 18418
diff changeset
369 if (! ispp && isnumeric (extrap))
18417
71d1a1450365 interp1.m: Clean up function
Rik <rik@octave.org>
parents: 18415
diff changeset
370 ## determine which values are out of range and set them to extrap,
71d1a1450365 interp1.m: Clean up function
Rik <rik@octave.org>
parents: 18415
diff changeset
371 ## unless extrap == "extrap".
71d1a1450365 interp1.m: Clean up function
Rik <rik@octave.org>
parents: 18415
diff changeset
372 minx = min (x(1), x(nx));
71d1a1450365 interp1.m: Clean up function
Rik <rik@octave.org>
parents: 18415
diff changeset
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
71d1a1450365 interp1.m: Clean up function
Rik <rik@octave.org>
parents: 18415
diff changeset
377 if (size_equal (outliers, yi))
71d1a1450365 interp1.m: Clean up function
Rik <rik@octave.org>
parents: 18415
diff changeset
378 yi(outliers) = extrap;
71d1a1450365 interp1.m: Clean up function
Rik <rik@octave.org>
parents: 18415
diff changeset
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
71d1a1450365 interp1.m: Clean up function
Rik <rik@octave.org>
parents: 18415
diff changeset
381 yi(outliers, :) = extrap;
71d1a1450365 interp1.m: Clean up function
Rik <rik@octave.org>
parents: 18415
diff changeset
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
71d1a1450365 interp1.m: Clean up function
Rik <rik@octave.org>
parents: 18415
diff changeset
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
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
387 endif
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
388
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
389 endfunction
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
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
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
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
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
403 %! %--------------------------------------------------------
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
404 %! % confirm that interpolated function matches the original
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
405
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
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
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
417 %! %--------------------------------------------------------
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
418 %! % confirm that interpolated function matches the original
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
419
6721
01036667884a [project @ 2007-06-14 06:56:41 by dbateman]
dbateman
parents: 6702
diff changeset
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
01036667884a [project @ 2007-06-14 06:56:41 by dbateman]
dbateman
parents: 6702
diff changeset
434 %! t = 0 : 0.3 : pi; dt = t(2)-t(1);
01036667884a [project @ 2007-06-14 06:56:41 by dbateman]
dbateman
parents: 6702
diff changeset
435 %! n = length (t); k = 100; dti = dt*n/k;
01036667884a [project @ 2007-06-14 06:56:41 by dbateman]
dbateman
parents: 6702
diff changeset
436 %! ti = t(1) + [0 : k-1]*dti;
01036667884a [project @ 2007-06-14 06:56:41 by dbateman]
dbateman
parents: 6702
diff changeset
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
01036667884a [project @ 2007-06-14 06:56:41 by dbateman]
dbateman
parents: 6702
diff changeset
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
71d1a1450365 interp1.m: Clean up function
Rik <rik@octave.org>
parents: 18415
diff changeset
468 %! legend ([h(1), g(1)], {'left-continuous', 'right-continuous'}, ...
71d1a1450365 interp1.m: Clean up function
Rik <rik@octave.org>
parents: 18415
diff changeset
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
71d1a1450365 interp1.m: Clean up function
Rik <rik@octave.org>
parents: 18415
diff changeset
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
419017274c1e [project @ 2007-03-01 15:57:50 by jwe]
jwe
parents: 6366
diff changeset
476 ## For each type of interpolated test, confirm that the interpolated
419017274c1e [project @ 2007-03-01 15:57:50 by jwe]
jwe
parents: 6366
diff changeset
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
419017274c1e [project @ 2007-03-01 15:57:50 by jwe]
jwe
parents: 6366
diff changeset
479 ## confirm they are the correct values.
419017274c1e [project @ 2007-03-01 15:57:50 by jwe]
jwe
parents: 6366
diff changeset
480
5837
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
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
419017274c1e [project @ 2007-03-01 15:57:50 by jwe]
jwe
parents: 6366
diff changeset
484 %! xi = [-1, 0, 2.2, 4, 6.6, 10, 11];
419017274c1e [project @ 2007-03-01 15:57:50 by jwe]
jwe
parents: 6366
diff changeset
485
419017274c1e [project @ 2007-03-01 15:57:50 by jwe]
jwe
parents: 6366
diff changeset
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
419017274c1e [project @ 2007-03-01 15:57:50 by jwe]
jwe
parents: 6366
diff changeset
488 ## The test for ppval of cubic has looser tolerance, but otherwise
419017274c1e [project @ 2007-03-01 15:57:50 by jwe]
jwe
parents: 6366
diff changeset
489 ## the tests are identical.
419017274c1e [project @ 2007-03-01 15:57:50 by jwe]
jwe
parents: 6366
diff changeset
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
419017274c1e [project @ 2007-03-01 15:57:50 by jwe]
jwe
parents: 6366
diff changeset
492 ## style vs. *style, occurs only in the first section.
419017274c1e [project @ 2007-03-01 15:57:50 by jwe]
jwe
parents: 6366
diff changeset
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
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
495 %!test style = "nearest";
6374
419017274c1e [project @ 2007-03-01 15:57:50 by jwe]
jwe
parents: 6366
diff changeset
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)
29917
09b36aa7088a interp1.m: Don't interpret later numeric input as "xi" (bug #60967).
Markus Mützel <markus.muetzel@gmx.de>
parents: 29358
diff changeset
527 %!assert (interp1 (yp, xi, style, 0), ...
09b36aa7088a interp1.m: Don't interpret later numeric input as "xi" (bug #60967).
Markus Mützel <markus.muetzel@gmx.de>
parents: 29358
diff changeset
528 %! interp1 (1:numel (yp), yp, xi, style, 0), 10*eps)
14363
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14359
diff changeset
529 %!error interp1 (1,1,1, style)
6374
419017274c1e [project @ 2007-03-01 15:57:50 by jwe]
jwe
parents: 6366
diff changeset
530 ## 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
531
19294
b80b396e7d54 interp1.m: Add new methods "previous" and "next" (bug #43377).
Nir Krakauer <nkrakauer@ccny.cuny.edu>
parents: 18642
diff changeset
532 %!test style = "previous";
b80b396e7d54 interp1.m: Add new methods "previous" and "next" (bug #43377).
Nir Krakauer <nkrakauer@ccny.cuny.edu>
parents: 18642
diff changeset
533 ## BLOCK
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, [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
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 (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
538 %!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
539 %!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
540 %!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
541 %!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
542 %! [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
543 ## 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
544 ## "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
545 #%!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
546 #%! 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
547 %!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
548 %! 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
549 %!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
550 %!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
551 %! 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
552 %!test style = ["*",style];
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, [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
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 (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
557 %!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
558 %!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
559 %!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
560 %!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
561 %! [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
562 #%!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
563 #%! 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
564 %!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
565 %! interp1 (xp,yp,xi,style,"extrap"),10*eps)
29917
09b36aa7088a interp1.m: Don't interpret later numeric input as "xi" (bug #60967).
Markus Mützel <markus.muetzel@gmx.de>
parents: 29358
diff changeset
566 %!assert (interp1 (yp, xi, style, 0), ...
09b36aa7088a interp1.m: Don't interpret later numeric input as "xi" (bug #60967).
Markus Mützel <markus.muetzel@gmx.de>
parents: 29358
diff changeset
567 %! interp1 (1:numel (yp), yp, xi, style, 0), 10*eps)
19294
b80b396e7d54 interp1.m: Add new methods "previous" and "next" (bug #43377).
Nir Krakauer <nkrakauer@ccny.cuny.edu>
parents: 18642
diff changeset
568 %!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
569 ## ENDBLOCK
b80b396e7d54 interp1.m: Add new methods "previous" and "next" (bug #43377).
Nir Krakauer <nkrakauer@ccny.cuny.edu>
parents: 18642
diff changeset
570
b80b396e7d54 interp1.m: Add new methods "previous" and "next" (bug #43377).
Nir Krakauer <nkrakauer@ccny.cuny.edu>
parents: 18642
diff changeset
571 %!test style = "next";
b80b396e7d54 interp1.m: Add new methods "previous" and "next" (bug #43377).
Nir Krakauer <nkrakauer@ccny.cuny.edu>
parents: 18642
diff changeset
572 ## BLOCK
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, [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
574 %!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
575 %!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
576 %!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
577 %!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
578 %!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
579 %!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
580 %!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
581 %! [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
582 #%!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
583 #%! 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
584 %!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
585 %! 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
586 %!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
587 %!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
588 %! 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
589 %!test style = ["*",style];
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, [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
591 %!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
592 %!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
593 %!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
594 %!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
595 %!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
596 %!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
597 %!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
598 %! [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
599 #%!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
600 #%! 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
601 %!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
602 %! interp1 (xp,yp,xi,style,"extrap"),10*eps)
29917
09b36aa7088a interp1.m: Don't interpret later numeric input as "xi" (bug #60967).
Markus Mützel <markus.muetzel@gmx.de>
parents: 29358
diff changeset
603 %!assert (interp1 (yp, xi, style, 0), ...
09b36aa7088a interp1.m: Don't interpret later numeric input as "xi" (bug #60967).
Markus Mützel <markus.muetzel@gmx.de>
parents: 29358
diff changeset
604 %! interp1 (1:numel (yp), yp, xi, style, 0), 10*eps)
19294
b80b396e7d54 interp1.m: Add new methods "previous" and "next" (bug #43377).
Nir Krakauer <nkrakauer@ccny.cuny.edu>
parents: 18642
diff changeset
605 %!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
606 ## ENDBLOCK
b80b396e7d54 interp1.m: Add new methods "previous" and "next" (bug #43377).
Nir Krakauer <nkrakauer@ccny.cuny.edu>
parents: 18642
diff changeset
607
14363
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14359
diff changeset
608 %!test style = "linear";
6374
419017274c1e [project @ 2007-03-01 15:57:50 by jwe]
jwe
parents: 6366
diff changeset
609 ## BLOCK
14363
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14359
diff changeset
610 %!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
611 %!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
612 %!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
613 %!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
614 %!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
615 %!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
616 %!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
617 %!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
618 %! [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
619 %!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
620 %! 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
621 %!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
622 %! 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
623 %!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
624 %!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
625 %! 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
626 %!test style = ['*',style];
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14359
diff changeset
627 %!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
628 %!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
629 %!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
630 %!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
631 %!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
632 %!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
633 %!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
634 %!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
635 %! [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
636 %!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
637 %! 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
638 %!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
639 %! interp1 (xp,yp,xi,style,"extrap"),10*eps)
29917
09b36aa7088a interp1.m: Don't interpret later numeric input as "xi" (bug #60967).
Markus Mützel <markus.muetzel@gmx.de>
parents: 29358
diff changeset
640 %!assert (interp1 (yp, xi, style, 0), ...
09b36aa7088a interp1.m: Don't interpret later numeric input as "xi" (bug #60967).
Markus Mützel <markus.muetzel@gmx.de>
parents: 29358
diff changeset
641 %! interp1 (1:numel (yp), yp, xi, style, 0), 10*eps)
21317
a4faec57f4c8 maint: remove semicolon after %!assert tests to follow Octave conventions.
Rik <rik@octave.org>
parents: 20852
diff changeset
642 %!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
643 %!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
644 %!error interp1 (1,1,1, style)
6374
419017274c1e [project @ 2007-03-01 15:57:50 by jwe]
jwe
parents: 6366
diff changeset
645 ## 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
646
14363
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14359
diff changeset
647 %!test style = "cubic";
6374
419017274c1e [project @ 2007-03-01 15:57:50 by jwe]
jwe
parents: 6366
diff changeset
648 ## BLOCK
14363
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14359
diff changeset
649 %!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
650 %!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
651 %!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
652 %!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
653 %!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
654 %!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
655 %!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
656 %!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
657 %! [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
658 %!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
659 %! 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
660 %!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
661 %! 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
662 %!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
663 %!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
664 %! 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
665 %!test style = ["*",style];
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14359
diff changeset
666 %!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
667 %!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
668 %!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
669 %!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
670 %!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
671 %!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
672 %!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
673 %!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
674 %! [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
675 %!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
676 %! 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
677 %!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
678 %! interp1 (xp,yp,xi,style,"extrap"),100*eps)
29917
09b36aa7088a interp1.m: Don't interpret later numeric input as "xi" (bug #60967).
Markus Mützel <markus.muetzel@gmx.de>
parents: 29358
diff changeset
679 %!assert (interp1 (yp, xi, style, 0), ...
09b36aa7088a interp1.m: Don't interpret later numeric input as "xi" (bug #60967).
Markus Mützel <markus.muetzel@gmx.de>
parents: 29358
diff changeset
680 %! interp1 (1:numel (yp), yp, xi, style, 0), 10*eps)
14363
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14359
diff changeset
681 %!error interp1 (1,1,1, style)
6374
419017274c1e [project @ 2007-03-01 15:57:50 by jwe]
jwe
parents: 6366
diff changeset
682 ## 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
683
14363
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14359
diff changeset
684 %!test style = "pchip";
6374
419017274c1e [project @ 2007-03-01 15:57:50 by jwe]
jwe
parents: 6366
diff changeset
685 ## BLOCK
14363
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14359
diff changeset
686 %!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
687 %!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
688 %!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
689 %!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
690 %!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
691 %!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
692 %!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
693 %!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
694 %! [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
695 %!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
696 %! 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
697 %!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
698 %! 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
699 %!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
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',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
702 %!test style = ["*",style];
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14359
diff changeset
703 %!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
704 %!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
705 %!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
706 %!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
707 %!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
708 %!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
709 %!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
710 %!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
711 %! [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
712 %!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
713 %! 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
714 %!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
715 %! interp1 (xp,yp,xi,style,"extrap"),10*eps)
29917
09b36aa7088a interp1.m: Don't interpret later numeric input as "xi" (bug #60967).
Markus Mützel <markus.muetzel@gmx.de>
parents: 29358
diff changeset
716 %!assert (interp1 (yp, xi, style, 0), ...
09b36aa7088a interp1.m: Don't interpret later numeric input as "xi" (bug #60967).
Markus Mützel <markus.muetzel@gmx.de>
parents: 29358
diff changeset
717 %! interp1 (1:numel (yp), yp, xi, style, 0), 10*eps)
14363
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14359
diff changeset
718 %!error interp1 (1,1,1, style)
6374
419017274c1e [project @ 2007-03-01 15:57:50 by jwe]
jwe
parents: 6366
diff changeset
719 ## 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
720
14363
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14359
diff changeset
721 %!test style = "spline";
6374
419017274c1e [project @ 2007-03-01 15:57:50 by jwe]
jwe
parents: 6366
diff changeset
722 ## BLOCK
14363
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14359
diff changeset
723 %!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
724 %!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
725 %!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
726 %!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
727 %!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
728 %!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
729 %!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
730 %!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
731 %! [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
732 %!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
733 %! 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
734 %!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
735 %! 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
736 %!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
737 %!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
738 %! 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
739 %!test style = ["*",style];
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14359
diff changeset
740 %!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
741 %!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
742 %!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
743 %!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
744 %!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
745 %!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
746 %!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
747 %!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
748 %! [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
749 %!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
750 %! 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
751 %!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
752 %! interp1 (xp,yp,xi,style,"extrap"),10*eps)
29917
09b36aa7088a interp1.m: Don't interpret later numeric input as "xi" (bug #60967).
Markus Mützel <markus.muetzel@gmx.de>
parents: 29358
diff changeset
753 %!assert (interp1 (yp, xi, style, 0), ...
09b36aa7088a interp1.m: Don't interpret later numeric input as "xi" (bug #60967).
Markus Mützel <markus.muetzel@gmx.de>
parents: 29358
diff changeset
754 %! interp1 (1:numel (yp), yp, xi, style, 0), 10*eps)
14363
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14359
diff changeset
755 %!error interp1 (1,1,1, style)
6374
419017274c1e [project @ 2007-03-01 15:57:50 by jwe]
jwe
parents: 6366
diff changeset
756 ## ENDBLOCK
419017274c1e [project @ 2007-03-01 15:57:50 by jwe]
jwe
parents: 6366
diff changeset
757 ## ENDBLOCKTEST
5837
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
758
19294
b80b396e7d54 interp1.m: Add new methods "previous" and "next" (bug #43377).
Nir Krakauer <nkrakauer@ccny.cuny.edu>
parents: 18642
diff changeset
759 ## test extrapolation
14363
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14359
diff changeset
760 %!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
761 %!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
762 %!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
763 %!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
764 %!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
765 %!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
766 %!assert (interp1 ([0,1],[1,0],[0.1,0.9;0.2,1]), [0.9 0.1; 0.8 0], eps)
5837
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
767
18417
71d1a1450365 interp1.m: Clean up function
Rik <rik@octave.org>
parents: 18415
diff changeset
768 ## Basic sanity checks
14363
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,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
770 %!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
771 %!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
772 %!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
773 %!assert (interp1 (1:4,1:4,1.4,"cubic"), 1.4)
18417
71d1a1450365 interp1.m: Clean up function
Rik <rik@octave.org>
parents: 18415
diff changeset
774 %!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
775 %!assert (interp1 (1:3,1:3,1.4,"spline"), 1.4)
5837
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
776
14363
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14359
diff changeset
777 %!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
778 %!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
779 %!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
780 %!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
781 %!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
782 %!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
783 %!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
784
14363
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14359
diff changeset
785 %!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
786
12608
59e2460acae1 make piecewise polynomial (pp) functions more compatible
Kai Habel <kai.habel@gmx.de>
parents: 12459
diff changeset
787 %!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
788 %!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
789
18417
71d1a1450365 interp1.m: Clean up function
Rik <rik@octave.org>
parents: 18415
diff changeset
790 ## 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
791 %!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
792 %!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
71d1a1450365 interp1.m: Clean up function
Rik <rik@octave.org>
parents: 18415
diff changeset
793
19833
9fc020886ae9 maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
794 ## 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
795 %!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
796 %!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
797 %!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
798 %!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
799 %!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
800 %!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
801 %!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
802 %!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
803 %!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
804 %!error <discontinuities not supported> interp1 ([1 1],[1 2],1, "next")
18417
71d1a1450365 interp1.m: Clean up function
Rik <rik@octave.org>
parents: 18415
diff changeset
805 %!error <discontinuities not supported> interp1 ([1 1],[1 2],1, "pchip")
71d1a1450365 interp1.m: Clean up function
Rik <rik@octave.org>
parents: 18415
diff changeset
806 %!error <discontinuities not supported> interp1 ([1 1],[1 2],1, "cubic")
71d1a1450365 interp1.m: Clean up function
Rik <rik@octave.org>
parents: 18415
diff changeset
807 %!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
808 %!error <invalid METHOD 'invalid'> interp1 (1:2,1:2,1, "invalid")