MATLAB Function Reference | Search  Help Desk |
spline | Examples See Also |
yy = spline(xThe,
y,
xx) pp = spline(x,
y)
spline
function constructs a spline function which takes the value y(:,j)
at the point x(j)
, all j
. In particular, the given values may be vectors, in which case the spline function describes a curve that passes through the point sequence y(:,1),y(:,2), ...
.
yy = spline(x,y,xx)
returns the value at xx
of the interpolating cubic spline. If xx
is a refinement of the mesh x
, then yy
provides a corresponding refinement of y
.
pp = spline(x,y)
returns the pp-form of the cubic spline interpolant, for later use with ppval
(and with functions available in the Spline Toolbox).
Ordinarily, the `not-a-knot' end conditions are used. However, if y
contains exactly two more values than x
has entries, then y(:,1)
and y(:,end)
are used as the endslopes for the cubic spline.
The two vectors
t = 1900:10:1990; p = [ 75.995 91.972 105.711 123.203 131.669 ... 150.697 179.323 203.212 226.505 249.633 ];represent the census years from 1900 to 1990 and the corresponding United States population in millions of people. The expression
spline(tuses the cubic spline to extrapolate and predict the population in the year 2000. The result is,
p,
2000)
ans = 270.6060The statements
x = pi*[0:.5:2]; y = [0 1 0 -1 0 1 0; 1 0 1 0 -1 0 1]; pp = spline(x,y); yy = ppval(pp, linspace(0,2*pi,101)); plot(yy(1,:),yy(2,:),'-b',y(1,2:5),y(2,2:5),'or'), axis equalgenerate the plot of a circle, with the five data points
y(:,2),...,y(:,6)
marked with o's. Note that this y
contains two more values (i.e., two more columns) than does x
, hence y(:,1)
and y(:,end)
are used as endslopes. spline
uses the functions ppval
, mkpp
, and unmkpp
. These routines form a small suite of functions for working with piecewise polynomials. spline
uses these functions in a fairly simple fashion to perform cubic spline interpolation. For access to the more advanced features, see the on-line help for these M-files and the Spline Toolbox.
interp1
One-dimensional data interpolation (table lookup)
interp2
Two-dimensional data interpolation (table lookup)
interp3
Three-dimensional data interpolation (table lookup)
interpn
Multidimensional data interpolation (table lookup)
ppval
Evaluate piecewise polynomial