Spline Interpolation: Cubic Splines Explained Simply
A spline is a smooth curve through data points built from a different low-degree polynomial on each interval, joined so smoothly you cannot see the seams. A cubic spline uses cubic pieces matching values, slopes, and curvatures at every joint (knot) — like the flexible drafting strip engineers once bent through pins to draw ship hulls.
Single high-degree polynomials through many points oscillate badly (the Runge phenomenon), while straight-line joins look kinked. Cubic splines give the best of both: they pass through every point, stay smooth, and wiggle as little as possible — the natural cubic spline is the smoothest interpolant in a precise energy-minimizing sense.
Key Concepts
- Knot: a data point (x_i, y_i) where two polynomial pieces meet.
- Cubic piece: on [x_i, x_i+1] the spline is S_i(x) = a_i + b_i(x − x_i) + c_i(x − x_i)² + d_i(x − x_i)³.
- Smoothness conditions: at each interior knot, pieces share value, slope, and curvature (second derivative).
- Natural spline: the second derivative is set to zero at both endpoints, meaning the curve straightens out at the ends — the most common default choice.
Formulas
- Second-derivative form: with M_i = S″(x_i), each piece is S_i(x) = M_i(x_i+1 − x)³/(6h_i) + M_i+1(x − x_i)³/(6h_i) + (y_i − M_ih_i²/6)(x_i+1 − x)/h_i + (y_i+1 − M_i+1h_i²/6)(x − x_i)/h_i, where h_i = x_i+1 − x_i.
- Tridiagonal system: the smoothness conditions give one linear equation per interior knot linking M_i−1, M_i, M_i+1 — solvable in linear time.
- Natural boundary conditions: M₀ = 0 and M_n = 0, which close the system.
Worked Example
Build the natural cubic spline through (0, 0), (1, 1), (2, 4) with spacing h = 1. Natural conditions: M₀ = M₂ = 0. The interior equation: 4M₁ = 6[(4 − 1) − (1 − 0)] = 12, so M₁ = 3. On [0, 1]: S₀(x) = 3x³/6 + (1 − 3/6)x = 0.5x³ + 0.5x. On [1, 2] with t = x − 1: S₁(x) = 0.5(1 − t)³ + 0.5(1 − t) + 4t. Checks: S₀(1) = S₁(1) = 1 (values match); S₁(2) = 4 (endpoint matches); slopes S₀′(1) = 1.5 + 0.5 = 2 and S₁′(0) = −1.5 − 0.5 + 4 = 2 (slopes match). The join is perfectly smooth.
Common Misconceptions
- "A spline is one big polynomial." It is piecewise — a different cubic on each interval. That is precisely why it avoids the wild oscillations of a single high-degree polynomial.
- "Splines only approximate the data points." An interpolating spline passes through every point exactly; the smoothness is in how it travels between them.
- "The natural spline is always the best choice." It is a good default, but if you know the endpoint slopes, a clamped spline (prescribed first derivatives at the ends) is more accurate there.
Real-World Applications
- Computer-aided design: car bodies and aircraft wings are shaped with spline surfaces.
- Font rendering: the curves of every letter on your screen are spline-based outlines.
- Animation: camera paths and character motion are smoothed with splines between keyframes.
- Geography: elevation maps interpolate scattered survey measurements with splines.
Cubic splines join piecewise cubics with matching value, slope, and curvature at every knot, giving a curve that passes through all data points with minimal wiggle. The natural spline sets the endpoint curvatures to zero, and the whole construction reduces to one efficient tridiagonal solve.
Related blogs
- Floating Point Arithmetic and Error Analysis: Notes and FAQs
- Truncation and Round-Off Errors: Numerical Error Basics
- Bisection Method: Explained with Examples, Notes and FAQs
- Fixed Point Iteration: Concepts, Formulas and Examples
- Newton-Raphson Method Explained: Root Finding Made Simple
- Secant and Regula Falsi Methods: Root Finding Guide