Cubic Splines
Cubic splines join cubic pieces with matched first and second derivatives, giving smooth interpolation that avoids high-degree oscillation.
Smooth piecewise cubics
A cubic spline interpolates data with a separate cubic polynomial on each interval between nodes, chosen so the pieces join smoothly. At every interior node the value, first derivative, and second derivative match across the boundary, producing a curve that is continuous through its second derivative and visually smooth.
The system of equations
Matching conditions at n-1 interior points, plus two boundary conditions, determine the piecewise coefficients. Written in terms of the second derivatives at the nodes, the conditions form a tridiagonal linear system that is solved in O(n) time by the Thomas algorithm, making splines efficient even for many points.
Boundary conditions
- Natural: second derivative zero at both ends, the simplest choice.
- Clamped: specified first derivatives at the ends, best when slopes are known.
- Not-a-knot: third derivative continuous across the first and last interior nodes, a good general default.
Why splines beat high-degree polynomials
Because each piece is only cubic, splines do not suffer Runge's phenomenon: adding data refines the fit locally rather than raising a global degree. The result minimizes a bending-energy measure, which is why splines look natural and are used in computer graphics, CAD, and data smoothing.
from scipy.interpolate import CubicSpline
import numpy as np
xs = np.linspace(0, 6, 7)
ys = np.sin(xs)
cs = CubicSpline(xs, ys, bc_type='not-a-knot')
print(cs(2.5), cs(2.5, 1)) # value and first derivative
Splines are the standard tool for interpolating tabulated physics data and reconstructing smooth profiles between grid points in the breeder Hyperion models, where smoothness of derivatives matters for downstream calculations.