MATLAB Function Reference
  Go to function:
    Search    Help Desk 
spline    Examples   See Also

Cubic spline interpolation

Syntax

Description

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

Examples

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

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.


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

See Also

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

References

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



[ Previous | Help Desk | Next ]