Unit 10, lesson 127

Approximating Using Taylor’s Formula

How Taylor polynomials with a remainder bound give function values and integrals to a guaranteed accuracy, and how to pick the center and the degree to meet a given tolerance.

  • Theory part 253
  • Practice part 254
  • Approximation with Series

Before computers, tables of sin⁡x\sin x, exe^x and ln⁡x\ln x were filled in by hand, and the people who computed them needed to know every digit was right. Taylor’s formula gives both halves of that job. The polynomial gives the number, and the remainder term says how far off it can be. The same idea, integrated term by term, handles integrals that have no elementary antiderivative.

Key terms

Taylor’s formula with remainder

Definition Let n≥0n \ge 0 be an integer and let ff be n+1n + 1 times differentiable on an open interval II containing aa. For each xx in II,

f(x)=Pn(x)+Rn(x),Pn(x)=∑k=0nf(k)(a)k!(x−a)k,f(x) = P_n(x) + R_n(x), \qquad P_n(x) = \sum_{k=0}^{n} \frac{f^{(k)}(a)}{k!} (x - a)^k,

and there is a number ξ\xi strictly between aa and xx (or ξ=a\xi = a when x=ax = a) with

Rn(x)=f(n+1)(ξ)(n+1)!(x−a)n+1.R_n(x) = \frac{f^{(n+1)}(\xi)}{(n+1)!} (x - a)^{n+1}.

Consequently, if ∣f(n+1)(t)∣≤M\lvert f^{(n+1)}(t) \rvert \le M for every tt between aa and xx, then

∣Rn(x)∣≤M∣x−a∣n+1(n+1)!.\lvert R_n(x) \rvert \le \frac{M \lvert x - a \rvert^{n+1}}{(n+1)!}.

This is Taylor’s inequality.

In plain words The Taylor polynomial is the best polynomial match at aa, and the remainder is the exact error. You rarely know ξ\xi, but bounding the derivative bounds the error.

Example For f(x)=exf(x) = e^x at a=0a = 0, every derivative is exe^x, so

P2(x)=1+x+x22,R2(x)=eξ6x3P_2(x) = 1 + x + \frac{x^2}{2}, \qquad R_2(x) = \frac{e^{\xi}}{6} x^3

for some ξ\xi between 00 and xx.

Evaluating functions with Taylor polynomials

Definition To evaluate f(x)f(x) with a Taylor polynomial, compute Pn(x)P_n(x) and report it together with a bound BB on ∣Rn(x)∣\lvert R_n(x) \rvert from Taylor’s inequality, so that

Pn(x)−B≤f(x)≤Pn(x)+B.P_n(x) - B \le f(x) \le P_n(x) + B.

In plain words You get the approximate value and a guarantee in one step. The answer is an interval that must contain the true value.

Example Approximate e0.1e^{0.1} with n=3n = 3 and a=0a = 0. The polynomial gives

P3(0.1)=1+0.1+0.005+0.0016≈1.1051667.P_3(0.1) = 1 + 0.1 + 0.005 + \frac{0.001}{6} \approx 1.1051667.

On [0,0.1][0, 0.1] the fourth derivative satisfies f(4)(t)=et≤e0.1<1.2f^{(4)}(t) = e^t \le e^{0.1} < 1.2, so

∣R3(0.1)∣≤1.2⋅0.1424=5×10−6.\lvert R_3(0.1) \rvert \le \frac{1.2 \cdot 0.1^4}{24} = 5 \times 10^{-6}.

The true value is e0.1≈1.1051709e^{0.1} \approx 1.1051709, and the actual error 4.3×10−64.3 \times 10^{-6} is within the bound.

Taylor-based quadrature

Definition To approximate ∫cdf(x) dx\int_c^d f(x) \, dx, expand ff in a Taylor polynomial PnP_n about a point aa, where [c,d][c, d] lies inside an open interval II containing aa on which ff is n+1n + 1 times differentiable, and integrate the polynomial exactly. Since f=Pn+Rnf = P_n + R_n on II,

∫cdf(x) dx=∫cdPn(x) dx+∫cdRn(x) dx.\int_c^d f(x) \, dx = \int_c^d P_n(x) \, dx + \int_c^d R_n(x) \, dx.

The first integral is the approximation. The second is its error. When ff is the sum of a power series about aa and [c,d][c, d] lies inside the open interval of convergence, the series may be integrated term by term over [c,d][c, d] instead.

In plain words Polynomials are easy to integrate. Replace the hard integrand by its Taylor polynomial and integrate that.

Example Approximate ∫01/2e−x2 dx\int_0^{1/2} e^{-x^2} \, dx, which has no elementary antiderivative. Put u=−x2u = -x^2 in eu=1+u+u22+…e^{u} = 1 + u + \frac{u^2}{2} + \dots and keep three terms.

∫01/2(1−x2+x42)dx=12−124+1320≈0.4614583.\int_0^{1/2} \left( 1 - x^2 + \frac{x^4}{2} \right) dx = \frac{1}{2} - \frac{1}{24} + \frac{1}{320} \approx 0.4614583.

The full series integrates to an alternating series whose terms decrease to 00, so the error is at most the first omitted term,

(1/2)76⋅7≈1.86×10−4.\frac{(1/2)^7}{6 \cdot 7} \approx 1.86 \times 10^{-4}.

The true value is about 0.46128100.4612810, an error of 1.77×10−41.77 \times 10^{-4}.

Integrated remainder bound

Definition Suppose Taylor’s formula holds on an interval containing [c,d][c, d]. If ∣Rn(x)∣≤ρ(x)\lvert R_n(x) \rvert \le \rho(x) for all xx in [c,d][c, d] and ρ\rho is integrable on [c,d][c, d], then

∣∫cdf(x) dx−∫cdPn(x) dx∣=∣∫cdRn(x) dx∣≤∫cdρ(x) dx.\left\lvert \int_c^d f(x) \, dx - \int_c^d P_n(x) \, dx \right\rvert = \left\lvert \int_c^d R_n(x) \, dx \right\rvert \le \int_c^d \rho(x) \, dx.

With Taylor’s inequality one can take

ρ(x)=M∣x−a∣n+1(n+1)!,\rho(x) = \frac{M \lvert x - a \rvert^{n+1}}{(n+1)!},

where MM bounds ∣f(n+1)∣\lvert f^{(n+1)} \rvert on the smallest closed interval containing both aa and [c,d][c, d].

In plain words Bound the error at each point, then integrate the bound. This works whether or not the series alternates.

Example Approximate ∫01sin⁡xx dx\int_0^1 \frac{\sin x}{x} \, dx, where the integrand is defined as 11 at x=0x = 0. For sin⁡x\sin x about 00 the polynomials P5P_5 and P6P_6 are both x−x36+x5120x - \frac{x^3}{6} + \frac{x^5}{120}, and ∣sin⁡(7)∣≤1\lvert \sin^{(7)} \rvert \le 1, so ∣R6(x)∣≤∣x∣75040\lvert R_6(x) \rvert \le \frac{\lvert x \rvert^7}{5040}. Dividing by x>0x > 0 gives

∣sin⁡xx−(1−x26+x4120)∣≤x65040,\left\lvert \frac{\sin x}{x} - \left( 1 - \frac{x^2}{6} + \frac{x^4}{120} \right) \right\rvert \le \frac{x^6}{5040},

which also holds at x=0x = 0. Integrating over [0,1][0, 1] gives the approximation

1−118+1600≈0.9461111 - \frac{1}{18} + \frac{1}{600} \approx 0.946111

with error at most

∫01x65040 dx=135280≈2.83×10−5.\int_0^1 \frac{x^6}{5040} \, dx = \frac{1}{35280} \approx 2.83 \times 10^{-5}.

The true value is about 0.9460830.946083, an error of 2.80×10−52.80 \times 10^{-5}.

Expansion center

Definition The expansion center is the point aa about which PnP_n is built. It must lie in an open interval on which ff has the required derivatives, and the values f(k)(a)f^{(k)}(a) must be known exactly or cheaply. Because the remainder bound contains the factor ∣x−a∣n+1\lvert x - a \rvert^{n+1}, a center close to xx gives a smaller error for the same degree.

In plain words Expand around a nearby point where you already know the function exactly.

Example To approximate 4.1\sqrt{4.1}, a center at 00 is useless because x\sqrt{x} is not differentiable there. Center at a=4a = 4, where 4=2\sqrt{4} = 2. With f′(x)=12x−1/2f'(x) = \frac{1}{2}x^{-1/2} and f′′(x)=−14x−3/2f''(x) = -\frac{1}{4}x^{-3/2},

P2(x)=2+x−44−(x−4)264,P2(4.1)=2.02484375.P_2(x) = 2 + \frac{x - 4}{4} - \frac{(x - 4)^2}{64}, \qquad P_2(4.1) = 2.02484375.

On [4,4.1][4, 4.1] the third derivative satisfies

f′′′(t)=38t−5/2≤38⋅4−5/2=3256,f'''(t) = \frac{3}{8} t^{-5/2} \le \frac{3}{8} \cdot 4^{-5/2} = \frac{3}{256},

so the error is at most 3256⋅0.136≈1.95×10−6\frac{3}{256} \cdot \frac{0.1^3}{6} \approx 1.95 \times 10^{-6}. In fact 4.1≈2.02484567\sqrt{4.1} \approx 2.02484567, off by 1.92×10−61.92 \times 10^{-6}.

Polynomial degree

Definition For a fixed center aa and point xx, the degree nn of PnP_n is the highest power of (x−a)(x - a) allowed in it. To meet a target error, choose the smallest nn whose remainder bound

Mn+1∣x−a∣n+1(n+1)!\frac{M_{n+1} \lvert x - a \rvert^{n+1}}{(n+1)!}

is small enough, where Mn+1M_{n+1} bounds ∣f(n+1)∣\lvert f^{(n+1)} \rvert between aa and xx. The guarantee comes from the bound, so a degree that happens to give a small actual error without a bound to show it is not guaranteed.

In plain words More terms usually means a better answer, and the factorial in the bound tells you how many terms are enough.

Example Approximate e=e1e = e^1 with center 00 within 10−610^{-6}. Here ∣f(n+1)(t)∣=et≤e<3\lvert f^{(n+1)}(t) \rvert = e^t \le e < 3 on [0,1][0, 1], so you need

3(n+1)!≤10−6,that is(n+1)!≥3×106.\frac{3}{(n+1)!} \le 10^{-6}, \quad \text{that is} \quad (n+1)! \ge 3 \times 10^6.

Since 9!=3628809! = 362880 and 10!=362880010! = 3628800, take n=9n = 9. Then P9(1)≈2.7182815P_9(1) \approx 2.7182815 with actual error 3.0×10−73.0 \times 10^{-7}. With n=8n = 8 the error is 3.1×10−63.1 \times 10^{-6}, too large.

Error tolerance

Definition An error tolerance is a number τ>0\tau > 0 that the error must not exceed. An approximation AA of a quantity QQ meets an absolute tolerance τ\tau if ∣Q−A∣≤τ\lvert Q - A \rvert \le \tau, and a relative tolerance τ\tau if ∣Q−A∣≤τ∣Q∣\lvert Q - A \rvert \le \tau \lvert Q \rvert. To certify a Taylor approximation, show that the remainder bound is at most τ\tau.

In plain words The tolerance is the accuracy you were asked for. You are done when your error bound, not your hope, is below it.

Example Find ln⁡(1.1)\ln(1.1) within τ=10−5\tau = 10^{-5} using f(x)=ln⁡(1+x)f(x) = \ln(1 + x) at a=0a = 0. Here

f(n+1)(t)=(−1)nn!(1+t)n+1,f^{(n+1)}(t) = \frac{(-1)^n n!}{(1 + t)^{n+1}},

so for 0≤t≤x0 \le t \le x we get

∣Rn(x)∣≤n!(n+1)!xn+1=xn+1n+1.\lvert R_n(x) \rvert \le \frac{n!}{(n+1)!} x^{n+1} = \frac{x^{n+1}}{n+1}.

At x=0.1x = 0.1 the choice n=3n = 3 gives 10−44=2.5×10−5\frac{10^{-4}}{4} = 2.5 \times 10^{-5}, too big, while n=4n = 4 gives 10−55=2×10−6\frac{10^{-5}}{5} = 2 \times 10^{-6}. So

ln⁡(1.1)≈0.1−0.012+0.0013−0.00014≈0.0953083,\ln(1.1) \approx 0.1 - \frac{0.01}{2} + \frac{0.001}{3} - \frac{0.0001}{4} \approx 0.0953083,

and the true value 0.09531020.0953102 is indeed within 10−510^{-5}.

Check yourself

  1. Approximate cos⁡(0.2)\cos(0.2) by 1−x221 - \frac{x^2}{2} and bound the error.
Show the answer

The approximation is 1−0.02=0.981 - 0.02 = 0.98. For cosine P2=P3P_2 = P_3, and ∣cos⁡(4)∣≤1\lvert \cos^{(4)} \rvert \le 1, so the error is at most

0.2424≈6.7×10−5.\frac{0.2^4}{24} \approx 6.7 \times 10^{-5}.

In fact cos⁡0.2≈0.980067\cos 0.2 \approx 0.980067.

  1. What degree nn of the Taylor polynomial for sin⁡x\sin x about 00 guarantees sin⁡1\sin 1 within 10−410^{-4}?
Show the answer

Every derivative of sin⁡\sin is bounded by 11, so ∣Rn(1)∣≤1(n+1)!\lvert R_n(1) \rvert \le \frac{1}{(n+1)!}. You need (n+1)!≥104(n+1)! \ge 10^4. Since 7!=50407! = 5040 and 8!=403208! = 40320, take n=7n = 7, giving

1−16+1120−15040≈0.841468.1 - \frac{1}{6} + \frac{1}{120} - \frac{1}{5040} \approx 0.841468.
  1. Use cos⁡u≈1−u22\cos u \approx 1 - \frac{u^2}{2} to approximate ∫01/2cos⁡(x2) dx\int_0^{1/2} \cos(x^2) \, dx and bound the error.
Show the answer

The approximation is

∫01/2(1−x42)dx=12−(1/2)510=0.496875.\int_0^{1/2} \left( 1 - \frac{x^4}{2} \right) dx = \frac{1}{2} - \frac{(1/2)^5}{10} = 0.496875.

Since ∣cos⁡u−(1−u22)∣≤u424\lvert \cos u - (1 - \frac{u^2}{2}) \rvert \le \frac{u^4}{24}, the integrand error is at most x824\frac{x^8}{24}, and

∫01/2x824 dx=(1/2)9216≈9.0×10−6.\int_0^{1/2} \frac{x^8}{24} \, dx = \frac{(1/2)^9}{216} \approx 9.0 \times 10^{-6}.

How this lesson connects

It also uses remainder bounds.

Resources for this lesson