From first principles
Determine a cubic from endpoint values and slopes
On one panel \([a,b]\), approximate a smooth curve with a cubic and use both endpoint heights and slopes. Let \(h=b-a>0\), \(t=(x-a)/h\), endpoint heights \(y_0,y_1\), and derivatives \(d_0,d_1\) with respect to \(x\). The conditions at the left endpoint immediately fix two coefficients,
The factor \(h\) converts a derivative per unit \(x\) into one per unit \(t\). Write \(\Delta=y_1-y_0\). Imposing the right endpoint value and derivative gives two linear equations,
Solving gives
Thus four measurements determine four coefficients uniquely. Adjacent panels sharing heights and slopes join with a continuous first derivative. If only heights are measured, a spline construction supplies the missing information through smoothness conditions between panels and boundary conditions at the ends.
Derivation and applications
Check whether a cubic panel preserves a rising signal
A cubic matching two heights and slopes can overshoot even when both endpoint heights increase. Consider a Hermite panel with \(y_1>y_0\), length \(h\), slope of the chord \(m=(y_1-y_0)/h\), and endpoint derivatives \(d_0,d_1\). The derivative of the cubic is a quadratic. Express that derivative using the nonnegative Bernstein basis on \(0\le t\le1\),
Here \(p'\) is with respect to the physical coordinate \(x\). The first and last coefficients enforce the endpoint derivatives. Each of the three basis functions has integral \(1/3\) over \(t\). Since integrating \(p'(x)\) across the physical panel must return the specified height gain, the middle coefficient is fixed,
Nonnegative coefficients provide a simple sufficient condition for a nondecreasing panel. The basis functions also sum to one, so they immediately bound the derivative when the condition holds,
A negative middle coefficient alone does not prove reversal, since the three basis functions overlap. If the sufficient test fails, evaluate the minimum of the quadratic on the panel, including its endpoints and any interior stationary point. Local monotonicity matters when interpolating cumulative counts or instrument calibrations that must be invertible.
Worked example
Certify a rising calibration between samples
A signal rises from 2 to 5 over \(h=2\), so \(m=1.5\). Reported slopes are \(d_0=1\) and \(d_1=3\), giving \(b=0.5\). The derivative is nonnegative everywhere. At the midpoint it equals
No hidden local maximum can lie inside this panel.
Second application
Find a reversal that endpoint slopes conceal
On a separate unit panel take a rise of one and equal endpoint slopes of four. Then \(m=1\), \(b=3-8=-5\), and the midpoint derivative is
Both measured endpoint derivatives are positive, yet the fitted curve locally decreases. Replacing both slopes by \(1.5\) gives \(b=0\) and restores a certifiably nondecreasing interpolation while preserving the two measured heights.
Four conditions on a single panel
Line segments reproduce values but change slope abruptly at a sensor. A trajectory planner may require a smooth velocity as well as an accurate position. On a panel of width \(h\) let \(s=(x-x_i)/h\). A cubic polynomial has four coefficients. Specifying \(y_i,y_{i+1}\) and slopes \(d_i,d_{i+1}\) determines it uniquely. A convenient basis writes the interpolant as
To reconstruct these terms, seek a cubic multiplying \(y_i\) with value one at \(s=0\), zero at \(s=1\), and zero slope at both ends. The four linear conditions give \(2s^3-3s^2+1\). The other basis functions follow by imposing a unit on their own datum and zero on the remaining three. The factors of \(h\) convert derivatives with respect to physical \(x\) into derivatives with respect to dimensionless \(s\). Dropping these factors would make the interpolant change shape when switching between metres and centimetres.
For positions \(y_0=0,y_1=1\) m over one second with both endpoint velocities zero, \(H=3s^2-2s^3\) m. At half time the position is 0.5 m but the speed is 1.5 m/s, greater than the mean speed of 1 m/s. Imposing rest at both ends forces the intervening speed to exceed the mean somewhere. The piece alone leaves endpoint accelerations \(+6\) and \(-6\) m/s². A smooth join to a subsequent segment therefore needs more than identical endpoint positions.
Recover slopes when only values are measured
A cubic spline fits one cubic on every interval, requiring continuity of both first and second derivatives at interior nodes. Let \(M_i=S''(x_i)\). Since a cubic has a linear second derivative, on panel \(i\) interpolate \(M_i\) and \(M_{i+1}\) linearly and integrate twice. Use the two measured endpoint values to fix the integration constants. On equal panels the resulting right-hand slope at the left endpoint is \((y_{i+1}-y_i)/h-h(2M_i+M_{i+1})/6\). The left-hand slope at the right endpoint is \((y_{i+1}-y_i)/h+h(M_i+2M_{i+1})/6\).
Equating these expressions at an interior join gives
This tridiagonal system relates each undetermined curvature to the neighbouring data. Two additional end conditions are needed. A natural spline imposes zero curvature at both endpoints. A clamped spline uses given endpoint slopes instead. Choose those conditions from what the experiment actually controls.
Examine the influence of endpoint assumptions
Fit a natural spline at \(x=0,1,2\) to \(y=0,1,0\). The end curvatures are zero and the interior equation gives \(4M_1=6(0-2+0)=-12\), hence \(M_1=-3\). On the first panel \(S''=-3x\). Two integrations give
The endpoint values set \(b=0,a=1.5\), yielding \(S(0.5)=0.6875\) compared with 0.5 from the straight chord. Symmetry gives zero slope at the summit and a reflected cubic on the second interval.
Smoothness alone cannot establish the true midpoint value. A sensor measuring a sharp corner would support a piecewise linear description, and monotone data can require a slope limiter to avoid artificial extrema in a cubic fit. Likewise, setting endpoint curvature to zero in a mechanical fit asserts a moment condition only under the appropriate beam model. Report the end conditions with the fitted curve, especially when derivatives near the ends are used as physical observables.
Use independent endpoint information as a check
Suppose the three displacement values in the example come with an independent measurement of the initial slope, \(S'(0)=1\) rather than 1.5. Imposing a natural left endpoint as well as this slope would overdetermine that end. One reasonable choice is a mixed spline, clamped on the left and natural on the right. For \(h=1\), the slope formula at the left reads \(1-(2M_0+M_1)/6=1\), giving \(2M_0+M_1=0\). The interior equation gives \(M_0+4M_1=-12\), since \(M_2=0\).
Solving yields \(M_1=-24/7\) and \(M_0=12/7\). A measured slope at one end has changed curvatures inside the interval. That coupling across segments distinguishes a global spline fit from interpolating each segment independently with prescribed slopes at every node.
Why the natural spline minimises bending
Consider all twice continuously differentiable interpolants of the same tabulated values on an interval. For a natural cubic spline \(S\), each panel is cubic, \(S'\) and \(S''\) agree across knots, and \(S''=0\) at both endpoints. Let a competing interpolant be \(S+w\). The perturbation \(w\) vanishes at every knot including the endpoints. Expanding the squared curvature integral gives
To prove that \(S\) minimises this integral, account for every boundary term in the cross product.
Integrate the cross product by parts twice on each panel. The interior integral containing \(S''''w\) vanishes because the panel is cubic. The term \(S'''w\) vanishes at every panel endpoint since \(w=0\) at each knot. The remaining interface contributions \(S''w'\) cancel between adjacent panels because both factors are continuous. At the outer boundaries \(S''=0\). Thus the cross term vanishes exactly. Equality of the objectives requires \(w''=0\) throughout; a globally affine perturbation vanishing at two distinct knots is zero. This proves uniqueness within the admissible class and explains the natural endpoint condition as part of a variational statement.
Calculate the bending energy on an uneven grid
Suppose the interpolation points are \((0,0),(1,2),(3,2)\). The panel widths are one and two, and the secant slopes are two and zero. For a natural cubic write \(M_i=S''(x_i)\), so
Continuity of first derivative at the central knot gives \(2(1+2)M_1=6(0-2)\), hence \(M_1=-2\). The bending moment changes linearly from zero to −2 on the first panel and from −2 to zero on the second. The longer panel contains twice the squared curvature integral because it sweeps the same range of curvature over twice the distance.
Specifically the first contribution is
On the second panel \(S''=x-3\), giving \(\int_1^3(x-3)^2dx=8/3\). Total energy is four. Integrating the first curvature twice and fitting its endpoints gives
at the central knot the slope is \(4/3\), neither of the adjacent straight-line secant slopes. On the second panel write \(t=x-1\). Then \(S=2+4t/3-t^2+t^3/6\), which returns to two at \(t=2\). The curve rises above the equal second and third data values in between.
Minimum bending therefore does not guarantee monotonicity between nearly flat measurements or an absence of overshoot. If flat endpoints describe a known plateau rather than merely two equal observations, a shape constraint changes the admissible functions. The preceding proof still explains why the natural interpolant won its own curvature competition, but gives no reason to prefer it after physical constraints have changed.
For these data the overshoot can even be located analytically. On the second panel the derivative vanishes when \(4/3-2t+t^2/2=0\), giving the interior root \(t=2-2/\sqrt3\), about 0.845. A measured value taken near \(x=1.845\) would therefore help discriminate the minimum-bending curve from a physical plateau. Taking another measurement at either already constrained endpoint would do less to resolve that ambiguity.
Can an interpolated cumulative reading decrease?
A monotonically increasing quantity is sampled at integer times 0 through 4 with values 0, 0.04, 0.08, 1, 1. A natural spline enforces continuous second derivative and zero end curvature. A shape-preserving cubic constrains the node slopes.

Read values from the plot
| Time (s) | Natural cubic spline | Shape-preserving cubic | Piecewise linear |
|---|---|---|---|
| 0 | 0 | 0 | 0 |
| 1 | 0.04 | 0.04 | 0.04 |
| 2 | 0.08 | 0.08 | 0.08 |
| 3 | 1 | 1 | 1 |
| 4 | 1 | 1 | 1 |
Change parameters · Can an interpolated cumulative reading decrease?
Change one input at a time and compare the recalculated curves with the argument above. The browser evaluates this small model locally; the accompanying numerical values state its assumptions and reference checks. Reset restores the reference inputs, and the data can be downloaded as CSV.