MATLAB Function Reference Previous page   Next Page
spline

Cubic spline data interpolation

Syntax

Description

pp = spline(x,Y) returns the piecewise polynomial form of the cubic spline interpolant for later use with ppval and the spline utility unmkpp. x must be a vector. Y can be a scalar, a vector, or an array of any dimension, subject to the following conditions:

yy = spline(x,Y,xx) is the same as yy = ppval(spline(x,Y),xx), thus providing, in yy, the values of the interpolant at xx. xx can be a scalar, a vector, or a multidimensional array.The sizes of xx and yy are related as follows:

Exceptions

  1. If Y is a vector that contains two more values than x has entries, the first and last value in Y are used as the endslopes for the cubic spline. If Y is a vector, this means
  2. If Y is a matrix or an N-dimensional array with size(Y,N) equal to length(x)+2, the following hold:

Examples

Example 1. This generates a sine curve, then samples the spline over a finer mesh.

Example 2. This illustrates the use of clamped or complete spline interpolation where end slopes are prescribed. Zero slopes at the ends of an interpolant to the values of a certain distribution are enforced.

Example 3. The two vectors

represent the census years from 1900 to 1990 and the corresponding United States population in millions of people. The expression

uses the cubic spline to extrapolate and predict the population in the year 2000. The result is

Example 4. The statements

generate 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.

Example 5. The following code generates sine and cosine curves, then samples the splines over a finer mesh.

Algorithm

A tridiagonal linear system (with, possibly, several right sides) is being solved for the information needed to describe the coefficients of the various cubic polynomials which make up the interpolating spline. spline uses the functions ppval, mkpp, and unmkpp. These routines form a small suite of functions for working with piecewise polynomials. For access to more advanced features, see the M-file help for these functions and the Spline Toolbox.

See Also

interp1, ppval, mkpp, pchip, unmkpp

References

[1]  de Boor, C., A Practical Guide to Splines, Springer-Verlag, 1978.


Previous page  spinmap spones Next page

© 1994-2005 The MathWorks, Inc.