Interpolation when the data are not equally spaced: Lagrange's formula built from basis polynomials, Newton's divided differences that grow one point at a time, inverse interpolation, and why both beat solving for the coefficients.
A data logger was supposed to record every second, but readings at and were lost. We need the value at .
| (s) | 0 | 1 | 2 | 5 |
|---|---|---|---|---|
| 2 | 3 | 12 | 147 |
Newton forward and backward: equal spacing only.
Same polynomial, any spacing: two ways to write it.
input x[0..n], y[0..n], X
sum ← 0
for i = 0 … n:
L ← 1
for j = 0 … n, j ≠ i:
L ← L·(X − x[j]) / (x[i] − x[j])
sum ← sum + y[i]·L
return sumTwo nested loops: work for every new .
input x[0..n], y[0..n], X
c ← copy of y
for k = 1 … n: # build table
for i = n … k:
c[i] ← (c[i] − c[i−1]) / (x[i] − x[i−k])
# c[k] = f[x0, …, xk]
p ← c[n]
for k = n−1 … 0: # Horner
p ← c[k] + (X − x[k])·p
return ponce for the table, then for each .
| first | second | third | fourth (with ) | ||
|---|---|---|---|---|---|
| 0 | 2 | ||||
| 1 | 3 | ||||
| 2 | 12 | ||||
| 5 | 147 | ||||
| 4 | 78 |
, so . The new point adds one entry per column; the fourth divided difference is 0, so the data are a cubic.
The Vandermonde matrix has condition number about (Lecture 11): all 16 digits of double precision can be lost and the coefficients are garbage. Lagrange (in barycentric form) and divided differences never form that matrix and stay accurate.
Rule of thumb: few points, any spacing → divided differences (or barycentric Lagrange); many points → splines; noisy points → least squares.
| Form | Spacing | Setup | Each new | New point | Main use |
|---|---|---|---|---|---|
| Monomial (Vandermonde) | any | solve, ill-conditioned | resolve | avoid | |
| Newton forward/backward | equal | table | one term | tables, hand work | |
| Lagrange | any | none | (barycentric ) | restart (barycentric: update) | theory, few points |
| Divided differences | any | table | one row, one term | irregular data |
All four give the same polynomial through the same points; only cost and rounding differ.
Both methods handle any spacing, but one polynomial through many points behaves badly.
Click a card: each uses the Lagrange or divided-difference formula at a specific step.
Where exactly: cryptography (key management, crypto wallets). The secret is of a random polynomial; each person receives one point. Any 3 points determine the quadratic, and Lagrange at recovers the secret.
Real systems do the same arithmetic modulo a large prime, so the shares reveal nothing about the size of the secret.
Where exactly: error-correcting codes in QR codes, CDs, DVDs, deep-space links and RAID storage. The message is the coefficients of a polynomial; the stored data are its values at many points. Lost values are rebuilt by interpolation from the surviving ones.
A QR code with level H error correction survives about 30% damage.
Where exactly: sensor fusion (phones, drones, wearables). The accelerometer and the GPS report at different, irregular times; to combine them, each signal is interpolated to common time stamps.
Here the samples are of at irregular times; the estimate at is compared with the true value. Low degree (3–4 points around ) is the safe choice.
Where exactly: numerical integration (Lecture 20). Interpolate at , , by the Lagrange quadratic and integrate it exactly: the weights are the integrals of the .
Every Newton–Cotes and Gauss rule is built this way: interpolate, then integrate the interpolant.
by Lagrange and by divided differences; adding the recovered reading needed one new row, and its zero fourth divided difference showed the data are a cubic.
Splines and the Runge phenomenon. Why one polynomial through many points fails, and how piecewise cubics fix it.