LeoMath

Foundations of calculus · Section 5 of 5

Taylor expansion

Approximating functions by polynomials, with error control.

about 9 min

Start from a problem

Problem

A calculator can only add, subtract, multiply and divide. How does it compute sin⁡(0.3) or e0.3?

We need a way to approximate any smooth function by expressions using only those four operations (polynomials), and we must be able to say how large the error is; otherwise the approximation is worthless.

Observe

How does a calculator compute sin⁡(0.3)? It can only add, subtract, multiply and divide. But near 0:

sin⁡x≈x,sin⁡x≈x−x36,sin⁡x≈x−x36+x5120.

At x=0.3 these give 0.3, 0.2955, 0.295520, while the true value is 0.295520…. The longer the polynomial, the better the approximation.

Conjecture

If a polynomial p is to "look like" f near x0, the natural demand is that its value, slope, curvature, … at x0 all agree with those of f: p(k)(x0)=f(k)(x0) for k=0,1,…,n. Such a polynomial is unique, and the error should shrink as n grows.

Interactive experimentTaylor approximation
Function
Pn(x)=∑k=0nf(k)(a)k!(x−a)kmax error on [a−2, a+2] 0.2426

What did you observe?Play first, then answer. Read the explanation only after you have thought it through.

  1. 1.As n increases, what happens near the centre a?
  2. 2.As a changes, how does the region of best approximation move?
  3. 3.Why does raising the order not necessarily improve the approximation far away? Try 1/(1−x) at x = 1.5.

Definition

Definition 5.1Taylor polynomial

Let f have n derivatives at x0. The polynomial

Pn(x)=∑k=0nf(k)(x0)k!(x−x0)k

is the n-th Taylor polynomial of f at x0, and Rn(x)=f(x)−Pn(x) is the remainder.

Why f(k)(x0)k!? Differentiate Pn k times and set x=x0: of the terms (x−x0)j, only j=k survives, contributing k!. So Pn(k)(x0)=f(k)(x0), exactly the demand in the conjecture.

Theorem and proof

Polynomials are easy to evaluate, but an approximation without an error bound is meaningless. The theorem gives the error exactly.

Theorem 5.1Taylor's theorem (Lagrange remainder)

Let f have n+1 derivatives on an interval containing x0 and x. Then there is ξ between x0 and x with

Rn(x)=f(n+1)(ξ)(n+1)!(x−x0)n+1.
Proof

Fix x≠x0 and choose M with f(x)−Pn(x)=M(x−x0)n+1. Define

g(t)=f(t)−Pn(t)−M(t−x0)n+1.

Then g(x0)=g′(x0)=⋯=g(n)(x0)=0 (since Pn matches f to order n at x0 and the first n derivatives of (t−x0)n+1 vanish there) and g(x)=0.

By Rolle's theorem g has a zero ξ1 between x0 and x; then g′ vanishes at x0 and ξ1, so has a zero ξ2; after n+1 steps, g(n+1)(ξn+1)=0. Since Pn(n+1)≡0 and ((t−x0)n+1)(n+1)=(n+1)!,

g(n+1)(ξ)=f(n+1)(ξ)−M(n+1)!=0 ⇒ M=f(n+1)(ξ)(n+1)!.
Example 5.1Bounding an error with the remainder

Approximate cos⁡x by 1−x22 for |x|≤0.5. This polynomial is in fact P3 (the x3 coefficient is zero), so

|R3(x)|=|cos(4)⁡(ξ)4!x4|≤0.5424≈0.0026.
Definition 5.2Taylor series

If f is infinitely differentiable at x0, ∑k=0∞f(k)(x0)k!(x−x0)k is its Taylor series. The series converges to f(x) if and only if Rn(x)→0.

Proposition 5.2The series of e^x, sin, cos converge to them everywhere
ex=∑k=0∞xkk!,sin⁡x=∑k=0∞(−1)kx2k+1(2k+1)!,cos⁡x=∑k=0∞(−1)kx2k(2k)!.
Proof

All derivatives of these functions are uniformly bounded on any bounded interval (the derivative of ex is itself; those of sin⁡,cos⁡ have absolute value at most 1). Fix x and let C=max|ξ|≤|x|⁡|f(n+1)(ξ)| (e|x| for ex, 1 for sin⁡,cos⁡). Then

|Rn(x)|≤C|x|n+1(n+1)!→0,

because |x|nn!→0 (from some point on each term is multiplied by a factor below 12).

Try it in the plotter →

Remark

Not every Taylor series converges to its function. f(x)=e−1/x2 with f(0)=0 has all derivatives equal to 0 at 0; its Taylor series is identically 0, yet f is not. The remainder Rn(x)=f(x) never tends to 0. The clause "if and only if Rn→0" in the definition is not decoration.

Common mistake

A Taylor series converging is not the same as converging to f. For f(x)=e−1/x2 (with f(0)=0) the series converges everywhere (to 0) yet equals f only at x=0. The only way to know "series = function" is to prove the remainder Rn→0.

Applications

ApplicationWhere numerical error comes from

In Numerical solutions, Euler's method has local error O(h2) and RK4 has O(h5). All such statements come from expanding the true solution y(t+h) in a Taylor series and comparing it term by term with the numerical scheme.

ApplicationEuler's formula

Splitting the series of eiθ into real and imaginary parts gives eiθ=cos⁡θ+isin⁡θ. This is why complex characteristic roots produce trigonometric solutions in Second-order linear equations.

Exercises

0 of 2 done

1
In the Taylor series of sin⁡x at 0, what is the coefficient of x3 (four decimals)?

Decimals or fractions; anything within 0.00006 of the answer counts as correct.

2
Approximating cos⁡x by 1−x22 for |x|≤0.5, the sharpest bound the Lagrange remainder gives on the error is approximately
Answer to exercise 2

Discussion

Found a mistake, have a question or a suggestion? You can also write to 620026600@qq.com

No comments yet. Share your understanding, ask a question, or point out an error on this page.

Log in to join the discussion