MATLAB Function Reference    
spline

Cubic spline data interpolation

Syntax

Description

yy = spline(x,y,xx) uses cubic spline interpolation to find yy, the values of the underlying function y at the points in the vector xx. The vector x specifies the points at which the data y is given. If y is a matrix, then the data is taken to be vector-valued and interpolation is performed for each row of y. For this case, length(x) must equal size(y,2), and yy is size(y,1)-by-length(xx).

pp = spline(x,y) returns the piecewise polynomial form of the cubic spline interpolant for later use with ppval and the spline utility unmkpp.

Ordinarily, the not-a-knot end conditions are used. However, if y contains two more values than x has entries, then the first and last value in y are used as the endslopes for the cubic spline. Namely:

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.

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, unmkpp

References

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


  spinmap spones