Function Reference
— Function File: pp = pchip (x, y)
— Function File: yi = pchip (x, y, xi)

Piecewise Cubic Hermite interpolating polynomial. Called with two arguments, the piece-wise polynomial pp is returned, that may later be used with ppval to evaluate the polynomial at specific points.

The variable x must be a strictly monotonic vector (either increasing or decreasing). While y can be either a vector or array. In the case where y is a vector, it must have a length of n. If y is an array, then the size of y must have the form The array is then reshaped internally to a matrix where the leading dimension is given by and each row in this matrix is then treated separately. Note that this is exactly the opposite treatment than interp1 and is done for compatibility.

Called with a third input argument, pchip evaluates the piece-wise polynomial at the points xi. There is an equivalence between ppval (pchip (x, y), xi) and pchip (x, y, xi).

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