spline
Cubic spline interpolation.
Category: Mathematics > Interpolation
Syntax
yi = spline(x, y, xi)
Evaluates the not-a-knot cubic spline through (x, y) at xi.
pp = spline(x, y)
Returns the piecewise polynomial structure.
Description
A cubic spline is made of cubic pieces that join with continuous value, slope and curvature. With the default not-a-knot condition, the first two pieces share one cubic, and so do the last two. For this reason data that come from a cubic polynomial are reproduced exactly.
Giving two extra values in y selects the clamped condition instead, with the given slopes at the ends. Splines can oscillate between points when the data change abruptly; pchip and makima are alternatives for that case.
Input arguments
x- Vector of distinct sample points.
y- Sample values. If
yhas two more entries thanx, the first and last are the end slopes of a clamped spline. xi- Points at which to evaluate.
Output arguments
yi- Interpolated values.
pp- Piecewise polynomial structure, usable with
ppval.
Example
Reproducing a cubic and inspecting the pieces
x = 0:4;
y = x.^3;
spline(x, y, 2.5)
pp = spline(x, y);
pp.pieces
Output
ans = 15.6250
ans = 4