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 . This lesson proves that, proves with Taylor's inequality that , and 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 for , then
Proof. Put : . Differentiate term by term (allowed inside the radius, see Representations of Functions as Power Series) and put again: . After differentiations, the term becomes , lower terms have vanished and higher terms still contain a factor , so . ∎
The resulting series is the Taylor series of at ; with 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 has a series, this is it. Write
equals its Taylor series at exactly when the remainder . The tool for showing that:
Taylor's theorem (Lagrange form). If has derivatives between and , then for some between and
Taylor's inequality. Consequently, if between and , then
Proof sketch of the inequality for , . From , integrate from to : . Integrate again from to : . Repeating the integration times gives the general case. The Lagrange form follows similarly from the Mean Value Theorem (see The Mean Value Theorem).
equals its series for every
Every derivative of is , so and the Maclaurin series is . Fix and a bound . Between 0 and , , so
because for every fixed (it is the general term of , which converges by the ratio test). So for all real . The same argument with works for sin and cos, whose derivatives are all bounded by 1.
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 .
A smooth function that is not its Taylor series
has derivatives of every order everywhere, and every derivative at 0 equals 0 (each is a polynomial in times , and the exponential wins). So its Maclaurin series is , which equals only at . Functions that do equal their Taylor series near every point are called analytic; is smooth but not analytic. It is the standard building block for "bump functions" that are smooth yet exactly zero outside an interval.
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
| Maclaurin series | Valid for | |
|---|---|---|
| all | ||
| all | ||
| all | ||
| , | at least |
The last line is the binomial series. For a whole number it stops ( for ) and is the binomial theorem; for any other it is infinite. For example .
New series come from old ones without computing derivatives:
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 into the series gives the first line. That is how the integral of the Gaussian , which has no elementary antiderivative, is computed in practice: integrate the series term by term (Exercise 3).
In software
- Small-angle approximations. and 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 centred at .
Answer
, for .
Solution
This is the series with , as uniqueness predicts.
Exercise 2: Prove convergence for cos
Show equals its Maclaurin series at by bounding , and compute .
Answer
; ().
Solution
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 to 6 decimals using the series, and say how many terms you need.
Answer
; terms suffice (the next term is ).
Solution
It is alternating with decreasing terms, so the error is below the first omitted term.
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 to write as a series, then integrate to get the series for up to .
Answer
, so .
Solution
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
has a power series at 0 and . What is the coefficient of ?
- 240
- 48
- 2
What does the function (with ) show?
- Its Taylor series diverges
- A smooth function need not equal its Taylor series
- Taylor series only exist for polynomials
- Its derivatives at 0 are undefined
Which fact makes the remainder of the series tend to 0 for every ?
- is increasing
- The series is alternating
- for every fixed