Navigation

Operators and Keywords

Function List:

C++ API

: pp = pchip (x, y)
: yi = pchip (x, y, xi)

Return the Piecewise Cubic Hermite Interpolating Polynomial (pchip) of points x and y.

If called with two arguments, return the piecewise polynomial pp that may be used with ppval to evaluate the polynomial at specific points.

When called with a third input argument, pchip evaluates the pchip polynomial at the points xi. The third calling form is equivalent to ppval (pchip (x, y), xi).

The variable x must be a strictly monotonic vector (either increasing or decreasing) of length n.

y can be either a vector or array. If y is a vector then it must be the same length n as x. If y is an array then the size of y must have the form [s1, s2, …, sk, n] The array is reshaped internally to a matrix where the leading dimension is given by s1 * s2 * … * sk and each row of this matrix is then treated separately. Note that this is exactly opposite to interp1 but is done for MATLAB compatibility.

See also: spline, ppval, mkpp, unmkpp.

Demonstration 1

The following code

 x = 0:8;
 y = [1, 1, 1, 1, 0.5, 0, 0, 0, 0];
 xi = 0:0.01:8;
 yspline = spline (x,y,xi);
 ypchip = pchip (x,y,xi);
 title ("pchip and spline fit to discontinuous function");
 plot (xi,yspline, xi,ypchip,"-", x,y,"+");
 legend ("spline", "pchip", "data");
 %-------------------------------------------------------------------
 % confirm that pchip agreed better to discontinuous data than spline

Produces the following figure

Figure 1

Package: octave