Why one polynomial through many equally spaced points can be disastrous, how Chebyshev points and piecewise polynomials fix it, and how a natural cubic spline is built from one tridiagonal system.
Interpolate the smooth bell-shaped on with equally spaced points and one polynomial of degree .
| points | largest error |
|---|---|
| 5 | 0.44 |
| 9 | 1.05 |
| 11 | 1.92 |
| 15 | 7.19 |
| 21 | 59.8 |
Lagrange and divided differences: one polynomial through all the points.
When one polynomial fails, use many small ones joined smoothly.
input x[0..n], y[0..n], X
h[i] ← x[i+1] − x[i]
for i = 1 … n−1: # tridiagonal rows
a[i] ← h[i−1]; c[i] ← h[i]
b[i] ← 2(h[i−1] + h[i])
d[i] ← 6((y[i+1]−y[i])/h[i]
− (y[i]−y[i−1])/h[i−1])
M ← thomas(a, b, c, d); M[0] ← M[n] ← 0
i ← interval containing X
return S_i(X) # formula in step 5Setup once; each evaluation is one interval search and one cubic.
A single polynomial of degree 1000 through equally spaced points is useless: astronomically large swings, and coefficients that cannot even be represented. The spline needs one tridiagonal solve ( operations) and its largest error on Runge's function is .
Rule of thumb: few points → one polynomial (or Chebyshev); many points → cubic spline; noisy points → least squares.
| Method | Largest error () | Largest error () | Smoothness | Setup cost | Choose points? |
|---|---|---|---|---|---|
| Polynomial, equal spacing | 1.92 | 59.8 | but wild | no | |
| Polynomial, Chebyshev points | 0.109 | 0.015 | yes (needed) | ||
| Linear spline | 0.067 | 0.042 | corners () | none | no |
| Natural cubic spline | 0.022 | 0.0032 | tridiagonal | no |
Errors measured on 4001 points in (lab tool). Only the spline gets better steadily with equally spaced data.
We can now fill in values between data points in every common situation. Next we compute with them:
Click a card to see splines at work.
Where exactly: typography and vector graphics (TrueType, PostScript, SVG, PDF). Each glyph outline is a chain of polynomial pieces (quadratic or cubic Bézier curves) joined smoothly, so it can be scaled to any size without pixels.
"Spline" was originally a thin wooden strip that shipbuilders bent through fixed points to draw smooth hull lines.
Where exactly: robotics, drones and animation. Waypoints are given; a cubic spline through them gives positions whose velocity and acceleration (, ) are continuous, so motors and cameras move without jerks.
Switch to "linear" to see the corners a robot would have to stop at; switch to Lagrange to see the swings of one polynomial.
Where exactly: speech and audio processing. Converting a recording from 44.1 kHz to 16 kHz (common for speech models) needs sample values at new, in-between times. Simple converters use cubic interpolation between neighbouring samples; high-quality ones use band-limited (sinc) interpolation.
The same interpolation is used for pitch shifting and time-stretching in speech enhancement and data augmentation.
Where exactly: interpretable machine learning and statistics. A GAM models , where each is a spline; the coefficients are fitted by penalised least squares.
Used in medicine and credit scoring where models must be explainable; pyGAM and R's mgcv implement it.
With 11 equally spaced points the single polynomial has error 1.92; the natural cubic spline has 0.022, and with 21 points 0.003, while the polynomial grows to 60.
Module 5: numerical differentiation. Slopes from tabulated data, by differentiating the interpolation formulas.