MathLabs

Applied and computational mathematics

Interpolation and approximation

Constructing a function that passes through given data points, or approximates a complicated one closely.

IntuitionIntuition: connecting the dots with a curve

A weather station records the temperature at a handful of times during the day, a sensor reports a few discrete measurements, or an engineer has a table of just a few tabulated values — in every case you have a finite list of points (x0,y0),(x1,y1),…,(xn,yn)(x_0,y_0), (x_1,y_1), \dots, (x_n,y_n) and you want to guess the value in between, or draw a smooth curve through all of them. Interpolation is the art of constructing a function that passes through every one of these points exactly, while approximation more broadly looks for a function that stays close to a complicated one without necessarily matching it point for point.

A cubic curve threading exactly through four marked data points, with sliders for each of its four coefficients.
This cubic P(x)=x3−x2−2x+2P(x)=x^3-x^2-2x+2 is the unique polynomial of degree at most 33 passing through the four points (−1,2)(-1,2), (0,2)(0,2), (1,0)(1,0) and (2,2)(2,2): drag a,b,c,da,b,c,d and watch how just four coefficients are exactly enough to pin down a curve through four data points — the essence of polynomial interpolation.

UndergraduateDefinition: the interpolation problem

Definition: Polynomial interpolation

Given n+1n+1 distinct nodes x0,x1,…,xnx_0, x_1, \dots, x_n and values y0,y1,…,yny_0, y_1, \dots, y_n (typically yi=f(xi)y_i=f(x_i) for some function ff), the interpolation problem asks for a polynomial PP of degree at most nn with P(xi)=yiP(x_i)=y_i for every ii. The Lagrange basis polynomials LiL_i give an explicit construction.

Li(x)=∏j≠ix−xjxi−xjL_i(x) = \prod_{j \ne i} \dfrac{x - x_j}{x_i - x_j}

Each basis polynomial LiL_i is built to vanish at every other node and equal 11 at its own node: plugging in x=xjx=x_j with j≠ij\ne i makes the numerator's factor (xj−xj)=0(x_j-x_j)=0, giving Li(xj)=0L_i(x_j)=0, while plugging in x=xix=x_i makes numerator and denominator identical, giving Li(xi)=1L_i(x_i)=1. Summing these building blocks weighted by the target values gives the interpolating polynomial directly.

P(x)=∑i=0nyi Li(x)P(x) = \sum_{i=0}^{n} y_i\, L_i(x)
Comparing interpolation and approximation methods
MethodIdeaSmoothness across nodesWeakness
LagrangeSingle polynomial P(x)=∑iyiLi(x)P(x)=\sum_i y_i L_i(x) through all nodesInfinitely smooth (it is one polynomial)High degree with equispaced nodes oscillates wildly (Runge's phenomenon)
Newton divided differencesSame polynomial as Lagrange, built incrementally node by nodeInfinitely smooth (same polynomial)Adding a node is cheap, but suffers the same high-degree oscillation
Natural cubic splinePiecewise cubic, one cubic per subinterval, joined smoothlyC2C^2 (continuous up to the second derivative)No single global formula; must solve a linear system for the pieces

UndergraduateKey theorems

Given n+1n+1 distinct nodes x0,x1,…,xnx_0, x_1, \dots, x_n and values y0,y1,…,yny_0, y_1, \dots, y_n, there exists exactly one polynomial PP of degree at most nn such that P(xi)=yiP(x_i)=y_i for every i=0,…,ni=0,\dots,n.

Why is it true?

A degree-n polynomial has exactly n+1 free coefficients, and pinning down n+1 point values uses up exactly that many degrees of freedom — no more, no less — so there is room for one solution and no room for two different ones.

Proof

Step 1 (existence). The Lagrange construction P(x)=∑i=0nyiLi(x)P(x) = \sum_{i=0}^{n} y_i L_i(x) with Li(x)=∏j≠ix−xjxi−xjL_i(x) = \prod_{j\ne i} \dfrac{x-x_j}{x_i-x_j} already satisfies P(xk)=ykP(x_k)=y_k for every kk, since Li(xk)L_i(x_k) equals 11 when i=ki=k and 00 otherwise, so the sum collapses to the single term yk⋅1=yky_k \cdot 1 = y_k. So at least one valid PP exists, and each LiL_i has degree exactly nn (a product of nn linear factors), so PP has degree at most nn.

Step 2 (suppose two solutions). Suppose QQ is any other polynomial of degree at most nn with Q(xi)=yiQ(x_i)=y_i for every ii. Consider the difference D(x)=P(x)−Q(x)D(x) = P(x) - Q(x). Since both PP and QQ have degree at most nn, so does DD.

Step 3 (count the roots of the difference). For every node xix_i, D(xi)=P(xi)−Q(xi)=yi−yi=0D(x_i) = P(x_i)-Q(x_i) = y_i - y_i = 0. Since there are n+1n+1 distinct nodes x0,x1,…,xnx_0, x_1, \dots, x_n, DD has at least n+1n+1 distinct roots.

Step 4 (force D to be identically zero). A nonzero polynomial of degree at most nn can have at most nn roots (each root contributes one linear factor, and a degree-nn polynomial cannot contain more than nn such factors). Since DD has n+1n+1 roots, more than its degree allows unless DD is the zero polynomial, we conclude D(x)≡0D(x)\equiv0, i.e. Q=PQ=P. So the interpolating polynomial found in Step 1 is the only one.

Let ff be (n+1)(n+1)-times continuously differentiable on an interval containing distinct nodes x0,x1,…,xnx_0, x_1, \dots, x_n and a point xx, and let PP be the degree-nn polynomial interpolating ff at these nodes. Then there exists ξ\xi in that interval such that f(x)−P(x)=f(n+1)(ξ)(n+1)!∏i=0n(x−xi)f(x) - P(x) = \dfrac{f^{(n+1)}(\xi)}{(n+1)!} \prod_{i=0}^{n} (x - x_i).

Why is it true?

The interpolating polynomial matches f exactly at the nodes but knows nothing about f in between, so the leftover error must vanish at every node — exactly what the product term forces — scaled by a leftover derivative that measures how much f curves beyond what a degree-n polynomial can capture.

Proof

Step 1 (a clever auxiliary function). Fix a point xx that is not one of the nodes (if it is, the error is trivially 00). Let w(t)=∏i=0n(t−xi)w(t) = \prod_{i=0}^{n} (t - x_i) and define the constant c=f(x)−P(x)w(x)c = \dfrac{f(x)-P(x)}{w(x)} (well-defined since w(x)≠0w(x)\ne0). Define the auxiliary function g(t)=f(t)−P(t)−c w(t)g(t) = f(t) - P(t) - c\, w(t).

Step 2 (count the roots of g). At every node xix_i, both f(xi)−P(xi)=0f(x_i)-P(x_i)=0 (by the interpolation property) and w(xi)=0w(x_i)=0 (by definition of ww), so g(xi)=0g(x_i)=0 for all n+1n+1 nodes. Also, by the choice of cc, g(x)=f(x)−P(x)−c w(x)=f(x)−P(x)−[f(x)−P(x)]=0g(x) = f(x)-P(x) - c\,w(x) = f(x)-P(x) - [f(x)-P(x)] = 0. So gg has n+2n+2 distinct roots: the n+1n+1 nodes plus xx itself.

Step 3 (apply Rolle's theorem repeatedly). Between each pair of consecutive roots of gg (there are n+1n+1 such gaps among n+2n+2 roots), Rolle's theorem gives a point where g′g' vanishes, so g′g' has at least n+1n+1 roots. Repeating this argument on g′,g′′,…g', g'', \dots loses one root each time a derivative is taken, so after n+1n+1 applications, g(n+1)g^{(n+1)} has at least one root ξ\xi in the interval.

Step 4 (differentiate and solve for the error). Since PP has degree at most nn, its (n+1)(n+1)-th derivative is 00; and ww is a monic polynomial of degree n+1n+1, so w(n+1)(t)=(n+1)!w^{(n+1)}(t) = (n+1)! for every tt. Differentiating gg gives g(n+1)(t)=f(n+1)(t)−0−c (n+1)!g^{(n+1)}(t) = f^{(n+1)}(t) - 0 - c\,(n+1)!, and setting g(n+1)(ξ)=0g^{(n+1)}(\xi)=0 gives c=f(n+1)(ξ)(n+1)!c = \dfrac{f^{(n+1)}(\xi)}{(n+1)!}. Recalling c=f(x)−P(x)w(x)c=\dfrac{f(x)-P(x)}{w(x)} and solving for the error gives exactly f(x)−P(x)=f(n+1)(ξ)(n+1)!∏i=0n(x−xi)f(x) - P(x) = \dfrac{f^{(n+1)}(\xi)}{(n+1)!} \prod_{i=0}^{n} (x - x_i).

Given n+1n+1 points (x0,y0),…,(xn,yn)(x_0,y_0),\dots,(x_n,y_n) with x0<x1<⋯<xnx_0<x_1<\dots<x_n, there exists a unique function SS that is a cubic polynomial on each subinterval [xi,xi+1][x_i,x_{i+1}], is twice continuously differentiable on all of [x0,xn][x_0,x_n], satisfies S(xi)=yiS(x_i)=y_i for every ii, and satisfies the natural boundary conditions S′′(x0)=S′′(xn)=0S''(x_0)=S''(x_n)=0.

Why is it true?

A single high-degree polynomial through many points tends to wiggle, but stitching together many gentle cubic pieces and only demanding they match up smoothly at the seams gives just enough freedom to fit the data without any wild swings, and the natural boundary conditions supply exactly the two extra equations needed to make the whole system solvable.

Proof

Step 1 (unknowns: the second derivatives at the knots). Let Mi=S′′(xi)M_i = S''(x_i) for i=0,…,ni=0,\dots,n. The natural boundary conditions fix M0=0M_0=0 and Mn=0M_n=0 immediately, leaving n−1n-1 unknowns M1,…,Mn−1M_1,\dots,M_{n-1} to determine.

Step 2 (reconstruct each cubic piece from its M values). On [xi,xi+1][x_i,x_{i+1}], since SS is cubic, S′′S'' is linear, so it must be the straight line through (xi,Mi)(x_i,M_i) and (xi+1,Mi+1)(x_{i+1},M_{i+1}). Integrating this linear function twice and fixing the two constants of integration using S(xi)=yiS(x_i)=y_i and S(xi+1)=yi+1S(x_{i+1})=y_{i+1} determines SS completely on that piece, in terms of Mi,Mi+1,yi,yi+1M_i, M_{i+1}, y_i, y_{i+1} and the spacing hi=xi+1−xih_i=x_{i+1}-x_i. So once all the MiM_i are known, SS is fully known.

Step 3 (matching slopes gives a linear system). By construction SS and S′′S'' are already continuous across each knot. Demanding that the first derivative S′S' also matches from both sides at each interior knot xix_i (i=1,…,n−1i=1,\dots,n-1) produces one linear equation per interior knot relating three consecutive unknowns: hi−1Mi−1+2(hi−1+hi)Mi+hiMi+1=6(yi+1−yihi−yi−yi−1hi−1)h_{i-1} M_{i-1} + 2(h_{i-1}+h_i) M_i + h_i M_{i+1} = 6\left(\dfrac{y_{i+1}-y_i}{h_i} - \dfrac{y_i-y_{i-1}}{h_{i-1}}\right). This gives n−1n-1 linear equations in the n−1n-1 unknowns M1,…,Mn−1M_1,\dots,M_{n-1} (using M0=Mn=0M_0=M_n=0).

Step 4 (the system has a unique solution). The coefficient matrix of this system is tridiagonal with diagonal entries 2(hi−1+hi)2(h_{i-1}+h_i) and off-diagonal entries hi−1h_{i-1} and hih_i; since 2(hi−1+hi)>hi−1+hi2(h_{i-1}+h_i) > h_{i-1}+h_i (as all spacings hi>0h_i>0), the matrix is strictly diagonally dominant, and a strictly diagonally dominant matrix is always invertible. So the linear system for M1,…,Mn−1M_1,\dots,M_{n-1} has exactly one solution, and by Step 2 this determines exactly one spline SS, proving both existence and uniqueness.

UndergraduateReal-World Applications and Worked Examples

Interpolation is everywhere data is sampled but a continuous curve is needed: computer fonts and animation paths are drawn with splines, GPS receivers interpolate a handful of satellite readings into a smooth trajectory, image and audio resampling interpolate between pixels or samples when resizing or changing playback speed, and engineers interpolate sparse tables of material properties or thermodynamic data measured only at a few temperatures or pressures. Financial analysts interpolate a yield curve from bond prices observed only at a few maturities to price instruments that mature in between.

Example: Predicting a trend from three measurements with Lagrange interpolation

A lab records three measurements (0,1)(0,1), (1,3)(1,3), (2,7)(2,7). Using the Lagrange interpolating polynomial through these three points, estimate the value at x=3x=3.

Solution

Step 1: write the three basis polynomials evaluated at x=3x=3. With nodes x0=0,x1=1,x2=2x_0=0,x_1=1,x_2=2: L0(3)=(3−1)(3−2)(0−1)(0−2)=22=1L_0(3)=\dfrac{(3-1)(3-2)}{(0-1)(0-2)}=\dfrac{2}{2}=1, L1(3)=(3−0)(3−2)(1−0)(1−2)=3−1=−3L_1(3)=\dfrac{(3-0)(3-2)}{(1-0)(1-2)}=\dfrac{3}{-1}=-3, L2(3)=(3−0)(3−1)(2−0)(2−1)=62=3L_2(3)=\dfrac{(3-0)(3-1)}{(2-0)(2-1)}=\dfrac{6}{2}=3.

Step 2: weight each basis value by its data value. The values are y0=1,y1=3,y2=7y_0=1, y_1=3, y_2=7, so the estimate is P(3)=y0L0(3)+y1L1(3)+y2L2(3)=1(1)+3(−3)+7(3)P(3) = y_0 L_0(3) + y_1 L_1(3) + y_2 L_2(3) = 1(1) + 3(-3) + 7(3).

Step 3: add up. P(3)=1−9+21=13P(3) = 1 - 9 + 21 = 13.

Step 4: check with the explicit polynomial. Solving directly for the quadratic through the three points gives P(x)=x2+x+1P(x)=x^2+x+1, and indeed P(3)=9+3+1=13P(3)=9+3+1=13, confirming the Lagrange-form computation without ever writing the polynomial's coefficients explicitly.

Example: Why interpolation error explodes near the edges: a first look at Runge's phenomenon

Take the 55 equally spaced nodes x0=−1,x1=−0.5,x2=0,x3=0.5,x4=1x_0=-1, x_1=-0.5, x_2=0, x_3=0.5, x_4=1 on [−1,1][-1,1]. Compute the node polynomial w(x)=∏i=04(x−xi)w(x)=\prod_{i=0}^{4}(x-x_i) at a point near the center, x=0.1x=0.1, and at a point near the edge, x=0.9x=0.9, and compare their sizes.

Solution

Step 1: evaluate w(0.1)w(0.1). w(0.1)=(0.1+1)(0.1+0.5)(0.1−0)(0.1−0.5)(0.1−1)=(1.1)(0.6)(0.1)(−0.4)(−0.9)w(0.1)=(0.1+1)(0.1+0.5)(0.1-0)(0.1-0.5)(0.1-1) = (1.1)(0.6)(0.1)(-0.4)(-0.9), which multiplies out to 0.023760.02376.

Step 2: evaluate w(0.9)w(0.9). w(0.9)=(0.9+1)(0.9+0.5)(0.9−0)(0.9−0.5)(0.9−1)=(1.9)(1.4)(0.9)(0.4)(−0.1)w(0.9)=(0.9+1)(0.9+0.5)(0.9-0)(0.9-0.5)(0.9-1) = (1.9)(1.4)(0.9)(0.4)(-0.1), which multiplies out to −0.09576-0.09576, so ∣w(0.9)∣=0.09576|w(0.9)|=0.09576.

Step 3: compare. ∣w(0.9)∣≈0.0958|w(0.9)| \approx 0.0958 is roughly 44 times larger than ∣w(0.1)∣≈0.0238|w(0.1)| \approx 0.0238, even though 0.90.9 and 0.10.1 are both comfortably inside [−1,1][-1,1].

Step 4: connect to the error formula. Since the interpolation error is f(x)−P(x)=f(n+1)(ξ)(n+1)!w(x)f(x)-P(x)=\dfrac{f^{(n+1)}(\xi)}{(n+1)!}w(x), the larger ∣w(x)∣|w(x)| near the edges directly inflates the error bound there; for a function like f(x)=11+25x2f(x)=\dfrac{1}{1+25x^2} whose high derivatives grow very fast, this edge amplification (made worse as more equispaced nodes are added) is exactly what produces the wild oscillations known as Runge's phenomenon — the motivation for using cubic splines or unevenly spaced (Chebyshev) nodes instead of raising the degree of a single equispaced polynomial.

Given 55 distinct data points, what is the degree of the unique interpolating polynomial guaranteed by the existence-uniqueness theorem?

What is the value of the Lagrange basis polynomial Li(xi)L_i(x_i) at its own node xix_i?

An engineer fits a single degree-88 polynomial through 99 equally spaced measurements of a material's thermal conductivity. Near the ends of the measured range, the fitted curve oscillates wildly even though the true conductivity varies smoothly. What is the standard fix?

If ∣f(n+1)(x)∣≤M|f^{(n+1)}(x)| \le M on an interval and the node polynomial satisfies ∣w(x)∣≤W|w(x)| \le W there, what bound does the Lagrange error formula give for ∣f(x)−P(x)∣|f(x)-P(x)|?