comparison main/splines/spline.m @ 0:6b33357c7561 octave-forge

Initial revision
author pkienzle
date Wed, 10 Oct 2001 19:54:49 +0000
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:6b33357c7561
1 ## Copyright (C) 2000 Kai Habel
2 ##
3 ## This program is free software; you can redistribute it and/or modify
4 ## it under the terms of the GNU General Public License as published by
5 ## the Free Software Foundation; either version 2 of the License, or
6 ## (at your option) any later version.
7 ##
8 ## This program is distributed in the hope that it will be useful,
9 ## but WITHOUT ANY WARRANTY; without even the implied warranty of
10 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 ## GNU General Public License for more details.
12 ##
13 ## You should have received a copy of the GNU General Public License
14 ## along with this program; if not, write to the Free Software
15 ## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16
17 ## -*- texinfo -*-
18 ## @deftypefn {Function File} {@var{pp} = } spline (@var{x}, @var{y})
19 ## @deftypefnx {Function File} {@var{yi} = } spline (@var{x}, @var{y}, @var{xi})
20 ## cubic spline interpolation
21 ##
22 ## @seealso{ppval, csapi, csape}
23 ## @end deftypefn
24
25
26 ## Author: Kai Habel <kai.habel@gmx.de>
27 ## Date: 3. dec 2000
28 ## 2001-02-08 Paul Kienzle
29 ## * copied from csapi.m
30
31 function ret = spline (x, y, xi)
32
33 ret = csape (x, y, 'not-a-knot');
34
35 if (nargin == 3)
36 ret = ppval (ret, xi);
37 endif
38
39 endfunction
40
41 %!demo
42 %! x = 0:10; y = sin(x);
43 %! xspline = 0:0.1:10; yspline = spline(x,y,xspline);
44 %! title("spline fit to points from sin(x)");
45 %! plot(xspline,sin(xspline),";original;",...
46 %! xspline,yspline,"-;interpolation;",...
47 %! x,y,"+;interpolation points;");
48 %! %--------------------------------------------------------
49 %! % confirm that interpolated function matches the original
50
51 %!shared x,y
52 %! x = [0:10]'; y = sin(x);
53 %!assert (spline(x,y,x), y);
54 %!assert (spline(x,y,x'), y');
55 %!assert (spline(x',y',x'), y');
56 %!assert (spline(x',y',x), y);
57 %!assert (isempty(spline(x',y',[])));
58 %!assert (isempty(spline(x,y,[])));
59 %!assert (spline(x,[y,y],x), [spline(x,y,x),spline(x,y,x)])