TExcelTAD
Home › Calculus in Depth › Taylor and Maclaurin Series

Taylor and Maclaurin Series

If a function has a power series at all, its coefficients are forced: they are its derivatives at the centre divided by n!n!. This lesson proves that, proves with Taylor's inequality that exe^x, sin⁡x\sin x and cos⁡x\cos x really equal their series, shows a smooth function that does not, and builds the standard table of series.

A first look with pictures is in Taylor and Maclaurin Series.

The coefficients are forced

Theorem. If f(x)=∑cn(x−a)nf(x) = \sum c_n(x - a)^n for ∣x−a∣<R\lvert x - a \rvert < R, then

cn=f(n)(a)n!c_n = \frac{f^{(n)}(a)}{n!}

Proof. Put x=ax = a: f(a)=c0f(a) = c_0. Differentiate term by term (allowed inside the radius, see Representations of Functions as Power Series) and put x=ax = a again: f′(a)=c1f'(a) = c_1. After kk differentiations, the term ck(x−a)kc_k(x - a)^k becomes k!⋅ckk! \cdot c_k, lower terms have vanished and higher terms still contain a factor (x−a)(x - a), so f(k)(a)=k!⋅ckf^{(k)}(a) = k! \cdot c_k. ∎

The resulting series ∑n=0∞f(n)(a)n!(x−a)n\sum_{n=0}^{\infty} \frac{f^{(n)}(a)}{n!}(x - a)^n is the Taylor series of ff at aa; with a=0a = 0 it is the Maclaurin series. A corollary: a function has at most one power series at each centre, so any trick that produces a series (substitution, integration, multiplication) gives the Taylor series.

Does the series equal the function?

The theorem only says: if ff has a series, this is it. Write

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

ff equals its Taylor series at xx exactly when the remainder Rn(x)→0R_n(x) \to 0. The tool for showing that:

Taylor's theorem (Lagrange form). If ff has n+1n + 1 derivatives between aa and xx, then for some zz between aa and xx

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

Taylor's inequality. Consequently, if ∣f(n+1)∣≤M\lvert f^{(n+1)} \rvert \le M 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)!}

Proof sketch of the inequality for n=1n = 1, a<xa < x. From ∣f′′(t)∣≤M\lvert f''(t) \rvert \le M, integrate from aa to tt: ∣f′(t)−f′(a)∣≤M(t−a)\lvert f'(t) - f'(a) \rvert \le M(t - a). Integrate again from aa to xx: ∣f(x)−f(a)−f′(a)(x−a)∣≤M(x−a)2/2\lvert f(x) - f(a) - f'(a)(x - a) \rvert \le M(x - a)^2/2. Repeating the integration n+1n + 1 times gives the general case. The Lagrange form follows similarly from the Mean Value Theorem (see The Mean Value Theorem).

exe^x equals its series for every xx

Every derivative of exe^x is exe^x, so cn=1/n!c_n = 1/n! and the Maclaurin series is ∑xn/n!\sum x^n/n!. Fix xx and a bound d≥∣x∣d \ge \lvert x \rvert. Between 0 and xx, ∣f(n+1)(z)∣=ez≤ed=M\lvert f^{(n+1)}(z) \rvert = e^z \le e^d = M, so

∣Rn(x)∣≤ed∣x∣n+1(n+1)!→0\lvert R_n(x) \rvert \le \frac{e^d \lvert x \rvert^{n+1}}{(n + 1)!} \to 0

because ∣x∣n/n!→0\lvert x \rvert^n/n! \to 0 for every fixed xx (it is the general term of ∑∣x∣n/n!\sum \lvert x \rvert^n/n!, which converges by the ratio test). So ex=∑xn/n!e^x = \sum x^n/n! for all real xx. The same argument with M=1M = 1 works for sin and cos, whose derivatives are all bounded by 1.

python · try it yourself
import math

x = 3.0
for n in (5, 10, 15, 20):
    T = sum(x**k / math.factorial(k) for k in range(n + 1))
    actual = abs(math.exp(x) - T)
    bound = math.exp(x) * x ** (n + 1) / math.factorial(n + 1)
    print(f"n={n:2d}  T_n(3)={T:.10f}  |R_n|={actual:.2e}  Taylor bound={bound:.2e}")
n= 5  T_n(3)=18.4000000000  |R_n|=1.69e+00  Taylor bound=2.03e+01
n=10  T_n(3)=20.0796651786  |R_n|=5.87e-03  Taylor bound=8.91e-02
n=15  T_n(3)=20.0855344310  |R_n|=2.49e-06  Taylor bound=4.13e-05
n=20  T_n(3)=20.0855369230  |R_n|=2.37e-10  Taylor bound=4.11e-09

The real error always sits under the bound, and both fall faster than any geometric sequence once n>xn > x.

A smooth function that is not its Taylor series

f(x)=e−1/x2 for x≠0,f(0)=0f(x) = e^{-1/x^2} \ \text{for } x \ne 0, \qquad f(0) = 0

ff has derivatives of every order everywhere, and every derivative at 0 equals 0 (each is a polynomial in 1/x1/x times e−1/x2e^{-1/x^2}, and the exponential wins). So its Maclaurin series is 0+0x+0x2+⋯=00 + 0x + 0x^2 + \cdots = 0, which equals ff only at x=0x = 0. Functions that do equal their Taylor series near every point are called analytic; e−1/x2e^{-1/x^2} is smooth but not analytic. It is the standard building block for "bump functions" that are smooth yet exactly zero outside an interval.

python · try it yourself
import sympy as sp

x = sp.symbols("x")
f = sp.exp(-1 / x**2)
for k in range(4):
    print(f"f^({k})(x) -> {sp.limit(sp.diff(f, x, k), x, 0)} as x -> 0")
print("f(0.5) =", float(f.subs(x, 0.5)), "but the Maclaurin series gives 0")
f^(0)(x) -> 0 as x -> 0
f^(1)(x) -> 0 as x -> 0
f^(2)(x) -> 0 as x -> 0
f^(3)(x) -> 0 as x -> 0
f(0.5) = 0.01831563888873418 but the Maclaurin series gives 0

The standard table

f(x)f(x) Maclaurin series Valid for
1/(1−x)1/(1 - x) ∑xn\sum x^n (−1,1)(-1, 1)
exe^x ∑xn/n!\sum x^n/n! all xx
sin⁡x\sin x ∑(−1)nx2n+1/(2n+1)!\sum (-1)^n x^{2n+1}/(2n + 1)! all xx
cos⁡x\cos x ∑(−1)nx2n/(2n)!\sum (-1)^n x^{2n}/(2n)! all xx
ln⁡(1+x)\ln(1 + x) ∑n≥1(−1)n−1xn/n\sum_{n \ge 1} (-1)^{n-1} x^n/n (−1,1](-1, 1]
arctan⁡x\arctan x ∑(−1)nx2n+1/(2n+1)\sum (-1)^n x^{2n+1}/(2n + 1) [−1,1][-1, 1]
(1+x)k(1 + x)^k ∑C(k,n) xn\sum C(k, n)\, x^n, C(k,n)=k(k−1)⋯(k−n+1)/n!C(k, n) = k(k - 1)\cdots(k - n + 1)/n! (−1,1)(-1, 1) at least

The last line is the binomial series. For a whole number kk it stops (C(k,n)=0C(k, n) = 0 for n>kn > k) and is the binomial theorem; for any other kk it is infinite. For example 1+x=1+x/2−x2/8+x3/16−⋯\sqrt{1 + x} = 1 + x/2 - x^2/8 + x^3/16 - \cdots.

New series come from old ones without computing derivatives:

python · try it yourself
import sympy as sp

x = sp.symbols("x")
print("e^(-x²)       :", sp.series(sp.exp(-x**2), x, 0, 9))
print("x·cos(2x)     :", sp.series(x * sp.cos(2 * x), x, 0, 8))
print("e^x · sin x   :", sp.series(sp.exp(x) * sp.sin(x), x, 0, 6))
print("sqrt(1 + x)   :", sp.series(sp.sqrt(1 + x), x, 0, 4))
e^(-x²)       : 1 - x**2 + x**4/2 - x**6/6 + x**8/24 + O(x**9)
x·cos(2x)     : x - 2*x**3 + 2*x**5/3 - 4*x**7/45 + O(x**8)
e^x · sin x   : x + x**2 + x**3/3 - x**5/30 + O(x**6)
sqrt(1 + x)   : 1 + x/2 - x**2/8 + x**3/16 + O(x**4)

Substituting −x2-x^2 into the exe^x series gives the first line. That is how the integral of the Gaussian e−x2e^{-x^2}, which has no elementary antiderivative, is computed in practice: integrate the series term by term (Exercise 3).

In software

  • Small-angle approximations. sin⁡θ≈θ\sin\theta \approx \theta and cos⁡θ≈1−θ2/2\cos\theta \approx 1 - \theta^2/2 are the first Taylor terms; physics engines and pendulum models use them, and the next term tells you the error (see Applications of Taylor Polynomials).
  • Taylor-mode automatic differentiation carries truncated Taylor series through a program instead of single numbers, getting higher derivatives in one pass (Automatic Differentiation).
  • Activation functions like GELU and tanh are approximated near 0 by short polynomials taken from their series.

Exercises

Exercise 1: Coefficients from derivatives

Find the Taylor series of f(x)=ln⁡xf(x) = \ln x centred at a=1a = 1.

Answer

ln⁡x=∑n=1∞(−1)n−1(x−1)n/n\ln x = \sum_{n=1}^{\infty} (-1)^{n-1} (x - 1)^n/n, for 0<x≤20 < x \le 2.

Solution
f(n)(x)=(−1)n−1(n−1)!xn⇒f(n)(1)n!=(−1)n−1(n−1)!n!=(−1)n−1nf^{(n)}(x) = \frac{(-1)^{n-1} (n - 1)!}{x^n} \quad\Rightarrow\quad \frac{f^{(n)}(1)}{n!} = \frac{(-1)^{n-1} (n - 1)!}{n!} = \frac{(-1)^{n-1}}{n}

This is the ln⁡(1+u)\ln(1 + u) series with u=x−1u = x - 1, as uniqueness predicts.

Exercise 2: Prove convergence for cos

Show cos⁡x\cos x equals its Maclaurin series at x=2x = 2 by bounding R8(2)R_8(2), and compute T8(2)T_8(2).

Answer

∣R8(2)∣≤29/9!≈0.00141\lvert R_8(2) \rvert \le 2^9/9! \approx 0.00141; T8(2)≈−0.415873T_8(2) \approx -0.415873 (cos⁡2≈−0.416147\cos 2 \approx -0.416147).

Solution
All derivatives of cos⁡ are ±sin⁡ or ±cos⁡, so M=1:∣Rn(2)∣≤2n+1(n+1)!→0.n=8:299!=512362880≈0.00141T8(2)=1−42+1624−64720+25640320\begin{aligned} &\text{All derivatives of } \cos \text{ are } \pm\sin \text{ or } \pm\cos, \text{ so } M = 1: \quad \lvert R_n(2) \rvert \le \frac{2^{n+1}}{(n + 1)!} \to 0. \\ n = 8&: \frac{2^9}{9!} = \frac{512}{362880} \approx 0.00141 \\ T_8(2) &= 1 - \frac{4}{2} + \frac{16}{24} - \frac{64}{720} + \frac{256}{40320} \end{aligned}
python · try it yourself
import math

T8 = sum((-1) ** k * 2 ** (2 * k) / math.factorial(2 * k) for k in range(5))
print(f"T8(2) = {T8:.6f}, cos 2 = {math.cos(2):.6f}, error = {abs(T8 - math.cos(2)):.6f}, bound = {2**9 / math.factorial(9):.6f}")
T8(2) = -0.415873, cos 2 = -0.416147, error = 0.000274, bound = 0.001411

Exercise 3: Integrate a series

Compute ∫01e−x2 dx\int_0^1 e^{-x^2}\,dx to 6 decimals using the series, and say how many terms you need.

Answer

≈0.746824\approx 0.746824; terms n=0…8n = 0 \ldots 8 suffice (the next term is 1/(19⋅9!)≈1.45×10−7<5×10−71/(19 \cdot 9!) \approx 1.45 \times 10^{-7} < 5 \times 10^{-7}).

Solution
e−x2=∑(−1)nx2nn!⇒∫01e−x2 dx=∑(−1)n(2n+1) n!e^{-x^2} = \sum \frac{(-1)^n x^{2n}}{n!} \quad\Rightarrow\quad \int_0^1 e^{-x^2}\,dx = \sum \frac{(-1)^n}{(2n + 1)\, n!}

It is alternating with decreasing terms, so the error is below the first omitted term.

python · try it yourself
import math

S = sum((-1) ** n / ((2 * n + 1) * math.factorial(n)) for n in range(9))
print(f"{S:.8f}  exact {math.sqrt(math.pi) / 2 * math.erf(1):.8f}  next term {1 / (19 * math.factorial(9)):.2e}")
0.74682427  exact 0.74682413  next term 1.45e-07

Exercise 4: Binomial series

Use the binomial series with k=−1/2k = -1/2 to write 1/1−x21/\sqrt{1 - x^2} as a series, then integrate to get the series for arcsin⁡x\arcsin x up to x7x^7.

Answer

1/1−x2=1+x2/2+3x4/8+5x6/16+⋯1/\sqrt{1 - x^2} = 1 + x^2/2 + 3x^4/8 + 5x^6/16 + \cdots, so arcsin⁡x=x+x3/6+3x5/40+5x7/112+⋯\arcsin x = x + x^3/6 + 3x^5/40 + 5x^7/112 + \cdots.

Solution
(1+u)−1/2=1−u2+38u2−516u3+⋯ ,u=−x2⇒1+x22+3x48+5x616+⋯Integrate from 0: x+x36+3x540+5x7112+⋯\begin{aligned} (1 + u)^{-1/2} &= 1 - \frac{u}{2} + \frac{3}{8}u^2 - \frac{5}{16}u^3 + \cdots, \qquad u = -x^2 \\ &\Rightarrow 1 + \frac{x^2}{2} + \frac{3x^4}{8} + \frac{5x^6}{16} + \cdots \\ &\text{Integrate from 0: } x + \frac{x^3}{6} + \frac{3x^5}{40} + \frac{5x^7}{112} + \cdots \end{aligned}
python · try it yourself
import sympy as sp

x = sp.symbols("x")
print(sp.series(sp.asin(x), x, 0, 9))
x + x**3/6 + 3*x**5/40 + 5*x**7/112 + O(x**9)

Test yourself

ff has a power series at 0 and f(5)(0)=240f^{(5)}(0) = 240. What is the coefficient of x5x^5?

  1. 240
  2. 48
  3. 2
  4. 1/21/2

What does the function e−1/x2e^{-1/x^2} (with f(0)=0f(0) = 0) show?

  1. Its Taylor series diverges
  2. A smooth function need not equal its Taylor series
  3. Taylor series only exist for polynomials
  4. Its derivatives at 0 are undefined

Which fact makes the remainder of the exe^x series tend to 0 for every xx?

  1. exe^x is increasing
  2. The series is alternating
  3. e<3e < 3
  4. ∣x∣n/n!→0\lvert x \rvert^n/n! \to 0 for every fixed xx