Polynomial Interpolation: Lagrange and Newton
Learning Objectives
- Prove that distinct nodes determine one polynomial of degree at most , 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 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 and any values , exactly one polynomial of degree at most has . Uniqueness: the difference of two such polynomials has degree at most and 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 , whose condition number grows fast: for 21 nodes, is for equispaced nodes on and on .
Lagrange and barycentric forms
The cardinal polynomials are , with equal to 1 when and 0 otherwise, so . Evaluated directly this costs per point. With weights and , we have . The constant function 1 is its own interpolant, so . Dividing cancels and gives the barycentric formula, for not a node:
Setup is and each evaluation is . This is what scipy.interpolate.BarycentricInterpolator computes.
Newton form and divided differences
Write . The coefficients are the divided differences , defined by and
The table takes work, and nested multiplication evaluates in . Adding a node appends one row, work, and leaves every earlier unchanged.
The error formula
Hypotheses. , the nodes are distinct points of , and . Conclusion. There is , depending on , with
It reads like the Taylor remainder with replaced by . Two factors compete: the derivative belongs to , and belongs to the nodes.
Nodes and the Lebesgue constant
On , the Chebyshev nodes , , are the zeros of . They give , the smallest value any choice of nodes can reach. Equispaced nodes leave small in the middle and large at the ends: for , is near and near the ends, against a maximum of for Chebyshev ( at ). On , map by .
The nodes also fix the conditioning of the data-to-polynomial map. Changing the values by at most changes by at most , where is the Lebesgue constant:
textn 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 analytic on an open interval containing , interpolation at Chebyshev nodes converges geometrically: the max error is at most for some , . For equispaced nodes no such statement holds.
Worked Examples
Example 1: one polynomial, three forms, one new node
Interpolate . The denominators are , so . At the barycentric sums are
The divided-difference table, with Newton coefficients on top of each column:
textx f f[,] f[,,] f[,,,] 0 1 2 -3/2 7/12 1 3 -1 5/6 2 2 3/2 4 5
So , which expands to and gives again. Symbolic expansion of the Lagrange form returns the same cubic, and BarycentricInterpolator and KroghInterpolator both return at .
Now add . One new row gives , , , , so gains only the term . That term is zero at the four old nodes and equals at , which takes to .
Example 2: checking the error formula
For on with nodes , the fourth derivative lies in . Calculus gives , at . So the max error is between and . Measured on a grid of points it is , near . There the formula gives , that is, , inside as promised.
Example 3: Runge's phenomenon
Take on , which is in and looks harmless. Max errors on a grid of 20001 points, with the equispaced case repeated in 200-digit arithmetic:
textn 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 has size , the factor can grow like , so the bound is useless here, and it cannot locate the trouble: at , in a region where the method works. What separates the regions is the pole. For this the error is exactly with , so it scales with , which at is at and at . The exact-arithmetic column proves this is real divergence and not rounding. The worst point moves toward the end, at and at , while the middle converges: on the error is , and at . Rounding joins in at the bottom of the table: at the float64 value is about 1000 times the exact one.
For Chebyshev nodes the observed factor per degree stays between and from to , and the error reaches rounding level near . Complex analysis predicts the rate from the poles of at : . Note the first row: at Chebyshev is worse.
Example 4: when rounding is the whole story
on has no Runge problem, since and the formula forces convergence.
textn 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 is accurate to 93 digits, and float64 returns garbage of size 1. BarycentricInterpolator shows the same growth ( at ), so this is not a coding error. Multiply out with : , and at , the size of the observed errors. Here the truncation error is gone and the rounding of the data, amplified by , is everything left.
Example 5: the same polynomial, five implementations
Chebyshev nodes, from Example 3, , float64. All five lines compute one mathematical object:
textmethod 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 the gap is against . The Vandermonde lines have , solve the system with numpy.linalg.solve, and use the nodes in the order . Their values are rounding noise: column order moves the error by four orders of magnitude here, sorting the nodes gives and instead, and the digits can change between machines. For the same matrices give with increasing powers and with decreasing powers, so bounds the worst right-hand side, and this smooth data is not it. A direct implementation of the barycentric formula matches BarycentricInterpolator to at and .
Example 6: when smoothness fails
is continuous but has no derivative at , so the error formula does not apply.
textn 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 : 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 , 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 .
- "Chebyshev nodes are always better." They lost at in Example 3, they give only for , and they require choosing where to sample. For data already sampled on a fixed grid, see
splinesandleast-squares-curve-fitting. - "Book vs today." The SciPy documentation warns that
scipy.interpolate.lagrangeis numerically unstable, says not to expect more than about 20 points, and marks it deprecated since version 1.18 in favor ofBarycentricInterpolator.
Summary
There is one polynomial of degree at most through distinct nodes. The barycentric form evaluates it stably in per point; the Newton form adds nodes cheaply but depends on node order; the monomial form inherits a Vandermonde condition number. The error is for . Equispaced nodes make and the Lebesgue constant large near the ends, which gives true divergence for ( at ) and rounding blow-up for (about at ). Chebyshev nodes keep under 4 in these runs and give geometric convergence for analytic functions, at a rate set by the poles ( per degree for ), but only for .
Documentation Links
- Driscoll and Braun: Fundamentals of Numerical Computation, 9.1 Polynomial interpolation
- Driscoll and Braun: Fundamentals of Numerical Computation, 9.2 The barycentric formula
- Driscoll and Braun: Fundamentals of Numerical Computation, 9.3 Stability of polynomial interpolation
- Demanet (2012): MIT OpenCourseWare 18.330, Chapter 3: Interpolation
- SciPy documentation: BarycentricInterpolator
- SciPy documentation: KroghInterpolator
- SciPy documentation: scipy.interpolate.lagrange
- Wikipedia: Polynomial interpolation