A computer can only add, multiply and round, so it replaces hard functions by polynomials through sample points. The error of that replacement has an exact formula, equally spaced points can make it explode (Runge), Chebyshev points tame it, and rounding adds a second, separate kind of error.
Apostol, not taughtBeyond the courseApostol Vol. 2, ch. 15 (15.1 to 15.4, 15.6 to 15.8, 15.10, 15.14 to 15.17, 15.19 to 15.20, 15.22)Trefethen, Approximation Theory and Approximation Practice (SIAM, 2013)Goldberg, What every computer scientist should know about floating-point arithmetic (1991)Burden and Faires, Numerical Analysis, ch. 3 and 4
A computer can add, subtract, multiply, divide and compare numbers. That is all. So how does it compute sin2.3, the area under e−x2, or 2? The answer in every case is to replace the hard function by a polynomial, which needs only multiplication and addition, and then to ask two questions. How far is the polynomial from the real function? And how much does it matter that every addition and multiplication is rounded? This chapter answers the first with an exact error formula (and shows the surprise that more nodes can make things worse), and the second with a look at how a computer stores numbers.
Quick checkA non-zero polynomial has degree at most 4. At most how many roots can it have?
A non-zero polynomial of degree d has at most d roots: each root r gives a factor x−r (the factor theorem), and each factor uses up one degree. The same fact will give uniqueness of the interpolating polynomial below.Review: at most n roots
Quick checkg is differentiable, and g(0) = g(1) = g(2) = 0. What can you say about g'?
Rolle's theorem (the case of the mean value theorem with equal end values) applies to each of the intervals [0,1] and [1,2] and gives a zero of g′ in each. This fact, repeated, is the engine of the error formula below.Review: Rolle and the mean value theorem
Quick checkA square matrix has a non-zero determinant. What does that tell you about Mx = y?
A matrix is invertible exactly when its determinant is non-zero, and an invertible M gives the unique solution x=M−1y for every y.Review: determinant and invertibility
The picture
Pick n+1 points on the x-axis (the nodes), read off the height of a function f above each, and draw the one polynomial of degree at most n through those n+1 points. That polynomial is the interpolating polynomial. The picture below does this for f(x)=1/(1+25x2) on [−1,1], with the nodes equally spaced to begin with. Slide the degree n up from 2 to 30. For small n the orange polynomial hugs the purple curve. Around n=8 it starts to swing at the ends of the interval, and by n=20 the swing is enormous: more nodes, a worse fit. Now switch the nodes to Chebyshev nodes, which crowd toward the ends. The fit now improves as n grows. Finally choose “Drag the heights yourself” and pull one dot: the polynomial through nine points can leave the dots far behind between them.
Two questions come out of the picture. Why is the error between the nodes what it is (the error formula), and why do some node choices behave so much better than others (the Chebyshev nodes)?
The idea, in words
A polynomial of degree n has n+1 coefficients, so it can be made to pass through n+1 points, and (as we prove) in only one way. Polynomials are easy: a computer evaluates them with additions and multiplications, and we can differentiate and integrate them exactly. So replace f by the polynomial pn through its values at n+1 nodes. What is the error f(x)−pn(x)? At the nodes it is 0. Between them it depends on two things: how wiggly f is, measured by its (n+1)-st derivative, and how the nodes are placed, measured by the product w(x)=(x−x0)⋯(x−xn). The error formula says
It is the Taylor remainder of 1.4 with the single centre a replaced by n+1 different centres, and it has the same proof. Everything else in the chapter is either a consequence (quadrature rules are integrals of interpolants) or a warning (the second factor can be huge, and the computer rounds).
Why· Two knobs: the function and the nodes
You do not control f, so you control the nodes. The factor w(x) is the only part that depends on them. Equally spaced nodes make w small in the middle and large near the ends. Chebyshev nodes spread the size of w evenly, and we prove that no choice of nodes makes the largest ∣w∣ smaller. That is the whole story of Runge’s phenomenon in two lines.
Where this came from· Interpolation: Newton, Waring, Lagrange, Runge
Astronomers and table makers needed values between the entries of a table. Isaac Newton worked out how to pass a polynomial through any number of points using differences; the method appears as Lemma V of Book III of the Principia (1687) and was published in full as Methodus Differentialis in 1711. Edward Waring published the formula we now call Lagrange’s in 1779. Joseph-Louis Lagrange gave it in 1795, in the fifth of his Leçons élémentaires at the École Normale, and it carries his name. It is natural to expect that more points give a better fit. Carl Runge showed in 1901 that this can fail: he interpolated 1/(1+25x2) at equally spaced points on [−1,1] and found that the error grows without bound with the degree. The cure, nodes that cluster at the ends, is built on polynomials that Pafnuty Chebyshev introduced in 1854 while studying the linkages of steam engines. Using their roots as interpolation nodes came later.
The chapter answers six questions. (1) Does a polynomial through the points exist, and is it unique? (2) How big is its error? (3) How do we place nodes to make the error small, and what goes wrong with equal spacing? (4) How do we compute the polynomial efficiently, and update it when a node is added? (5) How do we integrate numerically, and with what error? (6) What does rounding do, and how fast does Newton’s method converge?
Definitions and theorems
Existence and uniqueness
Definition A
Interpolating polynomial
Let x0,x1,…,xn be n+1distinct real numbers (the nodes) and y0,…,yn any real numbers. An interpolating polynomial is a polynomial p of degree at most n with p(xj)=yj for j=0,…,n. For a function f we take yj=f(xj) and write pn for the interpolating polynomial of f.
In one lineGiven distinct nodes x0,…,xn and values y0,…,yn, a polynomial p of degree at most n with p(xj)=yj for every j.
Why it existsIt is the simplest way to turn a table of values into a formula that can be evaluated, differentiated and integrated between the table entries.
Definition A
Lagrange basis polynomial
For distinct nodes x0,…,xn the Lagrange basis polynomial for node j is
ℓj(x)=k=0k=j∏nxj−xkx−xk.
It is a product of n linear factors, so it has degree n. At x=xj every factor is 1, so ℓj(xj)=1. At any other node xi the factor with k=i is 0, so ℓj(xi)=0.
In one lineℓj(x)=∏k=jxj−xkx−xk: the degree-n polynomial that equals 1 at the node xj and 0 at all the other nodes.
Why it existsIt is a building block: scaling it by y_j fixes the value at x_j without disturbing any other node, so adding the pieces solves the whole problem at once.
Theorem AApostol 15.6; Lagrange 1795
Existence and uniqueness of the interpolating polynomial
Let x0,…,xn be distinct and y0,…,yn arbitrary. Then p(x)=∑j=0nyjℓj(x) is an interpolating polynomial, and any polynomial of degree at most n that agrees with it at the n+1 nodes is equal to it.
In one lineFor distinct nodes there is exactly one polynomial of degree at most n through the given n+1 points, and it is p(x)=∑jyjℓj(x).
Why it is trueExistence is an explicit formula, so we can compute with it. Uniqueness says that every method (Lagrange, Newton, solving a linear system) finds the same polynomial, so the error formula applies to all.
ProofApostol 15.6
The idea: Existence: the formula works because each basis polynomial is a switch that is on at one node and off at the others. Uniqueness: the difference of two interpolants has too many roots.
p=∑jyjℓj has degree at most n.
A sum of polynomials of degree n times constants has degree at most n.
p(xi)=∑jyjℓj(xi)=yi for each i, so p interpolates.
At x=xi the basis polynomials are ℓj(xi)=1 if j=i and 0 otherwise.
Uniqueness: let r=p−q.
Suppose q also has degree at most n and q(xi)=yi for all i. The difference r=p−q has degree at most n.
r has n+1 roots.
r(xi)=yi−yi=0 at each of the n+1 distinct nodes.
r=0, that is q=p.
A non-zero polynomial of degree at most n has at most n roots (0.6), so r cannot be non-zero.
Worked example the system solved by elimination in 2.6
Find the polynomial of degree at most 2 through the points (1, 2), (2, 3) and (4, 9). Use it to estimate the value at x = 3.
Solution.
Write the three basis polynomials.ℓ0(x)=(1−2)(1−4)(x−2)(x−4)=3(x−2)(x−4), ℓ1(x)=(2−1)(2−4)(x−1)(x−4)=−2(x−1)(x−4), ℓ2(x)=(4−1)(4−2)(x−1)(x−2)=6(x−1)(x−2). For ℓj put the other nodes in the numerator, and divide by the same product evaluated at xj, so that ℓj(xj)=1.
Combine.p(x)=2ℓ0(x)+3ℓ1(x)+9ℓ2(x). The values at the nodes are the weights.
Expand.p(x)=32(x2−6x+8)−23(x2−5x+4)+23(x2−3x+2)=32x2−x+37. Collect the x2 terms: 32−23+23=32. The x terms: −4+215−29=−1. The constants: 316−6+3=37.
Check the nodes.p(1)=32−1+37=2, p(2)=38−2+37=3, p(4)=332−4+37=9. Any interpolating polynomial must pass through the data.
Evaluate at 3.p(3)=6−3+37=316. Direct from the formula. Check with the basis: ℓ0(3)=−31, ℓ1(3)=1, ℓ2(3)=31, so p(3)=−32+3+3=316.
Answer.p(x)=31(2x2−3x+7), the same polynomial that Gaussian elimination found in 2.6, and p(3)=316≈5.33. By uniqueness the two methods have to agree.
The same problem is a system of linear equations. Writing p(x)=c0+c1x+⋯+cnxn, the n+1 conditions p(xj)=yj say Vc=y with the following matrix. This is the link with 2.7: there the determinant of this matrix was computed for particular numbers, and the pattern is a theorem.
Definition A
Vandermonde matrix
For nodes x0,…,xn the Vandermonde matrix is V with Vjk=xjk, for j,k=0,…,n. Row j is (1,xj,…,xjn). Then (Vc)j=c0+c1xj+⋯+cnxjn=p(xj), so the coefficients c of the interpolating polynomial solve Vc=y.
In one lineThe (n+1)×(n+1) matrix whose row j is (1,xj,xj2,…,xjn). Its determinant is the product of all differences xj−xi with i<j.
Why it existsIt is the coefficient matrix of the interpolation problem in the monomial basis. It is invertible exactly when the nodes are distinct, which gives uniqueness a second proof.
Theorem AVandermonde; Apostol 15.6 and exercises
The Vandermonde determinant
For nodes x0,…,xn, detV=∏0≤i<j≤n(xj−xi).
In one linedetV=∏0≤i<j≤n(xj−xi). So V is invertible exactly when the nodes are distinct.
Why it is trueIt says again, in the language of 2.7, that distinct nodes are exactly what is needed for the interpolation problem to have a unique answer.
Proofstandard
The idea: Induction on n. Replace the last node by a variable t. The determinant becomes a polynomial in t of degree at most n that vanishes at the earlier nodes, so it is a known constant times a product of linear factors.
Base case n=1.
For n=1, det[11x0x1]=x1−x0, the product with the single pair (0,1).
Treat the last node as a variable t.
Assume the formula for n−1 and look at n. Let D(t) be the determinant of V with the last row replaced by (1,t,…,tn), so D(xn)=detV.
D has degree at most n, with tn-coefficient detVn−1.
Expand the determinant along the last row (2.7). Each entry tk is multiplied by a constant cofactor, so D is a polynomial in t of degree at most n. The coefficient of tn is the cofactor of the corner entry, which is the determinant of the Vandermonde matrix of x0,…,xn−1 (sign (−1)n+n=+1).
D(xi)=0 for i=0,…,n−1.
If t=xi for i<n then the last row equals row i, and a determinant with two equal rows is 0 (2.7).
D(t)=detVn−1⋅(t−x0)⋯(t−xn−1).
A polynomial of degree at most n with the n distinct roots x0,…,xn−1 is divisible by (t−x0)⋯(t−xn−1) (factor theorem), and the quotient must be a constant, the coefficient of tn.
Put t=xn and use the inductive hypothesis detVn−1=∏0≤i<j≤n−1(xj−xi).
So detV=0 exactly when all the differences xj−xi are non-zero, that is, when the nodes are distinct. By 2.7, Vc=y then has exactly one solution c, a second proof that the interpolating polynomial exists and is unique.
Your answerWhat is the determinant of the Vandermonde matrix for the nodes 0, 2 and 5?
Multiply every difference x_j − x_i with i < j.
The product of the differences: (2−0)(5−0)(5−2)=2⋅5⋅3=30. Check with the rows (1,0,0), (1,2,4), (1,5,25): expanding along the first row gives 2⋅25−4⋅5=30.
Quick checkWhy is it dangerous to compute an interpolating polynomial by solving Vc = y for the coefficients when the degree is high?
The solution exists and is unique for distinct nodes. But the columns 1,x,x2,…,xn look almost alike on an interval, so V is nearly singular. With 21 equally spaced nodes on [0,1] its condition number is about 9×1016, which by the rule of thumb in 3.5 means no correct digits are guaranteed in double precision.Review: the condition number
The error formula (Apostol 15.8)
Theorem AApostol 15.8
Interpolation error formula
Let f∈Cn+1[a,b], let x0,…,xn∈[a,b] be distinct, and let pn be the interpolating polynomial of degree at most n with pn(xj)=f(xj). Write w(t)=(t−x0)(t−x1)⋯(t−xn). Then for every x∈[a,b] there is a point ξ in the open interval (a,b) (it depends on x) with
f(x)−pn(x)=(n+1)!f(n+1)(ξ)w(x).
In one lineIf f has n+1 continuous derivatives on [a,b] and pn interpolates it at distinct nodes in [a,b], then for each x in [a,b] there is a point ξ in (a,b) with f(x)−pn(x)=(n+1)!f(n+1)(ξ)∏j=0n(x−xj).
Why it is trueIt says the error is the next derivative, divided by (n+1)!, times a polynomial that vanishes at every node. It is Taylor's remainder with n+1 centres instead of one, and it is proved the same way.
ProofApostol 15.8; the same trick as the Taylor remainder in 1.4
The idea: Build a function g that is zero at the n+1 nodes and also at x. Rolle's theorem, applied again and again, pushes the zeros down to a zero of the (n+1)-st derivative of g, and that zero is the xi.
Assume x is not a node.
If x is one of the nodes, then f(x)=pn(x) and w(x)=0, so both sides are 0 and any ξ works.
Let K=w(x)f(x)−pn(x).
Then w(x)=0, so we can divide. K is the unknown error constant: the number that makes the equation f(x)−pn(x)=Kw(x) true at this x.
Define g(t)=f(t)−pn(t)−Kw(t).
This is a function of t with x fixed. It has n+1 continuous derivatives because f does and pn, w are polynomials.
g is 0 at the n+1 nodes and at x: it has n+2 distinct zeros in [a,b].
At a node xj: f(xj)=pn(xj) and w(xj)=0. At t=x: g(x)=f(x)−pn(x)−Kw(x)=0 by the choice of K.
g′ has at least n+1 distinct zeros in (a,b).
Rolle's theorem (1.4) on each of the n+1 gaps between consecutive zeros of g gives a zero of g′ strictly inside the gap.
g(n+1) has at least 1 zero. Call it ξ.
Repeat: each application loses one zero. After k applications there are at least n+2−k distinct zeros of g(k).
g(n+1)(t)=f(n+1)(t)−K(n+1)!.
pn has degree at most n, so its (n+1)-st derivative is 0. And w is tn+1 plus lower powers, so w(n+1)(t)=(n+1)!.
K=(n+1)!f(n+1)(ξ), and by the definition of K this is the formula.
Put t=ξ, where g(n+1)(ξ)=0, and solve for K.
Why· The picture behind the proof
Look at the interpolation picture at the top of the chapter. At each of the n+1 nodes the orange curve and the purple one cross, so their difference is zero there. A smooth function that is zero at n+2 places must wiggle at least n+1 times (once between each pair of zeros), and its derivative must wiggle at least n times, and so on: the (n+1)-st derivative still has a zero. The proof is this count. It also explains why the error depends on f(n+1): if f were a polynomial of degree n then f(n+1)=0, the error is zero, and interpolation reproduces polynomials exactly.
Proof workshopRebuild the proof of the interpolation error formula
Tap the lines in the order a proof would write them. Each line can only use what is already above it.
Choose the constant K that makes the error at this particular x equal Kw(x).
A function that measures how far the formula Kw is from the true error.
g is built out of K and w, which must be defined first.
At nodes, f=pn and w=0. At x the choice of K makes g(x)=0.
You need g before you can count its zeros.
Each differentiation loses at most one zero, and Rolle's theorem finds a zero of the derivative between any two zeros.
The count of n+2 zeros is what Rolle's theorem starts from.
pn has degree at most n and w is monic of degree n+1.
This computes the same derivative whose zero was found above.
Set g(n+1)(ξ)=0 and solve for K, then use the definition of K.
This is the conclusion, so it comes after the zero ξ and the derivative.
Two consequences. First, a bound: if ∣f(n+1)∣≤Mn+1 on [a,b] then
∣f(x)−pn(x)∣≤(n+1)!Mn+1[a,b]max∣w∣.
Second, for equally spaced nodes w is explicit enough to bound.
Corollary Astandard; Burden and Faires 3.1
Error bound for equally spaced nodes
Let nodes be xj=a+jh for j=0,…,n, with h=(b−a)/n, and ∣f(n+1)∣≤Mn+1 on [a,b]. Then for all x∈[a,b], ∣f(x)−pn(x)∣≤4(n+1)Mn+1hn+1.
In one lineWith nodes xj=a+jh, h=(b−a)/n, we have ∣w(x)∣≤41hn+1n! on [a,b], so ∣f(x)−pn(x)∣≤4(n+1)Mn+1hn+1.
Why it is trueIt turns the error formula into a number you can compute before interpolating, and it shows the error shrinks like h to the n+1 if f is smooth.
Proofstandard
The idea: Take x between two neighbouring nodes. The two nearest factors are at most h squared over 4. Each other factor is at most a whole number of widths h.
∣(x−xj)(x−xj+1)∣≤h2/4.
Let x∈[xj,xj+1] for some j∈{0,…,n−1}. The product of the two nearest factors (x−xj)(xj+1−x) has fixed sum h, and a product of two numbers with a fixed sum is largest when they are equal (each h/2).
The factors to the left of xj multiply to at most hj(j+1)!.
For i<j, ∣x−xi∣≤xj+1−xi=(j+1−i)h. Multiplying over i=0,…,j−1 gives hj(j+1)(j)⋯2.
The factors to the right of xj+1 multiply to at most hn−j−1(n−j)!.
For i>j+1, ∣x−xi∣≤xi−xj=(i−j)h. Multiplying over i=j+2,…,n gives hn−j−12⋅3⋯(n−j).
∣w(x)∣≤41hn+1(j+1)!(n−j)!.
Multiply the three bounds. The powers of h add up to 2+j+(n−j−1)=n+1.
(j+1)!(n−j)!≤n!, hence ∣w(x)∣≤41hn+1n!.
(j+1)!(n−j)!/n!=(j+1)/(jn). For j=0 this is 1, and for 1≤j≤n−1 we have (jn)≥n≥j+1, so the ratio is at most 1.
Put this in the error bound and use n!/(n+1)!=1/(n+1).
Worked example
How many equally spaced nodes on [0, 1] guarantee an error below 10⁻⁶ when interpolating eˣ? How big is the actual error?
Solution.
Bound the derivative. Every derivative of ex is ex≤e on [0,1], so Mn+1=e. The bound needs only a maximum of ∣f(n+1)∣ over the interval.
Write the bound. With n intervals, h=1/n, and the error is at most 4(n+1)nn+1e. The corollary with Mn+1=e and hn+1=n−(n+1).
Try small n.n=5: 4⋅6⋅56e≈7.2×10−6, too big. n=6: 4⋅7⋅67e≈3.5×10−7, below 10−6. The bound falls extremely fast, because nn+1 grows faster than exponentially.
Compare with the truth. Computing the interpolants and the largest error on a fine grid gives 2.7×10−6 for n=5 and 1.2×10−7 for n=6. The bound is safe (the true errors are below it) but not sharp. Here n=6 is also the first that works in truth.
Answer. Seven nodes (n=6). The guaranteed error is 3.5×10−7; the actual error is 1.2×10−7. Smooth functions are approximated spectacularly well by interpolation, provided the nodes are well placed.
Quick checkIn the error formula, the point ξ depends on x. What does that mean for how you use it?
The theorem says some ξ exists, and gives no way to find it. The usable consequence is the bound with Mn+1=max∣f(n+1)∣. At the nodes the error is exactly 0 anyway.Review: the error formula
Runge’s phenomenon and Chebyshev nodes (Apostol 15.14 to 15.17)
The error formula has two factors. For f(x)=1/(1+25x2) the first factor is large: expanding 1+25x21=1−25x2+625x4−⋯ (geometric series, 1.6) shows the Taylor coefficient of x2m is ±25m=±52m, so ∣f(2m)(0)∣/(2m)!=52m and Mn+1/(n+1)! is at least 5n+1 when n+1 is even. The derivatives grow because f has poles at x=±i/5 in the complex plane (a pole is a point where the denominator is 0, here 1+25x2=0), only 0.2 away from the interval. The second factor, max∣w∣ for equally spaced nodes, is at most about (2/e)n≈0.74n by the corollary and Stirling’s estimate n!≈2πn(n/e)n. The product of the two factors behaves like 5n⋅0.74n≈3.7n, which grows, so the bound gives no guarantee. Runge found in 1901 that the actual error, not only the bound, grows with n near the ends of the interval. The table of actual errors below (largest error on [−1,1]) shows the damage, and what Chebyshev nodes do.
Degree n
Equally spaced
Chebyshev nodes
6
0.617
0.264
10
1.916
0.109
14
7.195
0.047
18
29.19
0.0225
30
2388
0.0021
The remedy changes only w. We look for nodes that make the largest value of ∣w∣ on [−1,1] as small as possible. The answer comes from a family of polynomials that Chebyshev found.
Definition A
Chebyshev polynomial
The Chebyshev polynomials are defined by T0(x)=1, T1(x)=x and the recurrence Tn+1(x)=2xTn(x)−Tn−1(x) for n≥1. The first few: T2=2x2−1, T3=4x3−3x, T4=8x4−8x2+1.
In one lineT0=1, T1=x, and Tn+1(x)=2xTn(x)−Tn−1(x). The key property is Tn(cosθ)=cos(nθ).
Why it existsIt is the polynomial version of 'cos(n theta)': oscillating between -1 and 1 exactly n+1 times on [-1, 1], which is the most evenly spread a polynomial of its size can be.
Theorem AApostol 15.15
Properties of the Chebyshev polynomials
For n≥1:
Tn(cosθ)=cos(nθ) for all θ.
Tn has degree exactly n, with leading coefficient 2n−1.
The roots of Tn are xk=cos2n(2k+1)π, k=0,…,n−1: n distinct numbers in (−1,1).
∣Tn(x)∣≤1 for ∣x∣≤1, and Tn(cosnkπ)=(−1)k for k=0,…,n.
In one lineTn(cosθ)=cosnθ; Tn has degree n and leading coefficient 2n−1 (for n≥1); it has n distinct roots cos2n(2k+1)π in (−1,1); ∣Tn∣≤1 on [−1,1] and Tn(cosnkπ)=(−1)k.
Why it is trueThese give the nodes (the roots) and the extra fact needed for the minimal property: T_n swings fully from -1 to 1 and back, n times.
ProofApostol 15.15
The idea: Part 1 by induction from the identity cos((n+1)t) + cos((n-1)t) = 2 cos t cos(nt). The rest are read off from cosines.
Part 1, base cases.
T0(cosθ)=1=cos0 and T1(cosθ)=cosθ.
Inductive step.
The addition formulas give cos((n+1)θ)+cos((n−1)θ)=2cosθcosnθ. By induction Tn(cosθ)=cosnθ and Tn−1(cosθ)=cos(n−1)θ, so Tn+1(cosθ)=2cosθcosnθ−cos(n−1)θ=cos(n+1)θ.
Part 2 by induction on the recurrence.
T1 has degree 1 and coefficient 1=20. If Tn has leading term 2n−1xn then 2xTn has leading term 2nxn+1, and Tn−1 has lower degree.
Part 3.
Tn(xk)=cos(nθk)=cos2(2k+1)π=0 with θk=2n(2k+1)π and xk=cosθk. For k=0,…,n−1 the angles θk are n distinct numbers in (0,π), and cosine is one-to-one there, so the xk are n distinct numbers. A polynomial of degree n has at most n roots, so these are all of them.
Part 4.
For ∣x∣≤1 write x=cosθ; then ∣Tn(x)∣=∣cosnθ∣≤1. At θ=kπ/n, cos(nθ)=coskπ=(−1)k.
Definition A
Chebyshev nodes
For interpolation of degree n on [−1,1] the Chebyshev nodes are the n+1 roots of Tn+1: xk=cos2n+2(2k+1)π, k=0,…,n. (On a general interval [a,b], move them by x↦2a+b+2b−ax.) Picture n+1 equally spaced points around the upper half of a circle, and drop each down to the diameter.
In one lineThe n+1 roots of Tn+1: xk=cos2n+2(2k+1)π for k=0,…,n. They are the projections onto the x-axis of equally spaced points on a semicircle, so they crowd toward the ends.
Why it existsThey are the interpolation nodes that make the factor w(x) as small as possible, uniformly over the interval, which is the whole point of the next theorem.
Theorem AApostol 15.16; Chebyshev 1854
Chebyshev's minimal property
Let q be a monic polynomial of degree m≥1 (leading coefficient 1). Then max−1≤x≤1∣q(x)∣≥21−m. The monic polynomial Tm/2m−1 has maximum exactly 21−m.
In one lineAmong all monic polynomials of degree m≥1, none has a smaller largest absolute value on [−1,1] than 21−m, and Tm/2m−1 achieves it.
Why it is trueWith nodes at the roots of T_(n+1), the polynomial w(x) is exactly T_(n+1)/2^n, so no other choice of n+1 nodes gives a smaller maximum of |w|. Chebyshev nodes are optimal for the error bound.
ProofApostol 15.16
The idea: Suppose some monic q does better. Subtract it from the Chebyshev polynomial; the difference has too low a degree to change sign as often as it must.
The Chebyshev polynomial achieves 21−m.
By part 2 of the properties, T~=Tm/2m−1 is monic of degree m, and by part 4, ∣T~∣≤21−m with T~(cosmkπ)=(−1)k21−m. So its maximum is exactly 21−m.
Assume q is better.
Suppose, for contradiction, that a monic q of degree m has ∣q(x)∣<21−m for all x∈[−1,1].
r=T~−q has degree at most m−1.
T~ and q are both monic of degree m, so the xm terms cancel.
r(x0)>0, r(x1)<0, r(x2)>0, and so on, for the m+1 points x0>x1>⋯>xm.
At xk=cosmkπ, T~(xk)=(−1)k21−m and ∣q(xk)∣<21−m, so r(xk) has the sign of (−1)k.
r has a root in each of m disjoint intervals: at least m roots.
Intermediate value theorem on each of the m gaps between consecutive xk: r is continuous and changes sign across each gap.
Contradiction.
A non-zero polynomial of degree at most m−1 has at most m−1 roots, and r is non-zero because r(x0)=0.
Tap the lines in the order a proof would write them. Each line can only use what is already above it.
Argue by contradiction, comparing the supposed better polynomial with the Chebyshev one.
Both polynomials are monic of degree m, so the leading terms cancel.
You need r defined as a difference before its degree can be read off.
Tm(cosθ)=cosmθ, which equals (−1)k at θ=kπ/m.
This is a fact about T~ that the sign argument will use.
∣q(xk)∣<21−m=∣T~(xk)∣, so subtracting q(xk) cannot change the sign of T~(xk).
The sign needs both the values of T~ and the assumption on q.
It changes sign across each of the m gaps between consecutive xk.
The sign pattern from the previous line is what the intermediate value theorem needs.
A non-zero polynomial of degree at most m−1 has at most m−1 roots.
This compares the root count with the degree, both found above.
With the Chebyshev nodes x0,…,xn, the polynomial w(x)=(x−x0)⋯(x−xn) is monic of degree n+1 with the same roots as Tn+1, so w=Tn+1/2n and max∣w∣=2−n. By the minimal property no other choice of nodes does better.
Corollary AApostol 15.17
Error bound for Chebyshev nodes
If f∈Cn+1[−1,1] with ∣f(n+1)∣≤Mn+1 and pn interpolates at the Chebyshev nodes, then ∣f(x)−pn(x)∣≤2n(n+1)!Mn+1 for x∈[−1,1]. On a general interval [a,b], moving the nodes as described above multiplies w by (2b−a)n+1, so the bound becomes (n+1)!Mn+1(2b−a)n+12−n.
In one lineWith the Chebyshev nodes on [−1,1], ∣f(x)−pn(x)∣≤2n(n+1)!Mn+1, and no choice of n+1 nodes makes the factor max∣w∣ smaller than 2−n.
Why it is trueIt is the clean answer to 'where should the nodes go'. The factor 2^(-n) shrinks geometrically while the equally spaced factor only shrinks like 0.74^n.
Worked example
Interpolate eˣ on [−1, 1] at the three Chebyshev nodes (n = 2) and bound the error. Compare with three equally spaced nodes.
Solution.
Find the nodes. Roots of T3=4x3−3x: x=0 and x=±23≈±0.866. Or from the formula cos6(2k+1)π for k=0,1,2: cos30∘, cos90∘, cos150∘.
Bound M3.f′′′=ex≤e on [−1,1]. The same maximum of the third derivative for both choices of nodes.
Chebyshev bound.22⋅3!M3=24e≈0.113. The corollary with n=2.
Equally spaced bound. The nodes −1,0,1 have w(x)=x(x2−1), with max∣w∣=332≈0.385 (at x=±31). So the bound is 6e⋅0.385≈0.174. Compare 0.385 with the Chebyshev value 2−2=0.25.
Actual errors. Computing on a fine grid: 0.0565 with Chebyshev nodes and 0.0785 with equally spaced nodes. Both below their bounds; Chebyshev is better in the bound and in the truth.
Answer. The Chebyshev bound is e/24≈0.113 against 0.174 for equally spaced nodes; the true largest errors are 0.057 and 0.079. The advantage is modest at n=2 and becomes decisive at large n.
Quick checkWhere do Chebyshev nodes sit on [−1, 1]?
They are the x-coordinates of equally spaced points on a semicircle, and a semicircle is steep near its ends, so the projections crowd there. That is the right place: equally spaced nodes leave w large near the ends, which is where Runge's polynomials swing.Review: Chebyshev nodes
Python labRunge's phenomenon with a plot
import numpy as npimport matplotlib.pyplot as pltf = lambda x: 1 / (1 + 25 * x**2)def interpolate(nodes, x): """Lagrange form: p(x) = sum over j of f(x_j) * l_j(x).""" p = np.zeros_like(x) for j, xj in enumerate(nodes): lj = np.ones_like(x) for k, xk in enumerate(nodes): if k != j: lj *= (x - xk) / (xj - xk) p += f(xj) * lj return px = np.linspace(-1, 1, 2001)cheb = lambda n: np.cos((2 * np.arange(n + 1) + 1) * np.pi / (2 * n + 2))print("degree max error (equally spaced) max error (Chebyshev)")for n in (6, 10, 14, 18): e1 = abs(interpolate(np.linspace(-1, 1, n + 1), x) - f(x)).max() e2 = abs(interpolate(cheb(n), x) - f(x)).max() print(f"{n:<7d} {e1:<27.4f} {e2:.4f}")plt.plot(x, f(x), "k", label="f")plt.plot(x, interpolate(np.linspace(-1, 1, 15), x), label="14 equally spaced")plt.plot(x, interpolate(cheb(14), x), label="14 Chebyshev")plt.ylim(-1, 2); plt.legend()
Try this.The equally spaced errors are 0.617, 1.916, 7.195 and 29.19, growing by a factor of 3 to 4 every 4 degrees, while the Chebyshev errors fall from 0.264 to 0.0225. Change 25 to 1 in f: now both errors collapse towards 0 (0.0068 and 0.0021 at n = 6, below 0.0001 for both at n = 18). The poles of 1/(1 + c x^2) are at plus or minus i over the square root of c, and a pole close to the interval is what hurts. Then try f = np.abs: equally spaced nodes diverge (0.18 at n = 6 to 32.0 at n = 18) while Chebyshev nodes converge slowly (0.087 to 0.0315).
Even Chebyshev nodes are not a universal cure. A theorem of Georg Faber (1914) says that for every fixed scheme of nodes, one set of nodes for each degree n, there is a continuous function whose interpolating polynomials do not converge uniformly; this includes the Chebyshev nodes (label B). What the nodes do buy is convergence for every function smooth enough, and, in practice, stability: the software library Chebfun is built on interpolation at Chebyshev nodes, and NumPy offers it as numpy.polynomial.chebyshev.chebinterpolate.
Newton’s divided differences (Apostol 15.10)
The Lagrange form has a drawback: if you add one more data point, every ℓj changes and you start again. Newton’s form builds the polynomial one node at a time, so that adding a node adds one term.
Definition A
Divided difference
For distinct nodes x0,…,xk, the divided differencef[x0,…,xk] is the leading coefficient (the coefficient of xk) of the interpolating polynomial of degree at most k through (x0,f(x0)),…,(xk,f(xk)). For a single node, f[x0]=f(x0).
In one linef[x0,…,xk] is the coefficient of xk in the interpolating polynomial of f at x0,…,xk. It satisfies f[x0,…,xk]=xk−x0f[x1,…,xk]−f[x0,…,xk−1].
Why it existsIt is the number that corrects the interpolant when a new node is added, and it behaves like a derivative divided by a factorial.
Theorem ANewton 1687; Apostol 15.10
Newton's divided-difference formula
Let x0,…,xn be distinct. Then
pn(x)=k=0∑nf[x0,…,xk]i=0∏k−1(x−xi) (the empty product, for k=0, is 1).
f[x0,…,xk]=xk−x0f[x1,…,xk]−f[x0,…,xk−1] for k≥1.
If f∈Cn on an interval containing the nodes, then f[x0,…,xn]=n!f(n)(ξ) for some ξ in that interval.
In one lineWith pk the interpolant through the first k+1 nodes, pn(x)=∑k=0nf[x0,…,xk](x−x0)⋯(x−xk−1), and the divided differences satisfy the quotient recursion in the definition.
Why it is trueIt gives an algorithm: fill a triangle of differences, read the coefficients off the top edge, and add a node by adding one row.
Proofstandard
The idea: Part 1: the difference between two consecutive interpolants vanishes at the earlier nodes, so it is a multiple of their product. Part 2: build the higher interpolant out of two lower ones and use uniqueness. Part 3: Rolle.
Part 1. The difference pk−pk−1 has the k roots x0,…,xk−1.
pk−pk−1 has degree at most k (both do), and at each node xi with i<k both equal f(xi), so it vanishes there.
pk(x)=pk−1(x)+f[x0,…,xk](x−x0)⋯(x−xk−1).
A polynomial of degree at most k with k known distinct roots is a constant times (x−x0)⋯(x−xk−1). The constant is the coefficient of xk; pk−1 has no xk term, so the constant is the leading coefficient of pk, which is f[x0,…,xk] by definition.
The sum for pn follows.
Add up these equations for k=1,…,n and start from p0=f(x0)=f[x0].
Combine two lower interpolants.
Part 2. Let qa interpolate at x1,…,xk and qb at x0,…,xk−1, both of degree at most k−1. Define q(x)=xk−x0(x−x0)qa(x)−(x−xk)qb(x), of degree at most k.
q interpolates f at all of x0,…,xk.
At x0: q=xk−x00−(x0−xk)f(x0)=f(x0). At xk: q=xk−x0(xk−x0)f(xk)=f(xk). At a middle node xi: both qa and qb equal f(xi), so q=f(xi)xk−x0(xi−x0)−(xi−xk)=f(xi).
f[x0,…,xk]=xk−x0f[x1,…,xk]−f[x0,…,xk−1].
By uniqueness (the existence and uniqueness theorem), q=pk. Compare the coefficients of xk: qa and qb have xk−1 coefficients f[x1,…,xk] and f[x0,…,xk−1], which become the xk coefficient of q after multiplying by x.
f(n)(ξ)=pn(n)(ξ).
Part 3. g=f−pn has the n+1 distinct zeros x0,…,xn. By Rolle's theorem applied n times, g(n) has a zero ξ in the interval.
f[x0,…,xn]=f(n)(ξ)/n!.
pn has leading term f[x0,…,xn]xn, and the n-th derivative of that is n!f[x0,…,xn], a constant.
Part 3 explains the name: a divided difference of order n is a derivative of order n, divided by n!, evaluated at an unknown point. The first one, f[x0,x1]=x1−x0f(x1)−f(x0), is the slope of the chord, and part 3 is the mean value theorem.
Worked example
Build the Newton form of the interpolating polynomial through (1, 2), (2, 3), (4, 9) with a divided-difference table. Then add the point (3, 5) and update.
Solution.
Order-0 column.f[1]=2, f[2]=3, f[4]=9. The data values.
Order-1 column.f[1,2]=2−13−2=1 and f[2,4]=4−29−3=3. The quotient recursion: slope of each chord.
Order-2 entry.f[1,2,4]=4−13−1=32. Same recursion, applied to the two slopes.
Read off the top edge.p2(x)=2+1⋅(x−1)+32(x−1)(x−2). The coefficients are the top diagonal f[x0],f[x0,x1],f[x0,x1,x2].
Expand to check.2+x−1+32(x2−3x+2)=32x2−x+37. The same polynomial as the Lagrange example above, as uniqueness demands.
Add the node (3,5) as x3. New entries: f[4,3]=3−45−9=4, f[2,4,3]=3−24−3=1, f[1,2,4,3]=3−11−32=61. Only a new bottom row of the table is computed; the old entries stay.
Update the polynomial.p3(x)=p2(x)+61(x−1)(x−2)(x−4). Adding a node adds one term. Check at x=3: p2(3)=316 and 61(2)(1)(−1)=−31, giving 5.
Answer.p2(x)=2+(x−1)+32(x−1)(x−2), and p3=p2+61(x−1)(x−2)(x−4). The Lagrange form would have needed all four basis polynomials recomputed.
Your answerFor the data (1, 2), (2, 3), (4, 9), what is the divided difference f[1, 2, 4]?
Divide the difference of the two chord slopes by x₂ − x₀.
f[1,2]=1 and f[2,4]=3, so f[1,2,4]=4−13−1=32. It is also the leading coefficient of 31(2x2−3x+7).
Numerical integration (Apostol 15.19 and 15.20)
Polynomials are easy to integrate, so a natural way to approximate ∫abf is to integrate an interpolant.
Definition A
Quadrature rule
A quadrature rule approximates ∫abf(x)dx by ∑j=0nwjf(xj), with nodes xj and fixed weights wj. If pn=∑jf(xj)ℓj is the interpolant, then ∫abpn=∑jf(xj)∫abℓj, so the weights are wj=∫abℓj(x)dx: the rule integrates the interpolant exactly.
In one lineAn approximation ∫abf≈∑jwjf(xj) by a weighted sum of values at chosen nodes. Integrating the interpolating polynomial gives one.
Why it existsEvaluating f at a handful of points is all a computer can do with a function it has no formula for, so every numerical integral is of this form.
Definition A
Trapezoidal rule
With the two nodes a and b (so n=1), the interpolant is the chord, and its integral is the trapezoidal ruleT=2b−a(f(a)+f(b)).
In one lineT=2b−a(f(a)+f(b)): the area of the trapezoid under the chord from (a,f(a)) to (b,f(b)), which is the integral of the linear interpolant.
Why it existsIt is the simplest quadrature rule, and it is exact for straight lines.
Definition A
Simpson's rule
With the three nodes a, m=2a+b and b (so n=2), the integral of the quadratic interpolant is Simpson’s ruleS=6b−a(f(a)+4f(m)+f(b)).
In one lineS=6b−a(f(a)+4f(m)+f(b)) with m=2a+b: the integral of the quadratic interpolant at a, m, b.
Why it existsFitting a parabola instead of a line gains two orders of accuracy, and by a happy accident the rule is even exact for cubics.
Where does the 61,64,61 come from? Shift the interval to [−h,h] (so b−a=2h and m=0). The Lagrange basis polynomials for the nodes −h,0,h are ℓ−1(t)=2h2t(t−h), ℓ0(t)=h2h2−t2 and ℓ1(t)=2h2t(t+h). Integrating over [−h,h] (odd powers of t integrate to 0): ∫ℓ−1=2h21⋅32h3=3h, ∫ℓ0=h22h3−32h3=34h, ∫ℓ1=3h. So S=3h(f(−h)+4f(0)+f(h)), which is the formula above with b−a=2h.
Lemma Astandard
Cauchy's mean value theorem
Let g,k be continuous on [0,h] and differentiable on (0,h), with k′(t)=0 for 0<t<h. Then k(h)=k(0) and there is τ∈(0,h) with (g(h)−g(0))k′(τ)=(k(h)−k(0))g′(τ).
In one lineIf g,k are continuous on [0,h], differentiable on (0,h) and k′=0 there, then k(h)−k(0)g(h)−g(0)=k′(τ)g′(τ) for some τ∈(0,h).
Why it is trueIt compares how two functions change over the same interval. We use it to read the error of a rule off the derivative of its error.
Proofstandard
The idea: Apply Rolle's theorem to the combination of g and k that has equal end values.
k(h)=k(0).
If k(h)=k(0), Rolle's theorem would give a zero of k′ in (0,h), against the hypothesis.
Let φ(t)=(g(h)−g(0))k(t)−(k(h)−k(0))g(t).
A linear combination of g and k. Both end values come out equal: φ(0)=g(h)k(0)−g(0)k(h)=φ(h).
There is τ∈(0,h) with φ′(τ)=0, which is the claimed equation.
Rolle's theorem for φ, which is continuous on [0,h] and differentiable inside, with φ(0)=φ(h).
Theorem AApostol 15.19 and 15.20; Burden and Faires 4.3
Error of the trapezoidal and Simpson rules
Let f∈C2[a,b] for the first formula and f∈C4[a,b] for the second. Then there are η,η′∈(a,b) with
In one lineOn an interval of width b−a, ∫abf−T=−12(b−a)3f′′(η) and ∫abf−S=−2880(b−a)5f(4)(η) for some η∈(a,b) (a different η in each).
Why it is trueEach error is the next derivative times a power of the width. The trapezoidal rule is exact for lines (f'' = 0), Simpson's for cubics (f'''' = 0).
Proofstandard
The idea: Centre the interval at 0, and let the half-width t grow from 0. The error G(t) of the rule on [-t, t] starts at 0 and has derivatives that are easy: G' for the trapezoid, G', G'' and G''' for Simpson. Cauchy's mean value theorem then expresses G(h) through the last derivative.
Set a=−h, b=h.
Translate so that the interval is [−h,h] with h=(b−a)/2. Integrals and the rules are unchanged by translation.
Define the error as a function of the half-width.
Trapezoid: define G(t)=∫−ttf−t(f(−t)+f(t)) for 0≤t≤h, the error of the rule on [−t,t]. Then G(0)=0 and G(h)=∫f−T.
G′(t)=−t(f′(t)−f′(−t)).
Differentiate: dtd∫−ttf=f(t)+f(−t) (fundamental theorem of calculus, 1.5), and the product rule on t(f(−t)+f(t)). The terms f(t)+f(−t) cancel.
G′(t)=−2t2f′′(ηt).
Mean value theorem for f′ on [−t,t]: f′(t)−f′(−t)=2tf′′(ηt) for some ηt∈(−t,t).
h3G(h)=3τ2G′(τ)=−32f′′(η) with η=ητ∈(−h,h).
Cauchy's mean value theorem with g=G and k(t)=t3 (so k′=3t2=0 on (0,h)), using G(0)=0=k(0).
This is the trapezoidal formula.
G(h)=−32h3f′′(η), and 32h3=12(2h)3=12(b−a)3.
Same plan for Simpson’s rule.
Simpson: define G(t)=∫−ttf−3t(f(−t)+4f(0)+f(t)). Again G(0)=0 and G(h)=∫f−S.
G(0)=G′(0)=G′′(0)=0.
Differentiate three times as before; each time terms cancel. G′(t)=32(f(t)+f(−t))−34f(0)−3t(f′(t)−f′(−t)), so G′(0)=0. Then G′′(t)=31(f′(t)−f′(−t))−3t(f′′(t)+f′′(−t)), so G′′(0)=0.
G′′′(t)=−32t2f(4)(ηt).
G′′′(t)=−3t(f′′′(t)−f′′′(−t)) (the other terms cancel). The mean value theorem for f′′′ gives f′′′(t)−f′′′(−t)=2tf(4)(ηt).
Cauchy's mean value theorem three times, with k(t)=t5, then 5t4, then 20t3, each with the previous function's value 0 at 0: h5G(h)=5t14G′(t1)=20t23G′′(t2)=60t32G′′′(t3) with 0<t3<t2<t1<h.
This is Simpson’s formula.
90h5=32⋅90(2h)5=2880(b−a)5.
Why· The picture behind the proof
For the trapezoid, draw the chord under a convex curve (say x2): the curve bulges below the chord, and the trapezoid overestimates the area. The sign in the formula says this: f′′>0 gives ∫f−T<0. The size of the bulge is controlled by how fast the slope changes, which is f′′, and by (b−a)2 for the height times (b−a) for the width. That is (b−a)3f′′ up to a constant, and 121 is the exact constant. For Simpson, a parabola through three points copies a cubic perfectly (the extra symmetry cancels the cubic term), so the first derivative that can create an error is the fourth.
A single interval is too wide for accuracy. Cut [a,b] into N equal pieces of width h=(b−a)/N and apply the rule to each. Adding up the errors gives the composite rules. In signed form, for continuous f′′, the sum of the N values f′′(ηi) divided by N is itself a value f′′(η) by the intermediate value theorem, so ∫abf−TN=−12(b−a)h2f′′(η). Simpson’s rule gives in the same way ∫abf−SN=−180(b−a)h4f(4)(η′). The theorem below states the absolute bounds, which are what we use.
Theorem AApostol 15.19 and 15.20
Composite trapezoidal and Simpson rules
Let fi=f(a+ih) and Mk=max[a,b]∣f(k)∣. For f∈C2: ∫abf−TN≤12(b−a)h2M2. For f∈C4 and N even: ∫abf−SN≤180(b−a)h4M4.
In one lineWith N pieces of width h: TN=h(21f0+f1+⋯+fN−1+21fN) has error at most 12(b−a)h2M2, and (for N even) SN=3h(f0+4f1+2f2+4f3+⋯+4fN−1+fN) has error at most 180(b−a)h4M4.
Why it is trueHalving h cuts the trapezoid error by 4 and the Simpson error by 16. That is the 'order of the method', and it is what you see in the error table of the PyLab below.
Proofstandard
The idea: Apply the one-interval error to each piece and add. The piece count is N or N/2, and that turns the cubic and fifth power of the width into the square and fourth.
Trapezoid: total error at most 12Nh3M2.
On each of the N pieces (width h) the trapezoid error is 12h3∣f′′(ηi)∣≤12h3M2. Adding N of them: N12h3M2.
=12(b−a)h2M2.
Nh=b−a.
Simpson: total error at most 2N⋅90h5M4.
Simpson's rule uses pairs of pieces: each pair has width 2h (so half-width h), and the error on it is 90h5∣f(4)(ηi)∣ by the theorem with half-width h. There are N/2 pairs.
=180(b−a)h4M4.
Nh=b−a, so 2N⋅90h5=180(b−a)h4.
Worked example
Estimate ∫₀¹ eˣ dx = e − 1 ≈ 1.718282 with the trapezoidal and Simpson rules using 4 pieces. Compare the error with the bound.
Solution.
Set up.h=41, nodes 0,41,21,43,1. Four pieces of width 41.
Trapezoid.T4=41(21e0+e1/4+e1/2+e3/4+21e1)≈1.727222. The weights are 21,1,1,1,21 times h.
Simpson.S4=121(e0+4e1/4+2e1/2+4e3/4+e1)≈1.718319. The weights are 1,4,2,4,1 times h/3.
Actual errors.T4−(e−1)≈0.008940 and S4−(e−1)≈0.000037. Subtract from 1.718282. The trapezoid overestimates because ex is convex.
Bounds.M2=M4=e on [0,1]. Trapezoid: 121⋅(1/16)e≈0.01416. Simpson: 1801⋅(1/256)e≈0.0000590. The composite bounds with b−a=1, h=41.
Answer.T4≈1.7272 (error 0.0089, bound 0.0142) and S4≈1.71832 (error 0.000037, bound 0.000059). With the same four pieces, Simpson is about 240 times more accurate.
Worked example
How many pieces does each rule need to compute ∫₀¹ e^(−x²) dx to within 10⁻⁶?
Solution.
Derivatives.f′′=(4x2−2)e−x2 and f′′′′=(16x4−48x2+12)e−x2. On [0,1] the largest values of ∣f′′∣ and ∣f′′′′∣ are M2=2 and M4=12, both at x=0. Differentiate twice, then twice more. Check the values at 0 directly: −2 and 12.
Trapezoid. Need 121⋅h2⋅2≤10−6, so h2≤6×10−6 and N≥1/(6×10−6)≈408.2, so N=409. h=1/N, and N2≥166667.
Simpson. Need 180h4⋅12≤10−6, so h4≤1.5×10−5 and N4≥66667, giving N≥16.07. N must be even, so N=18. 12/180=1/15.
Truth. The actual errors are 3.7×10−7 for the trapezoid with N=409 and 7.8×10−8 for Simpson with N=18 (already 1.2×10−7 at N=16). The bounds use the worst case of the derivative everywhere and so overestimate.
Answer. The bounds guarantee the trapezoidal rule at N=409 and Simpson’s rule at N=18. Simpson needs about 23 times fewer pieces. The integral is 0.746824…, the area behind the normal curve.
Your answerSimpson's rule with one piece (b − a = 2, nodes 0, 1, 2) for the integral of x⁴ from 0 to 2. What value does it give? (The exact value is 6.4.)
Use (b − a)/6 times f(a) + 4 f(m) + f(b).
S=62(f(0)+4f(1)+f(2))=31(0+4+16)=320≈6.667. The error is 154, and the formula predicts −288025⋅24=−154, with f(4)=24 constant: they agree exactly.
Your answerHow many pieces N does the composite trapezoidal rule need to guarantee an error below 10⁻⁴ for the integral of eˣ over [0, 1]? (M₂ = e.)
Solve (e/12) / N² ≤ 10⁻⁴ for N and round up.
The bound is 12(1)h2e≤10−4 with h=1/N, so N2≥e/(12×10−4)≈2265.2 and N≥47.6. Check: N=47 gives 1.025×10−4 (too big) and N=48 gives 9.83×10−5.
Quick checkYou double the number of pieces N in the composite Simpson rule for a smooth function. By roughly what factor does the error shrink?
The error is proportional to h4, and halving h divides h4 by 24=16. The trapezoidal rule has error proportional to h2, so doubling N divides its error by 4. The PyLab below prints exactly these ratios.Review: composite rules
Python labTrapezoid versus Simpson: the error as the number of pieces doubles
import numpy as npf, a, b, exact = np.exp, 0.0, 1.0, np.e - 1def trapezoid(f, a, b, n): x = np.linspace(a, b, n + 1); h = (b - a) / n return h * (f(x[0]) / 2 + f(x[1:-1]).sum() + f(x[-1]) / 2)def simpson(f, a, b, n): # n must be even x = np.linspace(a, b, n + 1); h = (b - a) / n return h / 3 * (f(x[0]) + 4 * f(x[1:-1:2]).sum() + 2 * f(x[2:-1:2]).sum() + f(x[-1]))print(" n trap error ratio Simpson error ratio")old_t = old_s = Nonefor n in (2, 4, 8, 16, 32, 64): et, es = abs(trapezoid(f, a, b, n) - exact), abs(simpson(f, a, b, n) - exact) rt = f"{old_t / et:6.2f}" if old_t else " " rs = f"{old_s / es:6.2f}" if old_s else " " print(f"{n:<4d} {et:<13.3e} {rt} {es:<14.3e} {rs}") old_t, old_s = et, es
Try this.Look at the ratio columns: each time n doubles the trapezoid error is divided by 4 (ratios 3.99, 4.00, ...) and the Simpson error by 16 (15.65, 15.91, 15.98, ...), as the error bounds predict. Now change f to lambda x: x**3, with exact = 0.25: Simpson's error is 0 up to rounding for every n, because the fourth derivative is 0, while the trapezoid error is exactly 1/(4 n^2).
Beyond the course: for understanding· Why the ratio is exactly 4 (and when it is not)
The Euler summation (Euler–Maclaurin) formula, which Apostol proves in 15.22, refines the trapezoid error to TN−I=12h2(f′(b)−f′(a))−720h4(f′′′(b)−f′′′(a))+⋯. The leading term is proportional to h2, so doubling N divides the error by 4, as long as f′(b)=f′(a). When the slopes at both ends agree, as for a smooth periodic function integrated over a full period, all the terms vanish to every order and the trapezoidal rule converges faster than any power of h. It is the best rule for that case, and the reason the discrete Fourier transform is accurate. The same formula also gives the closed forms of sums such as 12+22+⋯+N2. Apostol also covers the forward difference operator and factorial polynomials (15.11, 15.12): the Newton formula for equally spaced nodes, where every divided difference is a difference divided by a power of h and a factorial.
Rounding: how a computer stores numbers
Everything above was exact arithmetic. A computer stores a number with a fixed number of binary digits, so it works with a finite set of numbers and rounds every result to the nearest one.
Definition B
Floating-point number
A floating-point number with p significant bits is x=±m⋅2e, where m is an integer with 0≤m<2p and e lies between a smallest and a largest value. Numbers of size about 2k are spaced 2k−p+1 apart: the gaps grow with the size, but the gap relative to the number stays between 2−p and 21−p. Rounding any real number x in range to the nearest one gives fl(x)=x(1+δ) with ∣δ∣≤u=2−p. This u is the machine epsilon of 3.5: the largest relative rounding error. The standard model for arithmetic is that each operation is the exact result rounded: fl(x∘y)=(x∘y)(1+δ), ∣δ∣≤u, for ∘∈{+,−,×,÷}.
In one lineA number of the form ±m⋅2e with an integer m having at most p binary digits (the significand) and an exponent e in a fixed range. Every real number inside the range is rounded to the nearest one.
Why it existsIt gives constant relative precision across a huge range of sizes, which is what scientific computing needs, at the price that every operation can be off by a small relative amount.
Format
Bits (sign, exponent, stored fraction)
Significant bits p
u=2−p
Largest number
float64 (double)
1, 11, 52
53
1.1×10−16
1.8×10308
float32 (single)
1, 8, 23
24
6.0×10−8
3.4×1038
float16 (half)
1, 5, 10
11
4.9×10−4
65504
bfloat16
1, 8, 7
8
3.9×10−3
3.4×1038
(The leading binary digit of a non-zero significand is always 1 and is not stored, so p is one more than the stored fraction bits.) The examples below use double precision. Two facts follow at once. A number such as 0.1 has no finite binary expansion, so even storing it rounds: in float64, 0.1+0.2 equals 0.30000000000000004, not 0.3. And once the numbers are large enough the gap between neighbours exceeds 1: in float32, 224=16777216 is the last point where every integer is representable, so 16777216+1 rounds back to 16777216.
Definition B
Catastrophic cancellation
Suppose x~=x(1+δ1) and y~=y(1+δ2) with ∣δi∣≤u. The computed difference has relative error
When x and y are nearly equal, the right side is far larger than u. This is catastrophic cancellation. The factor (∣x∣+∣y∣)/∣x−y∣ is the condition number of the operation (x,y)↦x−y in the sense of 3.5: subtraction of nearly equal numbers is ill-conditioned, however well the subtraction is performed.
In one lineThe loss of most or all correct digits when two nearly equal numbers, each carrying a small rounding error, are subtracted.
Why it existsSubtraction itself is computed exactly, but it exposes errors that earlier steps already made, and the result is small so the same absolute error is a large relative error.
Worked example
Compute (1 − cos x)/x² for x = 10⁻⁸ in double precision. Why is the answer wrong, and how do you fix it?
Solution.
The true value. For small x, cosx=1−2x2+⋯, so (1−cosx)/x2→21. Taylor polynomial of cosine (1.4).
What the computer sees.cos(10−8)=1−5×10−17+⋯. The doubles immediately below 1 are spaced 1.1×10−16 apart, and 5×10−17 is less than half of that gap (5.5×10−17), so the nearest double is 1 itself. The rounding of the cosine has erased the entire difference from 1.
The subtraction.1−cosx evaluates to exactly 0, and the whole expression to 0. The subtraction is exact, but it subtracts a number from the rounded copy of itself.
The cancellation factor. Here (∣1∣+∣cosx∣)/∣1−cosx∣≈2/(5×10−17)=4×1016, and u⋅4×1016≈4: the bound on the relative error is above 1. The formula for cancellation predicts that no digit is guaranteed.
Fix by algebra. Use 1−cosx=2sin2(x/2), so the expression is x22sin2(x/2). The half-angle identity removes the subtraction. sin(x/2) is computed to full relative accuracy.
Evaluate.10−162sin2(5×10−9)=0.5 to about 16 digits. Checked in the PyLab below.
Answer. The naive formula returns 0.0; the rewritten one returns 0.5. The two formulas are equal as mathematics and different as algorithms. This is why library functions such as expm1 and log1p exist: they compute ex−1 and ln(1+x) for small x without cancellation.
Worked example
You estimate the derivative of sin at x = 1 by (sin(1 + h) − sin 1)/h. As h shrinks the error first falls and then rises. Find the best h.
Solution.
Truncation error. By Taylor (1.4), hf(1+h)−f(1)=f′(1)+2hf′′(ξ). So the truncation error is at most 2hM2. It shrinks in proportion to h.
Rounding error. Each computed value of sin carries an error up to about u∣f∣, so the difference carries up to about 2u∣f∣, and dividing by h gives about 2uM0/h. It grows as h shrinks: this is cancellation, since sin(1+h)≈sin1.
Add and minimize.E(h)≈2hM2+h2uM0 is smallest where its derivative is zero: 2M2=h22uM0, so h=2uM0/M2. With M0≈M2≈1 and u≈1.1×10−16: h≈2×10−8. The rule of thumb: the best step is about u≈10−8.
Compare with the computer. The measured errors are 4.2×10−3 at h=10−2, 4.2×10−5 at 10−4, 3.0×10−9 at 10−8, 5.8×10−8 at 10−10, 4.3×10−5 at 10−12 and 3.7×10−3 at 10−14. The first two fall as h; the minimum is near h=10−8; after that rounding dominates.
Answer. The best step is near 10−8, giving about 8 correct digits: half of the 16 available are lost to cancellation. For the central difference 2hf(x+h)−f(x−h) the truncation error is proportional to h2, the best step is near u1/3≈5×10−6, and the best error is near 10−11. This trade-off is why automatic differentiation (3.8) is used for gradients in machine learning instead of finite differences.
Quick checkIn double precision, 1 + 10⁻¹⁷ evaluates to exactly 1. What does that say about u?
The next double above 1 is 1+2.2×10−16, so a number added to 1 is lost if it is below about 1.1×10−16 (half the gap). The addition is correct to the rounding rule; and 10−17 is stored perfectly well on its own.Review: machine epsilon
Your answerx = 1.0000001 and y = 1 are stored with relative error at most u = 1.1×10⁻¹⁶ each. The bound on the relative error of x − y is u(|x| + |y|)/|x − y|. What is it, measured in units of 10⁻⁹? (For example, 3 means 3×10⁻⁹.)
Plug in: u times 2 divided by 1e-7.
∣x∣+∣y∣≈2 and ∣x−y∣=10−7, so the bound is 1.1×10−16×2/10−7=2.2×10−9, which is 2.2 in units of 10−9. Seven of the sixteen digits are gone.
Newton’s method, again (link to 4.2)
In 4.2 Newton’s method xk+1=xk−f(xk)/f′(xk) was shown to be a contraction near a simple root, with the derivative of the iteration map equal to 0 at the root. The Taylor remainder of 1.4 gives the sharper statement.
Theorem Astandard; Burden and Faires 2.3
Newton's method converges quadratically
Let f be twice continuously differentiable near a root r, with f′(xk)=0. Then the Newton step xk+1=xk−f(xk)/f′(xk) satisfies, for some ξk between xk and r,
xk+1−r=2f′(xk)f′′(ξk)(xk−r)2.
In one lineIf f(r)=0, f′(xk)=0 and f is twice differentiable, then xk+1−r=2f′(xk)f′′(ξk)(xk−r)2 for some ξk between xk and r.
Why it is trueThe new error is the square of the old error times a constant. Squaring an error below one doubles the number of correct digits at every step, which is why Newton's method is so fast.
Proofstandard
The idea: Expand f around x_k with Taylor's theorem and evaluate at the root.
0=f(r)=f(xk)+f′(xk)(r−xk)+21f′′(ξk)(r−xk)2.
Taylor's theorem with the Lagrange remainder (1.4), centre xk, order 1, evaluated at r.
Rearrange: f′(xk)f(xk)=(xk−r)−C(xk−r)2 with C=2f′(xk)f′′(ξk).
xk+1−r=C(xk−r)2.
xk+1−r=(xk−r)−f′(xk)f(xk); substitute the line above.
The identity holds at each step, but it does not by itself say that the iteration converges. For that we need the root to be a simple one, f′(r)=0, and f′′ continuous. Then f′ is non-zero near r, so C=f′′(ξk)/(2f′(xk)) is bounded by some number K on an interval [r−δ,r+δ]. Write ek=∣xk−r∣. If x0 lies in that interval and e0<1/K, then ek+1≤Kek2<ek, so every later iterate stays in the interval, and the errors satisfy ek≤(Ke0)2k/K: the exponent doubles at every step. This is quadratic convergence. At a double root (f′(r)=0) the argument fails and Newton’s method only halves the error each step.
Worked example compare the NumCheck in 4.2
Apply Newton's method to f(x) = x² − 2 from x₀ = 3/2. Check the error formula and watch the digits.
Solution.
The step.xk+1=xk−2xkxk2−2=2xk+xk1. f′=2x.
The error formula. Here f′′=2 is constant, so ξk does not matter: xk+1−2=2⋅2xk2(xk−2)2=2xk(xk−2)2. Direct from the theorem. Direct algebra confirms it: 2x+x1−2=2xx2−22x+2.
Read the digits. Correct digits: 1,3,6,12. They double each time, as ek+1≈ek2/(22) predicts.
The floor. In double precision x4=1.414213562373095 is within 2.2×10−16 of 2 (one gap between neighbouring doubles), and x5 is the same number. The computed value of f(xk) is only accurate to about u in relative terms, and so the iteration stops improving at the machine epsilon of 3.5.
Answer. The error formula is exact here, and six digits become twelve become the full 16. Newton’s method converges to roots as fast as a number format allows, so rounding, not the method, is what stops it.
Your answerNewton's method for x² − 2 has e_(k+1) = e_k²/(2 x_k). If x_k is close to √2 and e_k = 10⁻³, about how large is e_(k+1), measured in units of 10⁻⁷? (For example, 3 means 3×10⁻⁷.)
Square the error to get 10⁻⁶, divide by 2 times the root (about 2.83), and then count in units of 10⁻⁷.
ek+1=22(10−3)2=2.82810−6≈3.5×10−7, which is 3.54 in units of 10−7.
Quick checkNewton's method has e_(k+1) ≈ C e_k². After a step the error is 10⁻⁴. Roughly what is it after the next step (C near 1)?
Squaring: (10−4)2=10−8. The number of correct digits doubles from about 4 to about 8. A method that merely halves the error each step (like the bisection method) would give 5×10−5.Review: quadratic convergence
Examples and non-examples
More nodes, worse fit. Interpolating 1/(1+25x2) at equally spaced nodes: the largest error on [−1,1] is 0.62 at n=6 and 29 at n=18. Non-example of the rule “more points means better”.
Smooth is not enough, nodes matter. The same function interpolated at Chebyshev nodes has error 0.26 at n=6 and 0.0225 at n=18. The nodes, not the function, were the problem.
A function that equal spacing handles. For 1/(1+x2) (poles at ±i, farther away) equally spaced interpolation converges: error 0.0068 at n=6, about 0.0001 at n=14 and 0.000015 at n=18.
Exact rules. The trapezoidal rule is exact for lines, Simpson’s for polynomials up to degree three: for ∫02x3dx=4 Simpson with the single piece gives 62(0+4+8)=4 exactly. For x4 it does not (the Simpson NumCheck above gives 320 for the true value 532).
Same function, two algorithms.(1−cosx)/x2 and 2sin2(x/2)/x2 are equal for every x=0 and give 0 and 0.5 at x=10−8.
Where it is used
Used inside maths· Inside maths: Taylor's theorem is interpolation at one repeated node
Let all n+1 nodes slide together onto a single point a. The product w(x)=(x−x0)⋯(x−xn) becomes (x−a)n+1, and the divided difference f[x0,…,xn]=f(n)(ξ)/n! becomes f(n)(a)/n!. The Newton form of the interpolant becomes ∑kk!f(k)(a)(x−a)k, the Taylor polynomial, and the interpolation error formula becomes (n+1)!f(n+1)(ξ)(x−a)n+1, exactly the Lagrange remainder of 1.4. The proof by Rolle’s theorem is the same proof with the zeros all piled on top of each other. So Taylor polynomials are the extreme case of interpolation, with all information gathered at one point, and Chebyshev interpolation is the opposite extreme, with the information spread as evenly as possible.
Used inside maths· Inside maths: Chebyshev polynomials are orthogonal, and the Gram–Schmidt process produces them
Put x=cosθ in ∫−111−x2Tm(x)Tn(x)dx. Then dx=−sinθdθ, 1−x2=sinθ, and TmTn=cosmθcosnθ, so the integral becomes ∫0πcosmθcosnθdθ. By the product formula cosmθcosnθ=21(cos(m−n)θ+cos(m+n)θ), this is 0 for m=n, π/2 for m=n≥1, and π for m=n=0. (Numerical check: the integral for (m,n)=(2,3) is 0 up to rounding, for (3,3) it is 1.5708, and for (0,0) it is 3.1416.) So with the inner product ⟨f,g⟩=∫−11fg/1−x2dx of 2.9, the polynomials T0,T1,T2,… are orthogonal. They are what Gram–Schmidt gives when applied to 1,x,x2,… (up to scaling). Least squares approximation by polynomials in this inner product (2.10) is nearly the best uniform approximation, which is why Chebyshev expansions are used in practice.
Used in the real world· Why machine learning libraries use float32, float16 and bfloat16
A neural network has billions of numbers. Halving the bits per number halves the memory and, on a GPU or TPU, roughly doubles the speed of the matrix multiplications of 2.5. The cost is the unit roundoff in the table above: u=6×10−8 for float32, 4.9×10−4 for float16 and 3.9×10−3 for bfloat16. Three real consequences.
Sums stall. In float32, once a running total reaches 224=16777216, adding 1 does nothing (shown in the PyLab). Adding a long list of small numbers into a float16 accumulator stalls far sooner, at 211=2048. So libraries accumulate dot products in float32 even when the inputs are 16-bit. Micikevicius and colleagues’ paper Mixed Precision Training (ICLR 2018) trains with float16 values and keeps a float32 master copy of the weights and float32 accumulations, so that small updates are not rounded away.
Range. Float16 can only represent numbers between about 6×10−8 and 65504. Small gradients underflow to 0, so the same paper multiplies the loss by a constant (loss scaling) before back-propagation and divides afterwards.
bfloat16. Developed at Google Brain, it keeps float32’s 8 exponent bits (range up to 3.4×1038) and gives up fraction bits (7 stored). Kalamkar and colleagues (2019) found that training with bfloat16 tensors matched float32 results without changing hyperparameters: for training, range matters more than the last few digits.
Notice the connection to this chapter: each low-precision format is a choice of the unit roundoff u, and the question ‘how many digits of the answer survive?’ is answered by the condition number of 3.5.
Used in the real world· Why np.polyfit warns about conditioning at high degree
np.polyfit(x, y, d) finds the degree-d polynomial that fits the data best in least squares (2.10) by solving a linear system whose matrix is the Vandermonde matrix of this chapter. Its columns 1,x,x2,…,xd look more and more alike as d grows, so its condition number explodes. For 21 equally spaced points on [0,1] (degree 20) the Vandermonde matrix has condition number about 9×1016, which is about 1/u: by the rule of thumb of 3.5 (you lose log10κ digits) there are no reliable digits left in the coefficients, and polyfit raises RankWarning: Polyfit may be poorly conditioned. With 50 data points on [0,1], the warning appears at degree 20 and not at degree 15. Rescaling x to [−1,1] already reduces the condition number to about 8×108 for the same 21 points, and using the Chebyshev polynomials as the basis (the numpy.polynomial.chebyshev module) keeps it small at any degree. Two lessons. A high-degree polynomial fit of noisy data oscillates between points for the same reason as Runge’s example. And coefficients in the monomial basis are a bad way to store a polynomial: store the values, or the Chebyshev coefficients.
Python labRounding in action: the surprises of floating point
import numpy as npimport warningsprint(0.1 + 0.2, 0.1 + 0.2 == 0.3)print(np.float32(16777216) + np.float32(1)) # 2**24 + 1 in float32x = 1e-8print((1 - np.cos(x)) / x**2, 2 * np.sin(x / 2)**2 / x**2)print(np.finfo(np.float16).max, np.finfo(np.float32).max, float(np.finfo(np.float64).max))print(np.float16(0.1).item(), np.float32(0.1).item())print("h error of (sin(1+h) - sin(1)) / h as an estimate of cos(1)")for h in (1e-2, 1e-4, 1e-8, 1e-12): print(f"{h:<8g} {abs((np.sin(1 + h) - np.sin(1)) / h - np.cos(1)):.2e}")xs = np.linspace(0, 1, 50); ys = np.sin(2 * np.pi * xs)for d in (10, 15, 20): with warnings.catch_warnings(record=True) as w: warnings.simplefilter("always"); np.polyfit(xs, ys, d) print("polyfit degree", d, "warnings:", [str(i.message) for i in w])
Try this.Read each line against the chapter. 0.1 + 0.2 is not 0.3 (not exactly representable). In float32 adding 1 to 2^24 does nothing. The naive (1 - cos x)/x^2 gives 0.0 and the rewritten one 0.5. The finite-difference error is smallest near h = 1e-8, as computed above. Then change x = 1e-8 to 1e-4 and see that the naive formula is now correct to about 8 digits, because the cancellation is less severe. Note that float16 max prints as 65500.0: NumPy rounds the display, the true value is 65504.
Traps
Watch out· More interpolation nodes do not mean a better fit
With equally spaced nodes the error can grow with the degree (Runge). The error formula has the factor f(n+1)/(n+1)! and the factor max∣w∣. If the first grows faster than the second shrinks, the error grows. Choosing the nodes (Chebyshev) fixes the second factor, and only smoothness of f fixes the first.
Watch out· The point ξ in the error formula is not computable
The theorem says some ξ exists. You cannot solve for it, so the formula gives bounds, never exact errors. The bound uses the maximum of ∣f(n+1)∣ over the whole interval, and is usually several times too large (the true errors in the examples were about 1.5 to 3 times smaller).
Watch out· Simpson's rule needs an even number of pieces, and the weights alternate 4, 2, 4, 2
The composite weights are 1,4,2,4,2,…,4,1 times h/3: each odd node is the middle of a pair and gets 4; each even interior node is shared between two pairs and gets 2. Using 1,4,1 over and over double-counts the shared ends.
Watch out· Order of accuracy is a statement about smooth functions
‘Trapezoid error shrinks 4 times when h halves; Simpson 16 times’ needs f′′ and f(4) to be bounded. For a function with a corner or an integrable singularity the observed ratios are smaller. And the ratios cannot be seen once the error reaches the rounding level 10−16: more pieces then add rounding error instead of removing truncation error.
Watch out· Shrinking the step forever makes finite differences worse
Truncation error falls with h; rounding error grows like u/h. The best step is about u≈10−8 for a forward difference and the best error is not zero. A step of 10−14 is thousands of times worse than 10−8.
Watch out· Never test floating-point numbers for equality, and subtract nearly equal numbers with care
0.1 + 0.2 == 0.3 is False. Compare with a tolerance. A formula that subtracts two nearly equal quantities (the smaller root of a quadratic when b2≫4ac, 1−cosx, x+1−x for large x) should be rewritten algebraically before it is coded.
Watch out· Rounding and truncation are two different errors
Truncation error (replacing f by a polynomial, an integral by a sum) goes to zero as the method is refined. Rounding error does not: it sets a floor. When a result stops improving as you refine, you have reached the floor, and refining further helps nothing.
Problems
check
For the nodes 0,1,3, write the Lagrange basis polynomial ℓ1(x) and find ℓ1(2).
Solution
ℓ1(x)=(1−0)(1−3)(x−0)(x−3)=−2x(x−3). At x=2: −22⋅(−1)=1. (Check: ℓ1(1)=−21⋅(−2)=1 and ℓ1(0)=ℓ1(3)=0.)
check
Find the determinant of the Vandermonde matrix for the nodes 1,2,3,5.
Solution
The product of all differences xj−xi with i<j: (2−1)(3−1)(5−1)(3−2)(5−2)(5−3)=1⋅2⋅4⋅1⋅3⋅2=48.
check
Apply the trapezoidal rule with N=2 pieces to ∫02x2dx. Compare with the exact value and with the error formula.
Solution
h=1, nodes 0,1,2: T2=1⋅(21⋅0+1+21⋅4)=3. The exact value is 38, so the error T2−∫=31. The formula: ∫−T=−12(b−a)h2f′′(η)=−122⋅1⋅2=−31 (here f′′=2 is constant, so the formula is exact).
check
Take one Newton step for x2−3=0 from x0=2. Check it against the error formula.
Solution
x1=2x0+2x03=1+43=1.75. The error is 1.75−3≈0.0179. The formula: 2x0(x0−3)2=4(0.2679)2=0.0179. They agree.
use
Find the Newton form of the polynomial through (0,1), (1,3), (3,13) using divided differences, and evaluate it at x=2.
Solution
f[0,1]=13−1=2, f[1,3]=213−3=5, f[0,1,3]=3−05−2=1. So p(x)=1+2x+1⋅x(x−1)=x2+x+1. At x=2: 7. (Check: p(3)=13.)
use
Bound the error of interpolating sinx on [0,π] at the four equally spaced nodes 0,3π,32π,π. The true largest error is about 0.0436; is your bound consistent?
Solution
n=3, h=π/3, and ∣f(4)∣=∣sin∣≤1=M4. The corollary gives 4⋅4M4h4=16(π/3)4≈161.2026≈0.0752. The true error 0.0436 is below it, so the bound is consistent (and about 1.7 times too large).
use
Use Simpson’s rule with N=4 pieces for ∫0πsinxdx. Compare with the exact value and with the error bound.
Solution
h=π/4. S4=12π(0+4sin4π+2sin2π+4sin43π+0)=12π(42+2)≈12π(7.6569)≈2.00456. The exact value is 2, so the error is 0.00456. The bound: 180(b−a)h4M4=180π(π/4)4≈0.00664. The actual error is below it.
use
The smaller root of x2−108x+1=0 is very close to 10−8. Computing it as (108−1016−4)/2 in double precision gives about 7.45×10−9. Explain the error and give a better formula.
Solution
1016−4≈108−2×10−8, so the subtraction 108−⋅ cancels about 16 digits and leaves the rounding error of the square root (the spacing of doubles near 108 is 1.5×10−8, comparable with the difference 2×10−8 that we are trying to compute). The relative cancellation factor is 2×108/(2×10−8)=1016≈1/u. Fix: the product of the roots is c/a=1, so the small root is 1/rbig with rbig=(108+1016−4)/2, an addition, with no cancellation. This gives 1.0×10−8 to full precision.
prove
Prove that the Lagrange basis polynomials add up to 1: ∑j=0nℓj(x)=1 for every x. Deduce that if f is a polynomial of degree at most n then its interpolant pn equals f.
Solution
The constant function 1 has degree 0≤n and takes the value 1 at every node. By the existence formula, ∑j1⋅ℓj is an interpolating polynomial of degree at most n with these values, and by uniqueness it is equal to the constant 1. For the second part, if f has degree at most n then f itself is a polynomial of degree at most n with f(xj)=f(xj) at every node, so by uniqueness pn=f. (This agrees with the error formula: f(n+1)=0.) ■
prove
Prove that Simpson’s rule on [−h,h] is exact for every cubic polynomial, without using the error theorem.
Solution
A cubic is c0+c1t+c2t2+c3t3, and both sides of the rule are linear in f, so it is enough to test 1,t,t2,t3. Write S=3h(f(−h)+4f(0)+f(h)). For f=1: S=3h⋅6=2h=∫−hh1dt. For f=t: S=3h(−h+0+h)=0=∫tdt. For f=t2: S=3h(h2+0+h2)=32h3=∫t2dt. For f=t3: S=3h(−h3+0+h3)=0=∫t3dt (odd function on a symmetric interval). So the rule is exact for 1,t,t2,t3 and hence for every cubic. By translation the same holds on any interval. ■
prove
Prove that if f′′≥0 on [a,b] (a convex function) then the trapezoidal rule overestimates: T≥∫abf.
Solution
By the error theorem, ∫abf−T=−12(b−a)3f′′(η) for some η∈(a,b). Since f′′(η)≥0 and (b−a)3>0, the right side is ≤0, so ∫abf≤T. ■ (Picture: the chord lies above a convex curve, so the trapezoid under the chord has more area.)
prove
For the Chebyshev nodes x0,…,xn show that w(x)=∏j(x−xj)=Tn+1(x)/2n, and conclude that max[−1,1]∣w∣=2−n.
Solution
The nodes are exactly the n+1 distinct roots of Tn+1, a polynomial of degree n+1. So Tn+1(x)=c∏j(x−xj) where c is the leading coefficient of Tn+1, which is 2n. Hence w=Tn+1/2n. Since ∣Tn+1∣≤1 on [−1,1] with the value ±1 attained (at x=1), max∣w∣=2−n. ■
prove
Newton’s method for x2−a (a>0) is xk+1=21(xk+a/xk). Prove that if x0>0 then xk≥a for all k≥1, and that xk+1≤xk for k≥1. Deduce convergence to a.
Solution
By the arithmetic-geometric mean inequality, 21(x+a/x)≥x⋅a/x=a for any x>0 (equivalently, 21(x+a/x)−a=2x(x−a)2≥0). So xk≥a for k≥1. Then xk−xk+1=21(xk−a/xk)=2xkxk2−a≥0. So (xk)k≥1 is decreasing and bounded below by a; by the monotone convergence theorem (1.2) it converges to a limit L≥a, and passing to the limit in the recursion gives L=21(L+a/L), i.e. L2=a, so L=a. ■
stretch
Find weights w0,w1,w2 so that ∫−11f≈w0f(−1)+w1f(0)+w2f(1) is exact for f=1,t,t2 (the method of undetermined coefficients). Show that the rule is then also exact for t3, and identify it.
Solution
Exactness for 1: w0+w1+w2=2. For t: −w0+w2=0. For t2: w0+w2=32. The last two give w0=w2=31, then w1=2−32=34. This is Simpson’s rule with h=1. For t3: the rule gives 31(−1)+0+31(1)=0, and ∫−11t3=0. It is exact for all cubics, which is one degree more than the three conditions forced. (The method of undetermined coefficients is how rules of higher order are derived.)
stretch
Suppose ek+1≤Kek2 for all k and Ke0≤21. Prove that ek≤K1(21)2k. How many steps until ek<10−16/K?
Solution
Let ak=Kek. Multiplying the hypothesis by K gives ak+1≤ak2. By induction ak≤a02k: true for k=0, and if ak≤a02k then ak+1≤ak2≤a02k+1 (all quantities non-negative). Since a0≤21, ak≤(21)2k, i.e. ek≤K1(21)2k. We need (21)2k<10−16, that is 2k>16log210≈53.2, so k=6 steps (26=64). Six Newton steps from a start with Ke0≤21 reach double precision.
Summary
The interpolating polynomial of degree at most n through n+1 points with distinct nodes exists and is unique. Existence: the Lagrange form∑yjℓj(x). Uniqueness: two interpolants differ by a polynomial with too many roots. The coefficient system has the Vandermonde matrix, with determinant ∏i<j(xj−xi).
The error formula is f(x)−pn(x)=(n+1)!f(n+1)(ξ)∏j(x−xj), proved by Rolle’s theorem applied n+1 times. It is Taylor’s remainder with n+1 centres. Equally spaced nodes give the bound Mn+1hn+1/(4(n+1)).
Runge’s phenomenon: for 1/(1+25x2) the equally spaced interpolation error grows with n (from 0.6 at n=6 to 29 at n=18). Chebyshev nodescos2n+2(2k+1)π make max∣w∣=2−n, the smallest possible (Chebyshev’s minimal property), and the error shrinks.
Newton’s form adds one divided difference per node and works as a table. A divided difference of order n equals f(n)(ξ)/n!. Taylor’s polynomial is the case of one repeated node.
Quadrature integrates the interpolant. The trapezoidal rule has error −12(b−a)3f′′(η) and Simpson’s −2880(b−a)5f(4)(η); composite versions have errors proportional to h2 and h4, so doubling the pieces divides the error by 4 and 16.
A floating-point number has p significant bits and unit roundoff u=2−p (1.1×10−16 in double). Every operation is correct up to a factor 1+δ, ∣δ∣≤u. Subtracting nearly equal numbers (catastrophic cancellation) multiplies the relative error by (∣x∣+∣y∣)/∣x−y∣. Truncation error shrinks with the method, rounding error sets a floor.
Newton’s method has xk+1−r=2f′(xk)f′′(ξ)(xk−r)2: quadratic convergence, correct digits double each step, until rounding stops it.
Used: the choice of float32, float16 or bfloat16 in machine learning, the conditioning warning of np.polyfit, finite-difference step sizes, and, inside maths, Taylor’s theorem as repeated-node interpolation and Chebyshev polynomials as an orthogonal family.
Watch and read
The same ideas explained by someone else. Use these when an explanation here does not land.
MATH 375 / 376: Apostol's chapter 15 is the one chapter of his Vol. 2 that the course never reached. Its idea, replace a function by a polynomial through points and bound the error with Rolle's theorem, is the same idea as Taylor's theorem with the remainder of 1.4.
CS 240 / CS 400: Floating-point numbers, and why 0.1 + 0.2 is not 0.3, are a standard topic of a computer-organization or numerical-methods course. The error formula here tells you how fast interpolation and quadrature converge; the rounding section tells you where convergence stops.
MATH 521 / MATH 321: The Weierstrass approximation theorem says polynomials can approximate any continuous function. Runge's phenomenon shows that interpolating polynomials need not. Courses on numerical linear algebra (Trefethen and Bau) and on the finite element method build on the same error formulas.
CS 532 / AI: Deep learning libraries store numbers in float32, float16 or bfloat16, and mixed precision training is a rounding-error analysis in disguise. np.polyfit warning about conditioning at high degree is the Vandermonde matrix of this chapter meeting the condition number of 3.5.