Learn the Lagrange interpolation technique used to construct polynomials that estimate values between known data points.
Lagrange interpolation constructs the unique polynomial of degree at most $n$ that passes exactly through $n + 1$ given points. It is used to estimate values between measurements, construct integration and differentiation formulas, and as the theoretical basis of numerical methods [1].
Given the points $(x_0, y_0), \dots, (x_n, y_n)$ with distinct abscissas, the interpolating polynomial is
$$p(x) = \sum_{i=0}^{n} y_i\,L_i(x), \qquad L_i(x) = \prod_{j \neq i}\frac{x - x_j}{x_i - x_j}.$$
Each basis polynomial $L_i$ equals $1$ at $x_i$ and $0$ at the other nodes, so $p(x_i) = y_i$ (see the row on polynomials and the one on interpolation). The polynomial is unique because the difference of two interpolating polynomials, of degree at most $n$, would have $n + 1$ zeros and would be zero [1][2].
For the points $(1, 2)$, $(2, 3)$, $(4, 7)$ (assumed values) the polynomial is $p(x) = \tfrac{1}{3}x^2 + \tfrac{5}{3}$, as verified: $p(1) = 2$, $p(2) = \tfrac{4}{3} + \tfrac{5}{3} = 3$, $p(4) = \tfrac{16}{3} + \tfrac{5}{3} = 7$. At $x = 3$ it equals $p(3) = 4.667$ (calculation). The same polynomial is written with Newton divided differences: $2 + 1\,(x - 1) + \tfrac{1}{3}(x - 1)(x - 2)$, convenient because adding a point adds a term.
If the points come from a function $f$ differentiable $n + 1$ times, the error is $f(x) - p(x) = \dfrac{f^{(n+1)}(\xi)}{(n + 1)!}\prod_{i}(x - x_i)$ for some $\xi$ in the interval (see the row on Lagrange’s theorem and Taylor’s formula). It depends on the nodes through the product $\prod(x - x_i)$.
Increasing the number of equally spaced nodes does not always improve the approximation. For $f(x) = 1/(1 + 25x^2)$ on $[-1, 1]$ with $11$ equally spaced nodes the maximum error is about $1.92$, with large oscillations at the extremes: at $x = 0.95$ the polynomial equals $1.92$, while $f(0.95) = 0.042$ (calculation). With $11$ Chebyshev nodes, $x_k = \cos\dfrac{(2k + 1)\pi}{22}$, which cluster at the extremes, the maximum error drops to about $0.109$ (calculation).
To compute $p(x)$ with $O(n)$ operations after a preliminary work of $O(n^2)$ the barycentric form is used, stable in finite arithmetic, while the direct Lagrange form costs $O(n^2)$ for each value.
Numerical integration (Newton-Cotes formulas integrate the interpolating polynomial), numerical differentiation, graphics, and cryptography (Shamir’s secret sharing) (general remark). For interpolating many points splines are preferred (see the row on cubic splines).
With many equally spaced nodes interpolation is unstable: errors in the data are amplified. It is not suitable for noisy data, for which least squares are used (see the dedicated row), nor for irregular functions.
[1] Wikipedia (it): Interpolazione di Lagrange
[2] Wikipedia (en): Lagrange polynomial
Generating summary…