Polynomial Interpolation: Lagrange and Newton

Published on 2026-11-04·v1.0

Learning Objectives

  • Prove that n+1n+1 distinct nodes determine one polynomial of degree at most nn, and explain why the Vandermonde system is the wrong way to compute it.
  • Build the interpolant in Lagrange form, in barycentric form, and in Newton form with divided differences, and add a node to the Newton form.
  • State the interpolation error formula with its hypotheses and use it to bound an error.
  • Measure Runge's phenomenon, and separate true divergence of the polynomial from rounding amplified by the Lebesgue constant.
  • Say what Chebyshev nodes fix and what they do not.

Context & Motivation

A Taylor polynomial matches a function at one point. An interpolant matches it at many, and taylor-and-maclaurin-series-with-error-bounds already showed interpolation at Chebyshev nodes beating the Taylor polynomial of the same degree for sin⁡\sin by a factor of more than 250. Interpolation is also the raw material of quadrature in trapezoid-and-simpson-rules. The same Lagrange formula runs over finite fields in Reed-Solomon codes and Shamir secret sharing, where arithmetic is exact and nothing in this lesson about rounding applies.

Over floating-point numbers, three things can go wrong even though the polynomial is unique: the basis can be ill-conditioned in the sense of the-matrix-condition-number, the node positions can make the polynomial itself diverge, and the data's rounding can be amplified. These are separate failures, and this lesson measures each one.

Core Theory

Existence and uniqueness

Given distinct nodes x0,…,xnx_0,\ldots,x_n and any values y0,…,yny_0,\ldots,y_n, exactly one polynomial pp of degree at most nn has p(xj)=yjp(x_j) = y_j. Uniqueness: the difference of two such polynomials has degree at most nn and n+1n+1 roots, so it is zero. Existence: the Lagrange form below builds it. The nodes must be distinct, since a repeated node with two different values admits no function at all.

So the "Lagrange polynomial" and the "Newton polynomial" are one polynomial written in two bases. Only their numerical behavior differs. Writing it in the monomial basis means solving a Vandermonde system Vc=yVc = y, whose condition number grows fast: for 21 nodes, κ2(V)\kappa_2(V) is 8.3×1088.3\times10^{8} for equispaced nodes on [−1,1][-1,1] and 8.9×10168.9\times10^{16} on [0,1][0,1].

Lagrange and barycentric forms

The cardinal polynomials are ℓj(x)=∏k≠jx−xkxj−xk\ell_j(x) = \prod_{k\ne j}\frac{x-x_k}{x_j-x_k}, with ℓj(xi)\ell_j(x_i) equal to 1 when i=ji=j and 0 otherwise, so p(x)=∑jyjℓj(x)p(x) = \sum_j y_j\ell_j(x). Evaluated directly this costs O(n2)O(n^2) per point. With weights wj=1/∏k≠j(xj−xk)w_j = 1/\prod_{k\ne j}(x_j-x_k) and ω(x)=∏k(x−xk)\omega(x) = \prod_k (x-x_k), we have p(x)=ω(x)∑jwjyjx−xjp(x) = \omega(x)\sum_j \frac{w_j y_j}{x-x_j}. The constant function 1 is its own interpolant, so 1=ω(x)∑jwjx−xj1 = \omega(x)\sum_j\frac{w_j}{x-x_j}. Dividing cancels ω\omega and gives the barycentric formula, for xx not a node:

p(x)=∑jwjyjx−xj∑jwjx−xj.p(x) = \frac{\sum_j \dfrac{w_j y_j}{x-x_j}}{\sum_j \dfrac{w_j}{x-x_j}}.

Setup is O(n2)O(n^2) and each evaluation is O(n)O(n). This is what scipy.interpolate.BarycentricInterpolator computes.

Newton form and divided differences

Write p(x)=c0+c1(x−x0)+c2(x−x0)(x−x1)+⋯p(x) = c_0 + c_1(x-x_0) + c_2(x-x_0)(x-x_1) + \cdots. The coefficients are the divided differences ck=f[x0,…,xk]c_k = f[x_0,\ldots,x_k], defined by f[xi]=yif[x_i] = y_i and

f[xi,…,xi+k]=f[xi+1,…,xi+k]−f[xi,…,xi+k−1]xi+k−xi.f[x_i,\ldots,x_{i+k}] = \frac{f[x_{i+1},\ldots,x_{i+k}] - f[x_i,\ldots,x_{i+k-1}]}{x_{i+k}-x_i}.

The table takes O(n2)O(n^2) work, and nested multiplication evaluates pp in O(n)O(n). Adding a node appends one row, O(n)O(n) work, and leaves every earlier ckc_k unchanged.

The error formula

Hypotheses. f∈Cn+1[a,b]f \in C^{n+1}[a,b], the nodes are distinct points of [a,b][a,b], and x∈[a,b]x \in [a,b]. Conclusion. There is ξ∈[a,b]\xi \in [a,b], depending on xx, with

f(x)−p(x)=f(n+1)(ξ)(n+1)! ω(x),ω(x)=∏k=0n(x−xk).f(x) - p(x) = \frac{f^{(n+1)}(\xi)}{(n+1)!}\,\omega(x), \qquad \omega(x) = \prod_{k=0}^n (x-x_k).

It reads like the Taylor remainder with (x−a)n+1(x-a)^{n+1} replaced by ω\omega. Two factors compete: the derivative belongs to ff, and ω\omega belongs to the nodes.

Nodes and the Lebesgue constant

On [−1,1][-1,1], the Chebyshev nodes xk=cos⁡(2k+1)π2n+2x_k = \cos\frac{(2k+1)\pi}{2n+2}, k=0,…,nk=0,\ldots,n, are the zeros of Tn+1T_{n+1}. They give max⁡∣ω∣=2−n\max\lvert\omega\rvert = 2^{-n}, the smallest value any choice of n+1n+1 nodes can reach. Equispaced nodes leave ω\omega small in the middle and large at the ends: for n=20n=20, ∣ω∣\lvert\omega\rvert is 4.3×10−94.3\times10^{-9} near x=0.05x=0.05 and 2.3×10−42.3\times10^{-4} near the ends, against a maximum of 9.5×10−79.5\times10^{-7} for Chebyshev (8.3×10−78.3\times10^{-7} at x=0.05x=0.05). On [a,b][a,b], map by x↦a+b2+b−a2xx\mapsto\frac{a+b}{2}+\frac{b-a}{2}x.

The nodes also fix the conditioning of the data-to-polynomial map. Changing the values by at most ε\varepsilon changes pp by at most Λnε\Lambda_n\varepsilon, where Λn=max⁡x∑j∣ℓj(x)∣\Lambda_n = \max_x\sum_j\lvert\ell_j(x)\rvert is the Lebesgue constant:

text
n Lambda_n equispaced Lambda_n Chebyshev 10 2.99e+01 2.49 20 1.10e+04 2.90 40 4.69e+09 3.33 60 2.98e+15 3.58

For ff analytic on an open interval containing [−1,1][-1,1], interpolation at Chebyshev nodes converges geometrically: the max error is at most CK−nCK^{-n} for some C>0C>0, K>1K>1. For equispaced nodes no such statement holds.

Worked Examples

Example 1: one polynomial, three forms, one new node

Interpolate (0,1),(1,3),(2,2),(4,5)(0,1), (1,3), (2,2), (4,5). The denominators ∏k≠j(xj−xk)\prod_{k\ne j}(x_j-x_k) are −8,3,−4,24-8, 3, -4, 24, so w=(−18,13,−14,124)w = (-\tfrac18, \tfrac13, -\tfrac14, \tfrac1{24}). At x=3x=3 the barycentric sums are

−124+12−12−524−124+16−14−124=−1/4−1/6=32.\frac{-\frac1{24}+\frac12-\frac12-\frac5{24}}{-\frac1{24}+\frac16-\frac14-\frac1{24}} = \frac{-1/4}{-1/6} = \frac32.

The divided-difference table, with Newton coefficients on top of each column:

text
x f f[,] f[,,] f[,,,] 0 1 2 -3/2 7/12 1 3 -1 5/6 2 2 3/2 4 5

So p(x)=1+2x−32x(x−1)+712x(x−1)(x−2)p(x) = 1 + 2x - \tfrac32 x(x-1) + \tfrac7{12}x(x-1)(x-2), which expands to 712x3−134x2+143x+1\tfrac7{12}x^3 - \tfrac{13}4x^2 + \tfrac{14}3x + 1 and gives p(3)=32p(3) = \tfrac32 again. Symbolic expansion of the Lagrange form returns the same cubic, and BarycentricInterpolator and KroghInterpolator both return 1.51.5 at x=3x=3.

Now add (3,0)(3,0). One new row gives 55, 72\tfrac72, 43\tfrac43, 14\tfrac14, so pp gains only the term 14x(x−1)(x−2)(x−4)\tfrac14x(x-1)(x-2)(x-4). That term is zero at the four old nodes and equals −32-\tfrac32 at x=3x=3, which takes 32\tfrac32 to 00.

Example 2: checking the error formula

For f=exf = e^x on [0,1][0,1] with nodes 0,13,23,10, \tfrac13, \tfrac23, 1, the fourth derivative lies in [1,e][1,e]. Calculus gives max⁡∣ω∣=181\max\lvert\omega\rvert = \tfrac1{81}, at x=12±56x = \tfrac12\pm\tfrac{\sqrt5}{6}. So the max error is between 124⋅81=5.14×10−4\frac{1}{24\cdot81} = 5.14\times10^{-4} and e24⋅81=1.40×10−3\frac{e}{24\cdot81} = 1.40\times10^{-3}. Measured on a grid of 10510^5 points it is 9.24×10−49.24\times10^{-4}, near x=0.875x = 0.875. There the formula gives eξ=1.797e^\xi = 1.797, that is, ξ=0.586\xi = 0.586, inside [0,1][0,1] as promised.

Example 3: Runge's phenomenon

Take f(x)=1/(1+25x2)f(x) = 1/(1+25x^2) on [−1,1][-1,1], which is in C∞C^\infty and looks harmless. Max errors on a grid of 20001 points, with the equispaced case repeated in 200-digit arithmetic:

text
n equispaced equispaced exact Chebyshev 5 4.33e-01 4.33e-01 5.56e-01 10 1.92e+00 1.92e+00 1.09e-01 20 5.98e+01 5.98e+01 1.53e-02 40 1.05e+05 1.05e+05 2.89e-04 60 1.64e+08 2.29e+08 5.42e-06 80 6.31e+14 5.46e+11 1.02e-07

The hypotheses of the error formula hold; the formula just stops helping. Since f(2k)(0)f^{(2k)}(0) has size (2k)! 25k(2k)!\,25^{k}, the factor f(n+1)(ξ)/(n+1)!f^{(n+1)}(\xi)/(n+1)! can grow like 5n+15^{n+1}, so the bound is useless here, and it cannot locate the trouble: at n=40n=40, 541∣ω(0.025)∣=3.9×10115^{41}\lvert\omega(0.025)\rvert = 3.9\times10^{11} in a region where the method works. What separates the regions is the pole. For this ff the error is exactly ω(x)⋅2Re⁡[1/(50z ω(z)(x−z))]\omega(x)\cdot2\operatorname{Re}\big[1/(50z\,\omega(z)(x-z))\big] with z=i/5z=i/5, so it scales with ∣ω(x)/ω(i/5)∣\lvert\omega(x)/\omega(i/5)\rvert, which at n=40n=40 is 1.5×10−51.5\times10^{-5} at x=0.025x=0.025 and 2.9×1052.9\times10^{5} at x=0.975x=0.975. The exact-arithmetic column proves this is real divergence and not rounding. The worst point moves toward the end, x≈0.94x\approx0.94 at n=10n=10 and 0.9890.989 at n=40n=40, while the middle converges: on ∣x∣≤12\lvert x\rvert\le\tfrac12 the error is 0.1160.116, 0.01530.0153 and 5.5×10−45.5\times10^{-4} at n=10,20,40n=10,20,40. Rounding joins in at the bottom of the table: at n=80n=80 the float64 value is about 1000 times the exact one.

For Chebyshev nodes the observed factor per degree stays between 1.2181.218 and 1.2201.220 from n=40n=40 to n=160n=160, and the error reaches rounding level near n=160n=160. Complex analysis predicts the rate from the poles of ff at ±i/5\pm i/5: 15+1+125=1.2198\tfrac15+\sqrt{1+\tfrac1{25}} = 1.2198. Note the first row: at n=5n=5 Chebyshev is worse.

Example 4: when rounding is the whole story

exe^x on [−1,1][-1,1] has no Runge problem, since ∣f(n+1)∣≤e\lvert f^{(n+1)}\rvert \le e and the formula forces convergence.

text
n equispaced float64 equispaced exact Chebyshev float64 10 2.35e-10 2.35e-10 2.71e-11 20 2.12e-12 4.82e-24 2.22e-15 30 2.78e-09 1.02e-39 2.66e-15 40 2.34e-06 9.37e-57 2.66e-15 50 1.15e-03 7.98e-75 2.66e-15 60 9.66e-01 9.94e-94 3.11e-15

The true polynomial at n=60n=60 is accurate to 93 digits, and float64 returns garbage of size 1. BarycentricInterpolator shows the same growth (0.780.78 at n=60n=60), so this is not a coding error. Multiply out e u Λne\,u\,\Lambda_n with u=1.1×10−16u = 1.1\times10^{-16}: 3.3×10−123.3\times10^{-12}, 1.4×10−61.4\times10^{-6} and 0.890.89 at n=20,40,60n=20,40,60, the size of the observed errors. Here the truncation error is gone and the rounding of the data, amplified by Λn\Lambda_n, is everything left.

Example 5: the same polynomial, five implementations

Chebyshev nodes, ff from Example 3, n=60n=60, float64. All five lines compute one mathematical object:

text
method max error barycentric 5.42e-06 Newton, Leja node order 5.42e-06 Vandermonde, increasing powers 4.33e-03 Newton, nodes sorted left to right 1.43e+00 Vandermonde, decreasing powers (default) 5.24e+01

Leja order picks each next node to maximize the product of distances to those already chosen. Node order is the only difference between the two Newton lines, and at n=120n=120 the gap is 3.6×10−113.6\times10^{-11} against 3.2×10243.2\times10^{24}. The Vandermonde lines have κ2(V)=4.5×1022\kappa_2(V) = 4.5\times10^{22}, solve the system with numpy.linalg.solve, and use the nodes in the order k=0,…,nk=0,\ldots,n. Their values are rounding noise: column order moves the error by four orders of magnitude here, sorting the nodes gives 0.0480.048 and 3.663.66 instead, and the digits can change between machines. For exe^x the same matrices give 5.3×10−155.3\times10^{-15} with increasing powers and 3.0×10−103.0\times10^{-10} with decreasing powers, so κ\kappa bounds the worst right-hand side, and this smooth data is not it. A direct implementation of the barycentric formula matches BarycentricInterpolator to 1.1×10−151.1\times10^{-15} at n=20n=20 and n=40n=40.

Example 6: when smoothness fails

f(x)=∣x∣f(x) = \lvert x\rvert is continuous but has no derivative at 00, so the error formula does not apply.

text
n equispaced exact Chebyshev n * Chebyshev error 10 6.64e-01 5.46e-02 0.55 20 9.52e+01 2.85e-02 0.57 40 1.47e+07 1.46e-02 0.58 80 2.45e+18 7.37e-03 0.59

Equispaced interpolation diverges. Chebyshev converges, but only like 1/n1/n: the geometric rate needed analyticity. Continuity alone is not enough for any fixed node table: Faber's theorem says every table has some continuous function whose interpolants diverge.

Common Misconceptions & Pitfalls

  • "More nodes always give a better fit." Examples 3, 4 and 6 show errors growing with nn, for three different reasons.
  • "Runge's phenomenon is a rounding effect." The exact-arithmetic column of Example 3 diverges too. Example 4 is the opposite case: there the exact polynomial is fine and only rounding hurts.
  • "Lagrange and Newton give different answers." Uniqueness makes them one polynomial. They differ in cost and rounding.
  • "The Newton form is safe in any node order." Example 5 shows five orders of magnitude of difference from ordering alone at n=60n=60.
  • "Chebyshev nodes are always better." They lost at n=5n=5 in Example 3, they give only 1/n1/n for ∣x∣\lvert x\rvert, and they require choosing where to sample. For data already sampled on a fixed grid, see splines and least-squares-curve-fitting.
  • "Book vs today." The SciPy documentation warns that scipy.interpolate.lagrange is numerically unstable, says not to expect more than about 20 points, and marks it deprecated since version 1.18 in favor of BarycentricInterpolator.

Summary

There is one polynomial of degree at most nn through n+1n+1 distinct nodes. The barycentric form evaluates it stably in O(n)O(n) per point; the Newton form adds nodes cheaply but depends on node order; the monomial form inherits a Vandermonde condition number. The error is f(n+1)(ξ) ω(x)/(n+1)!f^{(n+1)}(\xi)\,\omega(x)/(n+1)! for f∈Cn+1f \in C^{n+1}. Equispaced nodes make ω\omega and the Lebesgue constant large near the ends, which gives true divergence for 1/(1+25x2)1/(1+25x^2) (10510^5 at n=40n=40) and rounding blow-up for exe^x (about 11 at n=60n=60). Chebyshev nodes keep Λn\Lambda_n under 4 in these runs and give geometric convergence for analytic functions, at a rate set by the poles (1.21981.2198 per degree for 1/(1+25x2)1/(1+25x^2)), but only 1/n1/n for ∣x∣\lvert x\rvert.

Documentation Links