Interpolation & Function Approximation

a cubic spline

Draftsmen once drew smooth curves through points by bending a thin flexible strip of wood or metal — a 'spline' — held in place by weights at the data points. The strip naturally settles into the smoothest possible shape. A cubic spline is the mathematical version of that strip: a curve made of cubic polynomial pieces, joined so smoothly that the seams are invisible.

Between each pair of neighbouring nodes you use a different cubic polynomial. You then stitch them together with three conditions at every interior node: the pieces must MEET (continuous value), have the same SLOPE (continuous first derivative), and the same CURVATURE (continuous second derivative). Matching values, slopes, AND curvatures is what makes a cubic spline look perfectly smooth to the eye, unlike the corners of a piecewise-linear fit. These matching conditions, plus passing through all the data, form a system with two leftover degrees of freedom, fixed by an end condition: a NATURAL spline sets the second derivative to zero at both ends (it straightens out, like the free ends of the wooden strip); a CLAMPED spline instead fixes the slope at each end to a prescribed value. The whole system reduces to a TRIDIAGONAL linear system in the unknown second derivatives, solved in O(n) time by the Thomas algorithm — fast even for many points.

Cubic splines are the default smooth interpolant across science and graphics, and for a deep reason: among ALL twice-differentiable functions through the data, the natural cubic spline is the one that minimizes the total bending energy (the integral of (f'')^2) — it is provably the 'least wiggly' interpolant, the exact mathematical echo of the relaxed wooden strip. Crucially, because each piece is low-degree and local, splines do NOT suffer Runge's phenomenon and never blow up as you add points. The honest caveat: splines can still overshoot slightly between widely varying points (they are not guaranteed monotone), and if your data is meant to be monotone or shape-constrained you may want a monotone (Hermite) variant instead.

Fit a natural cubic spline through (0, 0), (1, 1), (2, 0), (3, 1). It produces a smooth wavy curve hitting all four points; the second derivative is forced to zero at x = 0 and x = 3, while value, slope, and curvature all match continuously at the interior knots x = 1 and x = 2 — no visible corner anywhere.

Cubic pieces matched in value, slope, and curvature: invisibly smooth.

A 'natural' spline minimizes bending energy but its zero-curvature end condition is artificial and degrades accuracy near the ends; if you know the true end slopes, a 'clamped' spline is more accurate. Splines also do not guarantee monotonicity — they can overshoot.

Also called
cubic spline interpolationnatural splineclamped spline三次雲形線三次樣條插值