A637 of 55
0 XP
  1. Hook
  2. Play
  3. Predict
  4. Name it
  5. Check
  6. Explain

A6 · Lesson 37 · Taylor's remainder

How many terms are enough?

A math library computing sin⁡x for single-precision floats needs about seven correct digits. It can't check its answer against the true value, because it doesn't have the true value; that's what it's computing. It needs a guarantee in advance: this many terms always gets within 10−7 on this range. Taylor's theorem gives that guarantee. It says exactly what the error of a Taylor polynomial is, in a form you can bound without knowing the answer.

  • The blue curve is sin⁡x; the other is its Taylor polynomial of degree N about 0.
  • Raise N. The polynomial hugs sin⁡x over a wider and wider range.
  • At x0, the readouts show the actual error and the bound from Taylor's theorem. Is the actual error ever bigger than the bound?

Predict

Every derivative of sin⁡x is ±sin⁡x or ±cos⁡x, so none is ever bigger than 1 in size. What does that suggest about the error of its Taylor polynomials?

Name it

Taylor's theorem

If f has n+1 derivatives near a, then f(x)=Tn(x)+Rn(x), where Tn is the Taylor polynomial of degree n and the remainder is

Rn(x)=f(n+1)(ξ)(n+1)!(x−a)n+1

for some ξ between a and x. The remainder looks like the next term of the series, with the derivative evaluated at an unknown point ξ instead of at a.

The bound you can use

You don't know ξ, but if |f(n+1)|≤M everywhere between a and x, then

|Rn(x)|≤M(n+1)!|x−a|n+1

For sin⁡ and cos⁡, M=1. For ex on [0,b], M=eb (use 3 for e1 if you like round numbers).

Even and odd functions get a bonus

The degree-3 polynomial of sin⁡x is also its degree-4 polynomial, since the x4 term is zero. So you may use the remainder R4, giving the bound |x|55! instead of |x|44!. That's why the sim uses N+2.

Keep x small

The bound grows like |x−a|n+1, so libraries first reduce the range: using sin⁡(x+2π)=sin⁡x and other identities, they bring x into [−π4,π4] or so, where a short polynomial is enough.

Worked example

Bound the error of e0.5≈1+0.5+0.522.

Show the solution
  1. Write the remainder. This is T2, so the remainder is eξ3!(0.5)3 with 0<ξ<0.5.
  2. Bound it. Since eξ<e0.5<2, |R2|<26(0.125)=0.042
  3. Compare. The estimate is 1.625 and the true value is 1.6487, so the actual error is 0.024, inside the bound.

Answer the error is less than 0.042; the actual error is 0.024.

Worked example

What degree does a sine polynomial need for an error below 10−7 on [−π2,π2]?

Show the solution
  1. Write the bound. For an odd degree N, the bound is (π/2)N+2(N+2)!
  2. Try degree 9. (π/2)1111!=3.6×10−6 which is not enough.
  3. Try degree 11. (π/2)1313!=5.7×10−8 which is below 10−7.
  4. What libraries do. Real libraries do better by reducing to [−π4,π4] and fine-tuning the coefficients, but this is the principle.

Answer degree 11, which is six nonzero terms.

Worked example

Estimate ln⁡1.2 with the degree-3 Taylor polynomial about 1, and bound the error.

Show the solution
  1. Add three terms. Use ln⁡(1+h)≈h−h22+h33 with h=0.2: ln⁡1.2≈0.2−0.02+0.002667=0.18267
  2. Bound the remainder. It is f(4)(c)4!h4 with f(4)=−6/c4, at most 6 for c≥1: 624×0.0016=0.0004
  3. Compare. The true value is 0.182 32, so the actual error, 0.000 35, is just inside the bound.

Answer ln⁡1.2≈0.18267, with an error of at most 0.0004.

Check

You approximate e0.5 with its Taylor polynomial of degree 3 about 0. Using M=3 as a bound on eξ, what is the error bound?

Check

You approximate sin⁡0.5 with its Taylor polynomial of degree 3. Using the bonus for odd functions, what is the error bound?

Check

You compute e=e1 from its Taylor polynomial about 0, using the bound 3(n+1)!. What is the smallest degree n that guarantees an error below 0.001?

Check

What is the actual error of cos⁡0.5≈1−x22? (Use a calculator for cos⁡.)

Check

For x>0, 1+x≈1+x2. The second derivative is −14(1+ξ)−3/2, which is at most 14 in size. What is the error bound at x = 0.2?

Check

Why does the Taylor series for ex converge for every x, even x=100?

Check

Estimate ln⁡(1+0.2) with the degree-3 Taylor polynomial about 1.

(a)

What does it give?

(b)

What does the Lagrange remainder bound the error by? (|f(4)|=6/c4≤6.)

Check

Bound the Taylor error of the degree-3 polynomial for ex on [0,1].

Step 1

The remainder after degree 3 is f(4)(c)4!x4. What is the largest f(4)(c) can be for c in [0,1]?

Type it the way you would write it, like 3sin(2πft) or 3*sin(2*pi*f*t). Angles can be in radians or carry a degree sign, like 45°.

Explain why

A Taylor polynomial is very accurate near its center and poor far away. Use the remainder formula to explain why.

Practice

Keep practicing

9 kinds of problem on this topic, dealt one at a time with new numbers every time, for as long as you like.