pchip

Shape-preserving piecewise cubic Hermite interpolation.

Category: Mathematics > Interpolation

Syntax

yi = pchip(x, y, xi)

Evaluates the interpolant of (x, y) at the points xi.

pp = pchip(x, y)

Returns the piecewise polynomial structure for use with ppval.

Description

The slope at each sample point is chosen so that the interpolant is monotone wherever the data are monotone: it never overshoots the data, and where a local extremum occurs in the data it is placed at a sample point. The curve is C1 but its second derivative can jump at the points.

Compared with spline, pchip is less smooth and more faithful to the data, which makes it a good choice for values like prices or concentrations that should not ring.

Input arguments

x
Vector of distinct sample points.
y
Sample values at x.
xi
Points at which to evaluate.

Output arguments

yi
Interpolated values.
pp
Piecewise polynomial structure.

Example

Evaluating directly and through a structure

x = 1:5;
y = [1 4 2 5 3];
pchip(x, y, 2.5)
pp = pchip(x, y);
ppval(pp, 3.5)
Output
ans = 3
ans = 3.5000

See also

spline makima interp1 ppval mkpp