Mercurial > hg > octave-nkf
annotate scripts/polynomial/spline.m @ 12174:db1f49eaba6b
whitespace fixes
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Wed, 26 Jan 2011 23:49:42 -0500 |
parents | c792872f8942 |
children | 07e102029d2a |
rev | line source |
---|---|
11523 | 1 ## Copyright (C) 2000-2011 Kai Habel |
5824 | 2 ## Copyright (C) 2006 David Bateman |
3 ## | |
4 ## This file is part of Octave. | |
5 ## | |
6 ## Octave is free software; you can redistribute it and/or modify it | |
7 ## under the terms of the GNU General Public License as published by | |
7016 | 8 ## the Free Software Foundation; either version 3 of the License, or (at |
9 ## your option) any later version. | |
5824 | 10 ## |
11 ## Octave is distributed in the hope that it will be useful, but | |
12 ## WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
14 ## General Public License for more details. | |
15 ## | |
16 ## You should have received a copy of the GNU General Public License | |
7016 | 17 ## along with Octave; see the file COPYING. If not, see |
18 ## <http://www.gnu.org/licenses/>. | |
5824 | 19 |
20 ## -*- texinfo -*- | |
10793
be55736a0783
Grammarcheck the documentation from m-files.
Rik <octave@nomad.inbox5.com>
parents:
10658
diff
changeset
|
21 ## @deftypefn {Function File} {@var{pp} =} spline (@var{x}, @var{y}) |
7650 | 22 ## @deftypefnx {Function File} {@var{yi} =} spline (@var{x}, @var{y}, @var{xi}) |
5824 | 23 ## |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11536
diff
changeset
|
24 ## Return the cubic spline interpolant of @var{y} at points @var{x}. |
11536
702dbd0c53f5
Add undocumented ppder, ppint, ppjumps functions to documentation.
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
25 ## If called with two arguments, @code{spline} returns the piecewise |
8602 | 26 ## polynomial @var{pp} that may later be used with @code{ppval} to |
27 ## evaluate the polynomial at specific points. | |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11536
diff
changeset
|
28 ## If called with a third input argument, @code{spline} evaluates the |
9051
1bf0ce0930be
Grammar check TexInfo in all .m files
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
29 ## spline at the points @var{xi}. There is an equivalence |
8602 | 30 ## between @code{ppval (spline (@var{x}, @var{y}), @var{xi})} and |
31 ## @code{spline (@var{x}, @var{y}, @var{xi})}. | |
5824 | 32 ## |
33 ## The variable @var{x} must be a vector of length @var{n}, and @var{y} | |
9051
1bf0ce0930be
Grammar check TexInfo in all .m files
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
34 ## can be either a vector or array. In the case where @var{y} is a |
5824 | 35 ## vector, it can have a length of either @var{n} or @code{@var{n} + 2}. |
36 ## If the length of @var{y} is @var{n}, then the 'not-a-knot' end | |
9051
1bf0ce0930be
Grammar check TexInfo in all .m files
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
37 ## condition is used. If the length of @var{y} is @code{@var{n} + 2}, |
8602 | 38 ## then the first and last values of the vector @var{y} are the values |
39 ## of the first derivative of the cubic spline at the end-points. | |
5824 | 40 ## |
41 ## If @var{y} is an array, then the size of @var{y} must have the form | |
42 ## @tex | |
43 ## $$[s_1, s_2, \cdots, s_k, n]$$ | |
44 ## @end tex | |
8517
81d6ab3ac93c
Allow documentation tobe built for other formats than tex and info
sh@sh-laptop
parents:
8310
diff
changeset
|
45 ## @ifnottex |
5824 | 46 ## @code{[@var{s1}, @var{s2}, @dots{}, @var{sk}, @var{n}]} |
8517
81d6ab3ac93c
Allow documentation tobe built for other formats than tex and info
sh@sh-laptop
parents:
8310
diff
changeset
|
47 ## @end ifnottex |
5824 | 48 ## or |
49 ## @tex | |
8828 | 50 ## $$[s_1, s_2, \cdots, s_k, n + 2].$$ |
5824 | 51 ## @end tex |
8517
81d6ab3ac93c
Allow documentation tobe built for other formats than tex and info
sh@sh-laptop
parents:
8310
diff
changeset
|
52 ## @ifnottex |
5824 | 53 ## @code{[@var{s1}, @var{s2}, @dots{}, @var{sk}, @var{n} + 2]}. |
8517
81d6ab3ac93c
Allow documentation tobe built for other formats than tex and info
sh@sh-laptop
parents:
8310
diff
changeset
|
54 ## @end ifnottex |
8602 | 55 ## The array is then reshaped internally to a matrix where the leading |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11536
diff
changeset
|
56 ## dimension is given by |
5824 | 57 ## @tex |
58 ## $$s_1 s_2 \cdots s_k$$ | |
59 ## @end tex | |
8517
81d6ab3ac93c
Allow documentation tobe built for other formats than tex and info
sh@sh-laptop
parents:
8310
diff
changeset
|
60 ## @ifnottex |
5824 | 61 ## @code{@var{s1} * @var{s2} * @dots{} * @var{sk}} |
8517
81d6ab3ac93c
Allow documentation tobe built for other formats than tex and info
sh@sh-laptop
parents:
8310
diff
changeset
|
62 ## @end ifnottex |
9051
1bf0ce0930be
Grammar check TexInfo in all .m files
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
63 ## and each row of this matrix is then treated separately. Note that this |
5824 | 64 ## is exactly the opposite treatment than @code{interp1} and is done |
7001 | 65 ## for compatibility. |
5824 | 66 ## @seealso{ppval, mkpp, unmkpp} |
67 ## @end deftypefn | |
68 | |
69 ## This code is based on csape.m from octave-forge, but has been | |
70 ## modified to use the sparse solver code in octave that itself allows | |
71 ## special casing of tri-diagonal matrices, modified for NDArrays and | |
72 ## for the treatment of vectors y 2 elements longer than x as complete | |
73 ## splines. | |
74 | |
75 function ret = spline (x, y, xi) | |
76 | |
77 x = x(:); | |
78 n = length (x); | |
79 if (n < 3) | |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11536
diff
changeset
|
80 error ("spline: requires at least 3 points"); |
5824 | 81 endif |
82 | |
83 ## Check the size and shape of y | |
84 ndy = ndims (y); | |
85 szy = size (y); | |
86 if (ndy == 2 && (szy(1) == 1 || szy(2) == 1)) | |
87 if (szy(1) == 1) | |
6014 | 88 a = y.'; |
5824 | 89 else |
90 a = y; | |
91 szy = fliplr (szy); | |
92 endif | |
93 else | |
6014 | 94 a = reshape (y, [prod(szy(1:end-1)), szy(end)]).'; |
5824 | 95 endif |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11536
diff
changeset
|
96 |
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11536
diff
changeset
|
97 for k = (1:columns (a))(any (isnan (a))) |
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11536
diff
changeset
|
98 ok = ! isnan (a(:,k)); |
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11536
diff
changeset
|
99 a(!ok,k) = spline (x(ok), a(ok,k), x(!ok)); |
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11536
diff
changeset
|
100 endfor |
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11536
diff
changeset
|
101 |
5824 | 102 complete = false; |
103 if (size (a, 1) == n + 2) | |
104 complete = true; | |
105 dfs = a(1,:); | |
106 dfe = a(end,:); | |
107 a = a(2:end-1,:); | |
108 endif | |
109 | |
110 b = c = zeros (size (a)); | |
111 h = diff (x); | |
5838 | 112 idx = ones (columns (a), 1); |
5824 | 113 |
114 if (complete) | |
115 | |
116 if (n == 3) | |
117 dg = 1.5 * h(1) - 0.5 * h(2); | |
5838 | 118 c(2:n-1,:) = 1/dg(1); |
5824 | 119 else |
5838 | 120 dg = 2 * (h(1:n-2) .+ h(2:n-1)); |
5824 | 121 dg(1) = dg(1) - 0.5 * h(1); |
5838 | 122 dg(n-2) = dg(n-2) - 0.5 * h(n-1); |
5824 | 123 |
5838 | 124 e = h(2:n-2); |
5824 | 125 |
5838 | 126 g = 3 * diff (a(2:n,:)) ./ h(2:n-1,idx) ... |
127 - 3 * diff (a(1:n-1,:)) ./ h(1:n-2,idx); | |
128 g(1,:) = 3 * (a(3,:) - a(2,:)) / h(2) ... | |
5824 | 129 - 3 / 2 * (3 * (a(2,:) - a(1,:)) / h(1) - dfs); |
5838 | 130 g(n-2,:) = 3 / 2 * (3 * (a(n,:) - a(n-1,:)) / h(n-1) - dfe) ... |
131 - 3 * (a(n-1,:) - a(n-2,:)) / h(n-2); | |
5824 | 132 |
5838 | 133 c(2:n-1,:) = spdiags ([[e(:); 0], dg, [0; e(:)]], |
10549 | 134 [-1, 0, 1], n-2, n-2) \ g; |
5824 | 135 endif |
136 | |
137 c(1,:) = (3 / h(1) * (a(2,:) - a(1,:)) - 3 * dfs | |
10549 | 138 - c(2,:) * h(1)) / (2 * h(1)); |
5838 | 139 c(n,:) = - (3 / h(n-1) * (a(n,:) - a(n-1,:)) - 3 * dfe |
10549 | 140 + c(n-1,:) * h(n-1)) / (2 * h(n-1)); |
5838 | 141 b(1:n-1,:) = diff (a) ./ h(1:n-1, idx) ... |
10549 | 142 - h(1:n-1,idx) / 3 .* (c(2:n,:) + 2 * c(1:n-1,:)); |
5838 | 143 d = diff (c) ./ (3 * h(1:n-1, idx)); |
5824 | 144 |
145 else | |
146 | |
11196
d17cb8a1271d
spline.m: Fix algorithm for input with 3 elements (bug #31098)
Marco Caliari <marco.caliari@univr.it>
parents:
10793
diff
changeset
|
147 if (n == 3) |
5824 | 148 |
11196
d17cb8a1271d
spline.m: Fix algorithm for input with 3 elements (bug #31098)
Marco Caliari <marco.caliari@univr.it>
parents:
10793
diff
changeset
|
149 n = 2; |
d17cb8a1271d
spline.m: Fix algorithm for input with 3 elements (bug #31098)
Marco Caliari <marco.caliari@univr.it>
parents:
10793
diff
changeset
|
150 c = (a(1,:) - a(3,:)) / ((x(3) - x(1)) * (x(2) - x(3))) ... |
d17cb8a1271d
spline.m: Fix algorithm for input with 3 elements (bug #31098)
Marco Caliari <marco.caliari@univr.it>
parents:
10793
diff
changeset
|
151 + (a(2,:) - a(1,:)) / ((x(2) - x(1)) * (x(2) - x(3))); |
d17cb8a1271d
spline.m: Fix algorithm for input with 3 elements (bug #31098)
Marco Caliari <marco.caliari@univr.it>
parents:
10793
diff
changeset
|
152 b = (a(2,:) - a(1,:)) * (x(3) - x(1)) ... |
d17cb8a1271d
spline.m: Fix algorithm for input with 3 elements (bug #31098)
Marco Caliari <marco.caliari@univr.it>
parents:
10793
diff
changeset
|
153 / ((x(2) - x(1)) * (x(3) - x(2))) ... |
d17cb8a1271d
spline.m: Fix algorithm for input with 3 elements (bug #31098)
Marco Caliari <marco.caliari@univr.it>
parents:
10793
diff
changeset
|
154 + (a(1,:) - a(3,:)) * (x(2) - x(1)) ... |
d17cb8a1271d
spline.m: Fix algorithm for input with 3 elements (bug #31098)
Marco Caliari <marco.caliari@univr.it>
parents:
10793
diff
changeset
|
155 / ((x(3) - x(1)) * (x(3) - x(2))); |
d17cb8a1271d
spline.m: Fix algorithm for input with 3 elements (bug #31098)
Marco Caliari <marco.caliari@univr.it>
parents:
10793
diff
changeset
|
156 a = a(1,:); |
d17cb8a1271d
spline.m: Fix algorithm for input with 3 elements (bug #31098)
Marco Caliari <marco.caliari@univr.it>
parents:
10793
diff
changeset
|
157 d = zeros (size (a)); |
d17cb8a1271d
spline.m: Fix algorithm for input with 3 elements (bug #31098)
Marco Caliari <marco.caliari@univr.it>
parents:
10793
diff
changeset
|
158 x = [min(x), max(x)]; |
d17cb8a1271d
spline.m: Fix algorithm for input with 3 elements (bug #31098)
Marco Caliari <marco.caliari@univr.it>
parents:
10793
diff
changeset
|
159 |
d17cb8a1271d
spline.m: Fix algorithm for input with 3 elements (bug #31098)
Marco Caliari <marco.caliari@univr.it>
parents:
10793
diff
changeset
|
160 else |
5824 | 161 |
11196
d17cb8a1271d
spline.m: Fix algorithm for input with 3 elements (bug #31098)
Marco Caliari <marco.caliari@univr.it>
parents:
10793
diff
changeset
|
162 g = zeros (n-2, columns (a)); |
d17cb8a1271d
spline.m: Fix algorithm for input with 3 elements (bug #31098)
Marco Caliari <marco.caliari@univr.it>
parents:
10793
diff
changeset
|
163 g(1,:) = 3 / (h(1) + h(2)) ... |
d17cb8a1271d
spline.m: Fix algorithm for input with 3 elements (bug #31098)
Marco Caliari <marco.caliari@univr.it>
parents:
10793
diff
changeset
|
164 * (a(3,:) - a(2,:) - h(2) / h(1) * (a(2,:) - a(1,:))); |
d17cb8a1271d
spline.m: Fix algorithm for input with 3 elements (bug #31098)
Marco Caliari <marco.caliari@univr.it>
parents:
10793
diff
changeset
|
165 g(n-2,:) = 3 / (h(n-1) + h(n-2)) ... |
d17cb8a1271d
spline.m: Fix algorithm for input with 3 elements (bug #31098)
Marco Caliari <marco.caliari@univr.it>
parents:
10793
diff
changeset
|
166 * (h(n-2) / h(n-1) * (a(n,:) - a(n-1,:)) - (a(n-1,:) - a(n-2,:))); |
d17cb8a1271d
spline.m: Fix algorithm for input with 3 elements (bug #31098)
Marco Caliari <marco.caliari@univr.it>
parents:
10793
diff
changeset
|
167 |
d17cb8a1271d
spline.m: Fix algorithm for input with 3 elements (bug #31098)
Marco Caliari <marco.caliari@univr.it>
parents:
10793
diff
changeset
|
168 if (n > 4) |
5824 | 169 |
11196
d17cb8a1271d
spline.m: Fix algorithm for input with 3 elements (bug #31098)
Marco Caliari <marco.caliari@univr.it>
parents:
10793
diff
changeset
|
170 g(2:n - 3,:) = 3 * diff (a(3:n-1,:)) ./ h(3:n-2,idx) ... |
d17cb8a1271d
spline.m: Fix algorithm for input with 3 elements (bug #31098)
Marco Caliari <marco.caliari@univr.it>
parents:
10793
diff
changeset
|
171 - 3 * diff (a(2:n-2,:)) ./ h(2:n - 3,idx); |
5824 | 172 |
11196
d17cb8a1271d
spline.m: Fix algorithm for input with 3 elements (bug #31098)
Marco Caliari <marco.caliari@univr.it>
parents:
10793
diff
changeset
|
173 dg = 2 * (h(1:n-2) .+ h(2:n-1)); |
d17cb8a1271d
spline.m: Fix algorithm for input with 3 elements (bug #31098)
Marco Caliari <marco.caliari@univr.it>
parents:
10793
diff
changeset
|
174 dg(1) = dg(1) - h(1); |
d17cb8a1271d
spline.m: Fix algorithm for input with 3 elements (bug #31098)
Marco Caliari <marco.caliari@univr.it>
parents:
10793
diff
changeset
|
175 dg(n-2) = dg(n-2) - h(n-1); |
d17cb8a1271d
spline.m: Fix algorithm for input with 3 elements (bug #31098)
Marco Caliari <marco.caliari@univr.it>
parents:
10793
diff
changeset
|
176 |
d17cb8a1271d
spline.m: Fix algorithm for input with 3 elements (bug #31098)
Marco Caliari <marco.caliari@univr.it>
parents:
10793
diff
changeset
|
177 ldg = udg = h(2:n-2); |
d17cb8a1271d
spline.m: Fix algorithm for input with 3 elements (bug #31098)
Marco Caliari <marco.caliari@univr.it>
parents:
10793
diff
changeset
|
178 udg(1) = udg(1) - h(1); |
d17cb8a1271d
spline.m: Fix algorithm for input with 3 elements (bug #31098)
Marco Caliari <marco.caliari@univr.it>
parents:
10793
diff
changeset
|
179 ldg(n - 3) = ldg(n-3) - h(n-1); |
d17cb8a1271d
spline.m: Fix algorithm for input with 3 elements (bug #31098)
Marco Caliari <marco.caliari@univr.it>
parents:
10793
diff
changeset
|
180 c(2:n-1,:) = spdiags ([[ldg(:); 0], dg, [0; udg(:)]], |
10549 | 181 [-1, 0, 1], n-2, n-2) \ g; |
5824 | 182 |
11196
d17cb8a1271d
spline.m: Fix algorithm for input with 3 elements (bug #31098)
Marco Caliari <marco.caliari@univr.it>
parents:
10793
diff
changeset
|
183 elseif (n == 4) |
d17cb8a1271d
spline.m: Fix algorithm for input with 3 elements (bug #31098)
Marco Caliari <marco.caliari@univr.it>
parents:
10793
diff
changeset
|
184 |
d17cb8a1271d
spline.m: Fix algorithm for input with 3 elements (bug #31098)
Marco Caliari <marco.caliari@univr.it>
parents:
10793
diff
changeset
|
185 dg = [h(1) + 2 * h(2); 2 * h(2) + h(3)]; |
d17cb8a1271d
spline.m: Fix algorithm for input with 3 elements (bug #31098)
Marco Caliari <marco.caliari@univr.it>
parents:
10793
diff
changeset
|
186 ldg = h(2) - h(3); |
d17cb8a1271d
spline.m: Fix algorithm for input with 3 elements (bug #31098)
Marco Caliari <marco.caliari@univr.it>
parents:
10793
diff
changeset
|
187 udg = h(2) - h(1); |
d17cb8a1271d
spline.m: Fix algorithm for input with 3 elements (bug #31098)
Marco Caliari <marco.caliari@univr.it>
parents:
10793
diff
changeset
|
188 c(2:n-1,:) = spdiags ([[ldg(:);0], dg, [0; udg(:)]], |
d17cb8a1271d
spline.m: Fix algorithm for input with 3 elements (bug #31098)
Marco Caliari <marco.caliari@univr.it>
parents:
10793
diff
changeset
|
189 [-1, 0, 1], n-2, n-2) \ g; |
5824 | 190 |
11196
d17cb8a1271d
spline.m: Fix algorithm for input with 3 elements (bug #31098)
Marco Caliari <marco.caliari@univr.it>
parents:
10793
diff
changeset
|
191 endif |
d17cb8a1271d
spline.m: Fix algorithm for input with 3 elements (bug #31098)
Marco Caliari <marco.caliari@univr.it>
parents:
10793
diff
changeset
|
192 |
d17cb8a1271d
spline.m: Fix algorithm for input with 3 elements (bug #31098)
Marco Caliari <marco.caliari@univr.it>
parents:
10793
diff
changeset
|
193 c(1,:) = c(2,:) + h(1) / h(2) * (c(2,:) - c(3,:)); |
d17cb8a1271d
spline.m: Fix algorithm for input with 3 elements (bug #31098)
Marco Caliari <marco.caliari@univr.it>
parents:
10793
diff
changeset
|
194 c(n,:) = c(n-1,:) + h(n-1) / h(n-2) * (c(n-1,:) - c(n-2,:)); |
d17cb8a1271d
spline.m: Fix algorithm for input with 3 elements (bug #31098)
Marco Caliari <marco.caliari@univr.it>
parents:
10793
diff
changeset
|
195 b = diff (a) ./ h(1:n-1, idx) ... |
d17cb8a1271d
spline.m: Fix algorithm for input with 3 elements (bug #31098)
Marco Caliari <marco.caliari@univr.it>
parents:
10793
diff
changeset
|
196 - h(1:n-1, idx) / 3 .* (c(2:n,:) + 2 * c(1:n-1,:)); |
d17cb8a1271d
spline.m: Fix algorithm for input with 3 elements (bug #31098)
Marco Caliari <marco.caliari@univr.it>
parents:
10793
diff
changeset
|
197 d = diff (c) ./ (3 * h(1:n-1, idx)); |
5824 | 198 |
199 endif | |
200 | |
201 endif | |
202 | |
5838 | 203 d = d(1:n-1,:); |
204 c = c(1:n-1,:); | |
205 b = b(1:n-1,:); | |
206 a = a(1:n-1,:); | |
9768
31900e17b5f5
improve Matlab compatibility & performance of ppval/mkpp and some associated funcs
Jaroslav Hajek <highegg@gmail.com>
parents:
9211
diff
changeset
|
207 coeffs = cat (3, d.', c.', b.', a.'); |
5824 | 208 ret = mkpp (x, coeffs, szy(1:end-1)); |
209 | |
210 if (nargin == 3) | |
211 ret = ppval (ret, xi); | |
212 endif | |
213 | |
214 endfunction | |
215 | |
216 %!demo | |
217 %! x = 0:10; y = sin(x); | |
218 %! xspline = 0:0.1:10; yspline = spline(x,y,xspline); | |
219 %! title("spline fit to points from sin(x)"); | |
6702 | 220 %! plot(xspline,sin(xspline),"r",xspline,yspline,"g-",x,y,"b+"); |
221 %! legend("original","interpolation","interpolation points"); | |
5824 | 222 %! %-------------------------------------------------------- |
223 %! % confirm that interpolated function matches the original | |
224 | |
6686 | 225 %!shared x,y,abserr |
226 %! x = [0:10]; y = sin(x); abserr = 1e-14; | |
227 %!assert (spline(x,y,x), y, abserr); | |
228 %!assert (spline(x,y,x'), y', abserr); | |
229 %!assert (spline(x',y',x'), y', abserr); | |
230 %!assert (spline(x',y',x), y, abserr); | |
5824 | 231 %!assert (isempty(spline(x',y',[]))); |
232 %!assert (isempty(spline(x,y,[]))); | |
6686 | 233 %!assert (spline(x,[y;y],x), [spline(x,y,x);spline(x,y,x)],abserr) |
6014 | 234 %! y = cos(x) + i*sin(x); |
6686 | 235 %!assert (spline(x,y,x), y, abserr) |
236 %!assert (real(spline(x,y,x)), real(y), abserr); | |
237 %!assert (real(spline(x,y,x.')), real(y).', abserr); | |
238 %!assert (real(spline(x.',y.',x.')), real(y).', abserr); | |
239 %!assert (real(spline(x.',y,x)), real(y), abserr); | |
240 %!assert (imag(spline(x,y,x)), imag(y), abserr); | |
241 %!assert (imag(spline(x,y,x.')), imag(y).', abserr); | |
242 %!assert (imag(spline(x.',y.',x.')), imag(y).', abserr); | |
243 %!assert (imag(spline(x.',y,x)), imag(y), abserr); | |
10658
c66a4657d764
spline.m: Ignore NaNs within input vectors.
Ben Abbott <bpabbott@mac.com>
parents:
10549
diff
changeset
|
244 %!test |
c66a4657d764
spline.m: Ignore NaNs within input vectors.
Ben Abbott <bpabbott@mac.com>
parents:
10549
diff
changeset
|
245 %! xnan = 5; |
c66a4657d764
spline.m: Ignore NaNs within input vectors.
Ben Abbott <bpabbott@mac.com>
parents:
10549
diff
changeset
|
246 %! y(x==xnan) = NaN; |
c66a4657d764
spline.m: Ignore NaNs within input vectors.
Ben Abbott <bpabbott@mac.com>
parents:
10549
diff
changeset
|
247 %! ok = ! isnan (y); |
c66a4657d764
spline.m: Ignore NaNs within input vectors.
Ben Abbott <bpabbott@mac.com>
parents:
10549
diff
changeset
|
248 %! assert (spline (x, y, x(ok)), y(ok), abserr); |
c66a4657d764
spline.m: Ignore NaNs within input vectors.
Ben Abbott <bpabbott@mac.com>
parents:
10549
diff
changeset
|
249 %!test |
c66a4657d764
spline.m: Ignore NaNs within input vectors.
Ben Abbott <bpabbott@mac.com>
parents:
10549
diff
changeset
|
250 %! ok = ! isnan (y); |
c66a4657d764
spline.m: Ignore NaNs within input vectors.
Ben Abbott <bpabbott@mac.com>
parents:
10549
diff
changeset
|
251 %! assert (! isnan (spline (x, y, x(!ok)))); |