Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

6.1 Taylor Series

Section 5.3 introduced the idea of a series. A series is a sum of infinitely many ordered terms.

This section develops a general method for approximating functions using series. This method is widely used in mathematics and in science. It allows accurate approximation of arbitrary smooth functions with polynomials.

Polynomial Approximation

Suppose that f(x)f(x) is a smooth function of xx. We are asked to approximate f(x)f(x) for some xx. For example, we could be asked for e0.1e^{0.1}.

Often, we can’t find f(x)f(x), but can evaluate ff at some nearby xx_*. For instance, e0=1e^0 = 1. If ff is smooth, then we can use information about ff at xx_*, to approximate f(x)f(x) when xx is close to xx_*.

The simplest approximation is f(x)f(x)f(x) \approx f(x). We can do better if we use more information.

Suppose that we know f(x)f(x_*) for some xx_*, and we know the slope of f(x)f(x) at xx_*, ddxf(x)x=x=f(x)\frac{d}{dx} f(x)|_{x = x_*} = f'(x_*).

Consider the tangent line:

f(x)+f(x)×(xx).f(x_*) + f'(x_*) \times (x - x_*).

This tangent line provides a good approximation for f(x)f(x) when xx is close to xx_* since, by the limiting definition of a derivative:

f(x)=limΔx0f(x+Δx)f(x)Δxf(x)f(x)xx.f'(x_*) = \lim_{\Delta x \rightarrow 0} \frac{f(x_* + \Delta x) - f(x_*)}{\Delta x} \simeq \frac{f(x) - f(x_*)}{x - x_*}.

The sign \simeq means approximately equal to, and equal to in a limit. In this case, the limit is Δx=xx0\Delta x = x - x_* \rightarrow 0.

Therefore, for xx near xx_*:

f(x)f(x)+f(x)×(xx)=f~1(x).f(x) \simeq f(x_*) + f'(x_*) \times (x - x_*) = \tilde{f}_1(x).

The function f~1(x)\tilde{f}_1(x) is linear in xx. It passes through (x,f(x))(x_*,f(x_*)) with slope f(x)f'(x_*). We’ve denoted it f~\tilde{f} to emphasize that it approximates ff, and added the subscript 1_1 to emphasize that the approximation is a first order polynomial in xx (that is, a line).

The figure below shows a smooth function ff, and the linear approximations to ff at x=3x_* = -3 (red), x=0.5x_* = -0.5 (gold), and x=2x_* = 2 (green). Notice that each linear approximation accounts for the slope of ff.

Linear Approximations.

We can develop higher order polynomial approximations by approximating f(x)f'(x), then integrating. By the Fundamental Theorem of Calculus:

f(x)f(x)=xxf(y)dyf(x) - f(x_*) = \int_{x_*}^x f'(y) dy

Then, for yy near xx_*, use the linear approximation:

f(y)f(x)+f(x)(yx)f'(y) \simeq f'(x_*) + f''(x_*) (y - x_*)

where the slope is now f(x)f''(x_*) since ddxf(x)x=x=f(x)\frac{d}{dx} f'(x)|_{x = x_*} = f''(x_*).

Therefore:

f(x)f(x)xx(f(x)+f(x)(yx))dy=f(x)(xx)+12f(x)(xx)2.f(x) - f(x_*) \simeq \int_{x_*}^x \left( f'(x_*) + f''(x_*) (y - x_*) \right) dy = f'(x_*) (x - x_*) + \frac{1}{2} f''(x_*) (x - x_*)^2.

Isolating f(x)f(x) offers a quadratic approximation to ff:

f(x)f(x)+f(x)(xx)+12f(x)(xx)2=f~(2)(x).f(x) \simeq f(x_*) + f'(x_*) (x - x_*) + \frac{1}{2} f''(x_*) (x - x_*)^2 = \tilde{f}^{(2)}(x).

The figure below shows a smooth function ff, and the linear (dashed) and quadratic (dotted) approximations to ff at x=3x_* = -3 (red), x=0.5x_* = -0.5 (gold), and x=2x_* = 2 (green). Notice that each linear approximation accounts for the slope of ff, while each quadratic approximation account for its slope and curvature at xx_*. Also notice that the quadratic approximations are accurate farther from the points of expansion.

Linear and Quadratic Approximations.

We can use quadratic approximations to help draw functions. If you are asked to draw ff, and can evaluate both ff' and ff'', then when you select reference points xx_* for plotting, check the slope and second derivative, then sketch the tangent, and the tangent parabola f~2\tilde{f}_2.

Taylor Series

We can develop even better approximations by including more details about ff at xx_*. If we account for ff''' then we can introduce a cubic approximation:

f(x+Δx)f~3(Δx)=f(x)+f(x)Δx+12f(x)Δx2+16f(x)Δx3.f(x_* + \Delta x) \simeq \tilde{f}_3(\Delta x) = f(x_*) + f'(x_*) \Delta x + \frac{1}{2} f''(x_*) \Delta x^2 + \frac{1}{6} f'''(x_*) \Delta x^3.

The figure below shows a smooth function ff, its quadratic (dotted) and cubic (dash-dot) approximations at x=3x_* = -3 (red), x=0.5x_* = -0.5 (gold), and x=2x_* = 2 (green). Notice that the cubic approximations are extremely accurate, even for xx far from xx_*.

Cubic Approximations.

Taylor series generalize this idea by continuing the process out to infinitely many terms.

Examples

The two most important Taylor series in probability are the Taylor series of the exponential and the logarithm.

Exponential Functions

Suppose that f(x)=exf(x) = e^x. Then, let’s find its Taylor series about x=0x = 0.

To find the Taylor series we need to work out all of the derivatives of exe^x at x=0x = 0. This is easy, since the derivative of the exponential is the exponential:

f(x)=exf(x)=ddxex=exf(x)=ddxf(x)=ddxex=ex...\begin{aligned} & f(x) = e^x \\ & \Rightarrow f'(x) = \frac{d}{dx}e^x = e^x \\ & \Rightarrow f''(x) = \frac{d}{dx} f'(x) = \frac{d}{dx} e^x = e^x \\ & \Rightarrow ... \end{aligned}

Closing the recursion:

f(n)(x)=ex.f^{(n)}(x) = e^x.

Therefore, f(n)(0)=e0=1f^{(n)}(0) = e^0 = 1.

It follows that:

The figure below illustrates the first four approximations (linear, quadratic, cubic, quartic) to the exponential produced by its Taylor series about x=0x_* = 0. In particular, ex1+xe^x \simeq 1 + x. Higher order approximations are illustrated with lighter dotted curves.

Exponential Approximations.

To show that this series converges for all xx, use the ratio test (see Section 5.3):

r=limn1(n+1)!xn+11n!xn=limnn!(n+1)!x=limnxn+1=0.r = \lim_{n \rightarrow \infty} \frac{\frac{1}{(n+1)!}|x^{n+1}|}{\frac{1}{n!}{|x^n|}} = \lim_{n \rightarrow \infty} \frac{n!}{(n+1)!} |x| = \lim_{n \rightarrow \infty} \frac{|x|}{n+1} = 0.

Since r<1r < 1 for all xx the series converges for all xx.

The Taylor series for the exponential gives us a new series that we can close. We can add it to the list we started with the geometric series:

Sequence NameFormulaSeriesSeries ValueConvergence
Geometricrnr^nn=0rn\sum_{n=0}^{\infty} r^n11r\frac{1}{1 - r}if 1<r<1-1 < r < 1
Harmonicn1n^{-1}n=1n1\sum_{n=1}^{\infty} n^{-1}\inftydiverges
Exponential Taylor Seriesxn/n!x^n/n!n=01n!xn\sum_{n=0}^{\infty} \frac{1}{n!} x^nexe^xconverges for all xx

The exponential’s Taylor series can be easily generalized to related functions via composition. For instance, if f(x)=eg(x)f(x) = e^{g(x)}, then:

f(x)=n=01n!g(x)nf(x) = \sum_{n=0}^{\infty} \frac{1}{n!} g(x)^n

Useful examples include:

  1. eλx=n=01n!(λx)ne^{\lambda x} = \sum_{n = 0}^{\infty} \frac{1}{n!} (\lambda x)^n

  2. ex=n=01n!(x)ne^{-x} = \sum_{n = 0}^{\infty} \frac{1}{n!} (- x)^n

  3. e12x2=n=01n!(12)nx2ne^{-\frac{1}{2} x^2} = \sum_{n=0}^{\infty} \frac{1}{n!} \left( \frac{-1}{2} \right)^n x^{2n}.

Truncating these series provides helpful approximations. For example:

e12x2112x2e^{-\frac{1}{2} x^2} \simeq 1 - \frac{1}{2} x^2

when xx is small. This explains why, when we’ve drawn normal density functions (bell curves), we see a smooth parabola shape for xx near zero. That parabola is 10.5x21 - 0.5 x^2.

Logarithms

The next most important example is the logarithm. We’ll Taylor expand the logarithm about x=1x_* = 1 since the log diverges at x=0x = 0.

To find the Taylor expansion, evaluate log(x)\log(x), and its derivatives, at x=1x = 1:

f(x)=log(x)f(x)=ddxlog(x)=x1f(x)=ddxf(x)=ddxx1=x2f(x)=ddxf(x)=ddx(x2)=2x3...\begin{aligned} & f(x) = \log(x) \\ & \Rightarrow f'(x) = \frac{d}{dx} \log(x) = x^{-1} \\ & \Rightarrow f''(x) = \frac{d}{dx} f'(x) = \frac{d}{dx} x^{-1} = -x^{-2} \\ & \Rightarrow f'''(x) = \frac{d}{dx} f''(x) = \frac{d}{dx} (-x^{-2}) = 2 x^{-3} \\ & \Rightarrow ... \end{aligned}

Closing the recursion:

f(n)(x)=(1)n1(n1)!x(n1)f^{(n)}(x) = (-1)^{n-1} (n-1)! x^{-(n-1)}

for n>1n > 1.

So, at x=1x_* = 1:

f(1)f(1)f(1)f'(1)f(1)f''(1)f(1)f'''(1)f(4)(1)f^{(4)}(1)...f(n)(1)f^{(n)}(1)
log(1)\log(1)1-112- 1^{-2}2×132 \times 1^{-3}6×14-6 \times 1^{-4}...(1)n1(n1)!1(n1)(-1)^{n-1} (n-1)! 1^{-(n-1)}
01-12-6...(1)n1(n1)!(-1)^{n-1} (n-1)!

Therefore:

log(x)0+1×(x1)12×(x1)2+16×2×(x1)3...=(x1)12(x1)2+13(x1)3...\begin{aligned} \log(x) & \simeq 0 + 1 \times (x - 1) - \frac{1}{2} \times (x - 1)^2 + \frac{1}{6} \times 2 \times (x - 1)^3 - ... \\ & = (x - 1) - \frac{1}{2} (x - 1)^2 + \frac{1}{3} (x - 1)^3 - ... \end{aligned}

Writing x1=Δxx - 1 = \Delta x gives the concise form:

The figure below illustrates the first four approximations (linear, quadratic, cubic, quartic) to the logarithm produced by its Taylor series about x=1x_* = 1. In particular, log(x)x1\log(x) \simeq x - 1. Higher order approximations are illustrated with lighter dotted curves.

Log Approximations.

To identify the region where the series converges, use the ratio test from Section 5.3:

r=limn1n+1Δxn+11nΔxn=limnnn+1Δx=Δxr = \lim_{n \rightarrow \infty} \frac{\frac{1}{n+1} |\Delta x^{n+1}|}{\frac{1}{n} |\Delta x^n|} = \lim_{n \rightarrow \infty} \frac{n}{n+1} |\Delta x| = |\Delta x|

The series converges if r<1r < 1 and diverges if r>1r > 1, so the Taylor series for the logarithm converges if and only if Δx<1|\Delta x| < 1. This means that log(x)\log(x) only equals its Taylor series about x=1x_* = 1 for x(0,2)x \in (0,2).

We can now add the log Taylor series to the list of infinite series we can close:

Sequence NameFormulaSeriesSeries ValueConvergence
Geometricrnr^nn=0rn\sum_{n=0}^{\infty} r^n11r\frac{1}{1 - r}if 1<r<1-1 < r < 1
Harmonicn1n^{-1}n=1n1\sum_{n=1}^{\infty} n^{-1}\inftydiverges
Exponential Taylor Seriesxn/n!x^n/n!n=01n!xn\sum_{n=0}^{\infty} \frac{1}{n!} x^nexe^xconverges for all xx
Log Taylor Series(1)n1xn/n(-1)^{n-1} x^n/nn=1(1)n1nxn\sum_{n=1}^{\infty} \frac{(-1)^{n-1}}{n} x^nlog(1+x)\log(1 + x)if x(1,1)x \in (-1,1)