Shapes & spaces

PCHIP shape preserving cubic interpolation calculator

Interpolate ordered samples with a continuously differentiable piecewise cubic that preserves local monotonicity and avoids interval overshoot.

Your numbers

Calculated on your device. Your inputs aren’t sent to us.

Your result

Ready when you are

Enter your inputs and select Calculate.

Report an issue

Behind the numbers

How this calculation works

Interpolate ordered samples with a continuously differentiable piecewise cubic that preserves local monotonicity and avoids interval overshoot.

THE FORMULAFor same-sign neighboring secants, (w1+w2)/m_k=w1/d_(k-1)+w2/d_k, with w1=2h_k+h_(k-1), w2=h_k+2h_(k-1). Opposite signs or a zero secant give m_k=0.

A worked example

For (0,0),(1,1),(2,1.5),(3,2), PCHIP at x=1.5 is 1.27083333333333, its derivative is 0.458333333333333, and its integral from 0 to 3 is 3.5625.

Good to know

2–80 strictly increasing real x,y pairs; standard Fritsch–Butland interior weighted harmonic slopes and one-sided limited endpoint slopes. Return piece coefficients, nodal derivatives, value, first derivative, integral and interval extrema. Query only inside data range; reject near-coincident nodes. No smoothing or extrapolation.

Order the observations before interpolation

Enter one x,y pair per row with strictly increasing x coordinates. The y values may increase, decrease or change direction; it is the abscissa sequence that must be ordered and distinct. Duplicate x values with different responses do not define a single-valued interpolating function, while repeated copies of the same observation still create a zero-width interval and should be consolidated deliberately.

The samples are treated as exact interpolation targets. PCHIP passes through every entered point and does not estimate observational noise, confidence bands or a latent smooth trend. If a monotone physical measurement contains noisy reversals, the interpolant will preserve those local reversals rather than repair them. Decide whether interpolation or statistical smoothing fits the purpose before interpreting the drawn curve.

PCHIP follows monotone sample rangesPCHIP: local shape preservedOrdered sample positionillustrative spline
Scroll across to see the full diagram.
The blue PCHIP curve respects adjacent data ranges. The dashed curve illustrates possible spline overshoot.

Compare this with the Natural cubic spline interpolation calculator. Existing natural spline imposes zero endpoint second derivatives and explicitly excludes overshoot prevention. PCHIP derives limited first derivatives from adjacent secants and preserves local monotonicity, with only C1 continuity.

Why local slope selection matters

A cubic Hermite polynomial on an interval is determined by the values and first derivatives at its two endpoints. Unrestricted derivative choices can create an artificial maximum or minimum between monotone samples. PCHIP chooses derivatives from adjacent secant slopes so the interpolated segment follows the local direction without introducing that kind of range overshoot.

At an interior node whose neighboring secants have different signs, the nodal derivative is zero. When the secants share a nonzero sign, a spacing-weighted harmonic mean determines the derivative. This choice gives a small secant substantial influence, which prevents a steep neighbor from forcing a large derivative through a nearly flat interval. Unequal node spacing changes the weights and should not be replaced with a simple arithmetic average.

Use the endpoint convention consistently

The endpoint derivatives use one-sided three-point estimates followed by sign and magnitude limiting. With only two observations, the interpolant reduces to the straight line between them. Endpoint treatment is part of the algorithm, so comparisons against software that uses a different slope convention can differ near the first or last interval even if the central pieces agree.

Each polynomial is conveniently expressed in the local coordinate t=x-x_k. The four coefficients then support direct evaluation, differentiation and exact polynomial integration. PCHIP is continuously differentiable across nodes, but its second derivative can jump. It should therefore not be described as a natural cubic spline or as a curve with globally continuous curvature, and differentiating twice can expose visible changes at sample positions.

Reproduce the default numbers

The default spacings are all one and the successive secants are 1, 0.5 and 0.5. The four nodal slopes are 1.25, two thirds, 0.5 and 0.5. On the middle interval, using t=x-1, the polynomial is 1+(2/3)t-(1/3)t²+(1/6)t³. Substituting t=0.5 gives 61/48, approximately 1.27083333333333.

Differentiating that middle polynomial gives two thirds minus two thirds t plus one half t². At the query this is 11/24, approximately 0.458333333333333. Integrating each of the three local pieces and summing gives 57/16, approximately 3.5625. These checks test values, slopes and integration independently rather than checking only that the curve passes through its nodes.

Interpret interval extrema and the illustration

On every interval, derivative roots can be obtained from a quadratic equation and checked against the interval endpoints. The resulting minima and maxima describe the actual interpolating polynomial, rather than the original unknown process. For monotone adjacent samples the curve remains within their endpoint range; at a reversal the node itself can be a local extremum with zero derivative.

The illustration places sample points on a monotone curve and shows a comparison curve that overshoots between observations. Its purpose is to distinguish derivative construction, not to claim that all ordinary cubic splines always overshoot. Many data sets interpolate safely under several methods. The useful question is whether this specific method guarantees the desired local shape property for the entered observations.

Handle units and numerical spacing

The query and integration endpoints must lie inside the sampled x range. A derivative has response units divided by x units, while an integral has response units multiplied by x units. Changing the horizontal scale therefore changes derivative and integral magnitudes even when the curve looks identical after plotting. Include units when using interpolated values in a later calculation.

Near-coincident nodes can create enormous secants and cancellation when adjacent x coordinates are large. The tool rejects spacing that is not numerically distinguishable at its working scale. Centering or rescaling x can make a well-defined mathematical problem easier to evaluate, but does not justify inventing precision absent from the observations. A rejected spacing should prompt an input review rather than automatic rounding of distinct positions together.

Choose interpolation rather than extrapolation

This page accepts two through eighty nodes and deliberately restricts queries to the data range. Extending an endpoint cubic beyond the observed interval can produce large or implausible values and loses the shape guarantees tied to neighboring samples. A successful interpolation at the last node is not evidence that predictions beyond it are reliable.

Use linear interpolation when piecewise constant slopes are sufficient, a globally smooth spline when curvature continuity is the priority, and a smoothing model when noise must be modeled. PCHIP is especially useful for tabulated monotone responses and lookup curves where unwanted overshoot is unacceptable. It preserves those data-driven shapes while leaving uncertainty, extrapolation and physical-law enforcement to a separate modeling decision.

A few questions, answered

Does PCHIP smooth noisy observations?

No. It interpolates every supplied sample exactly.

Is the second derivative continuous?

Generally no. The first derivative is continuous, while curvature can jump at nodes.

May x values repeat?

No. Distinct increasing x values are required to define nonzero-width intervals.

Can I extrapolate?

This calculator restricts queries and integrals to the supplied data range.

Find your calculator

Start typing to explore the library.