# Taylor and Maclaurin Series with Examples

  

The use the Taylor and Maclaurin series to expand and approximate functions as a power series at given values of $x$ is presented. These series provide useful polynomial approximations of the generating functions which are easier to program on calculators. Examples and questions and their solutions are included.

## Definition of Taylor and Maclaurin Series

For a function $f$ with derivatives of all orders defined in an interval containing $a$, the taylor series of function $f$ at $x = a$ is given by [1] $\sum_{k=0}^{\infty} \dfrac{f^k(a)}{k!} (x-a)^k = f(a) + f'(a) (x-a) + \dfrac{f''(a)}{2!} (x-a)^2 + ... + \dfrac{f^{(n)}(a)}{n!} (x-a)^n + ...$ where $f'(a), f''(a), ... , f^{(n)}(a) ...$ are the derivatives of $f$ evaluated at $x = a$ The Maclaurin series of function $f$ is the Taylor series at $x = 0$ and is given by $\sum_{k=0}^{\infty} \dfrac{f^k(0)}{k!} x^k = f(0) + f'(0) x + \dfrac{f''(0)}{2!} x^2 + ... + \dfrac{f^{(n)}(0)}{n!} x^n + ...$
The Taylor and Maclaurin series are infinite but they may be truncated to $n$ terms so that the Taylor series is a Taylor polynomial given by $P_n(x) = f(a) + f'(a) (x-a) + \dfrac{f''(a)}{2!} (x-a)^2 + ... + \dfrac{f^{(n)}(a)}{n!} (x-a)^n$
An online Online Taylor Series Calculator is included and may be used to check many of the examples and exercises presented below and may also be used to generate and check many other problems.

## Examples of Taylor and Maclaurin Series Expansion

Example 1
a) Find the Taylor polynomial $P_4(x)$ (of order 4) generated by $f(x) = \sin(x)$ at $x = \pi/2$.
b) Use a grahing calculator to graph $\sin(x)$ and $P_4(x)$ in an interval containing $\pi/2$ and compare the two graphs.
solution
a)
The Talylor series of order 4 of $f$ is given by
$P_4(x) = f(\pi/2) + f'(\pi/2) (x-\pi/2) + \dfrac{f''(\pi/2)}{2!} (x-\pi/2)^2 + \dfrac{f^{(3)}(\pi/2))}{3!} (x- \pi/2)^3 + \dfrac{f^{(4)}(\pi/2))}{4!} (x- \pi/2)^4$
Calculate the first 4 derivatives of $f$
$f(x) = \sin(x)$ ,   $f'(x) = \cos(x)$ ,   $f''(x) = -\sin(x)$ ,
$f^{(3)}(x) = -\cos(x)$   $f^{(4)}(x) = \sin(x)$
Evaluate $f$ and its first 4 derivatives of $f$ at $x = \pi/2$
$f(\pi/2) = \sin(\pi/2) = 1$  ,  $f'(\pi/2) = \cos(\pi/2) = 0$ ,
$f''(\pi/2) = - \sin(\pi/2) = -1$ , $f^{(3)}(\pi/2) = -\cos(\pi/2) = 0$   ,
$f^{(4)}(\pi/2) = \sin(\pi/2) = 1$ ,

Substitute in $P_4(x)$ given above
$P_4(x) = f(a) + f'(a) (x-\pi/2) + \dfrac{f''(a)}{2!} (x-\pi/2)^2 + \dfrac{f^{(3)}(\pi/2))}{3!} (x- \pi/2)^3 + \dfrac{f^{(4)}(\pi/2))}{4!} (x- \pi/2)^4 \\ \quad = 1 - \dfrac{1}{2} (x-\pi/2)^2 + \dfrac{1}{24} (x- \pi/2)^4$
b)
Comparing the graphs of $\sin(x)$ and its Taylor series of order $4$, the two graphs are very close and therefore $P_4(x)$ may be used to approximate $\sin(x)$ within an interval containing $\pi/2$.

Example 2
a) Find the Taylor polynomial $P_5(x)$ (of order 5) generated by $f(x) = \ln(x)$ at $x = 1$.
b) Use a grahing calculator to graph $\ln(x)$ and $P_5(x)$ in an interval containing $1$ and compare the two graphs.
c) Evaluate $P_5(x)$ and $\ln(x)$ in the table below and compare the corresponding values .

 $P_5(1.01)$ $\ln(1.01)$ $P_5(0.99)$ $\ln(0.99)$ $P_5(1.1)$ $\ln(1.1)$ $P_5(0.9)$ $\ln(0.9)$ $P_5(1.5)$ $\ln(1.5)$ $P_5(0.5)$ $\ln(0.5)$ $P_5(1.8)$ $\ln(1.8)$ $P_5(0.2)$ $\ln(0.2)$

solution
a)
The
Talylor series of order 5 of $f$ is given by
$P_5(x) = f(1) + f'(1) (x-1) + \dfrac{f''(1)}{2!} (x-1)^2 + \dfrac{f^{(3)}(1)}{3!} (x-1)^3 + \dfrac{f^{(4)}(1)}{4!} (x-1)^4 + \dfrac{f^{(5)}(1)}{5!} (x-1)^5$
Calculate the first 5 derivatives of $f(x) = \ln(x)$
$f(x) = \ln(x)$ ,   $f'(x) = 1/x$ ,   $f''(x) = -1/x^2$ ,
$f^{(3)}(x) = 2/x^3$   $f^{(4)}(x) = -\dfrac{6}{x^4}$   $f^{(5)}(x) = \dfrac{24}{x^5}$
Evaluate $f$ and its first 5 derivatives of $f$ at $x = 1$
$f(1) = \ln(1) = 0$  ,  $f'(1) = 1$ ,
$f''(1) = -1$   ,   $f^{(3)}(1) = 2$ ,
$f^{(4)}(1) = - 6$   ,   $f^{(5)}(1) = 24$ ,

Substitute in $P_5(x)$ given above
$P_3(x) = 0 + (x-1) + \dfrac{-1}{2!} (x-1)^2 + \dfrac{2}{3!} (x- 1)^3 + \dfrac{-6}{4!} (x-1)^4 + \dfrac{24}{5!} (x-1)^5 \\ \quad = \dfrac{1}{5}x^5-\dfrac{5}{4}x^4+\dfrac{10}{3}x^3 - 5x^2+5x-\dfrac{137}{60}$
b)
From the graphs below, the Taylor series of order $5$ could approximate $\ln(x)$ in an interval containing $1$. How wide is that interval depends on the application.

c)
 $P_5(1.01) = 0.00995$ $\ln(1.01) = 0.00995$ $P_5(0.99) = -0.01005$ $\ln(0.99) = -0.01005$ $P_5(1.1) = 0.09531$ $\ln(1.1) = 0.09531$ $P_5(0.9) = -0.10536$ $\ln(0.9) = -0.10536$ $P_5(1.5) = 0.40729$ $\ln(1.5) = 0.40546$ $P_5(0.5) = -0.68854$ $\ln(0.5) = -0.69314$ $P_5(1.8) = 0.61380$ $\ln(1.8) = 0.58778$ $P_5(0.2) = -1.45860$ $\ln(0.2) = -1.60943$
From the table of values above, we note that the polynomial $P_5(x)$ is a good approximation to $\ln(x)$ for values close to $x = 1$.
The approximation also depends on the order of the series as well. A good approximation of a function using taylor series is obtained with a higher number of terms in the series .

Example 3
a) Find the Maclaurin series generated by $f(x) = e^x$.
b) Use a grahing calculator to graph the Maclaurin series in an interval containing $0$ with 2, 3, 4, 5 and 6 terms.

solution
a)
The Maclaurin series of $f$ is given by
$\sum_{k=0}^{\infty} \dfrac{f^k(0)}{k!} x^k = f(0) + f'(0) x + \dfrac{f''(0)}{2!} x^2 + ... + \dfrac{f^{(n)}(0)}{n!} x^n + ...$
Calculate the derivatives of $f(x) = e^x$
$f(x) = e^x$ ,   $f'(x) = e^x$ ,   $f''(x) = e^x$ ,
$f^{(n)}(x) = e^x$ for all $n \ge 3$
Evaluate the function and its derivatives at $x = 0$
$f(0) = 1$ ,   $f'(0) = 1$ ,   $f''(0) = 1$ ,
$f^{(n)}(0) = 1$ for all $n \ge 3$
Substitute in the series above to obtain the Maclaurin series of $f(x) = e^x$
$1 + x + \dfrac{1}{2!} x^2 + ... + \dfrac{1}{n!} x^n + ...$
b)
Maclaurin series with 2, 3, 4, 5 and 6 terms are given by
$P_1(x) = 1 + x$
$P_2(x) = 1 + x + \dfrac{1}{2} x^2$
$P_3(x) = 1 + x + \dfrac{1}{2} x^2 + \dfrac{1}{6} x^3$
$P_4(x) = 1 + x + \dfrac{1}{2!} x^2 + \dfrac{1}{6} x^3 + \dfrac{1}{24} x^4$
$P_5(x) = 1 + x + \dfrac{1}{2!} x^2 + \dfrac{1}{6} x^3 + \dfrac{1}{24} x^4 + \dfrac{1}{120} x^5$
The above five polynoials are graphed below along with the given function $f(x) = e^x$. We note that the approximations around $x = 0$ get better as the numbers of terms in the series increases.

.

## Questions

( with solutions )

Part A
Find the Taylor polynomial of order $4$ generated by $f$ at the given value of $x$
a) $f(x) = e^{-x}$ , at $x = 2$
b) $f(x) = \sin(x/2)$ , at $x = \pi$

Part B
Find the Maclaurin series for the functions
a) $f(x) = \cos(x+\pi/2)$
b) $f(x) = e^x + e^{-x}$
c) $f(x) = e^{-x^2}$
d) $f(x) = \sin(x)$
e) $f(x) = e^x - e^{-x}$

Part C
Find the Taylor polynomial of order $5$ generated by $f(x) = \sin(x) e^x$ at $x = 0$ and graph $f$ and the taylor polynomial in the same system of coordinates.
a)

## Solutions to the Above Questions

Part A
a)
$P_4(x) = f(2) + f'(2) (x-2) + \dfrac{f''(2)}{2!} (x-2)^2 + \dfrac{f^{(3)}(2))}{3!} (x- 2)^3 + \dfrac{f^{(4)}(2))}{4!} (x- 2)^4$

$f(x) = e^{-x}$ , $f'(x) = - e^{-x}$ , $f''(x) = e^{-x}$ , $f^{(3)}(x) = - e^{-x}$ , $f^{(4)}(x) = e^{-x}$

$P_4(x) = \quad \dfrac{1}{e^2}-\dfrac{1}{e^2}\left(x-2\right)+\dfrac{1}{2e^2}\left(x-2\right)^2-\dfrac{1}{6e^2}\left(x-2\right)^3+\dfrac{1}{24e^2}\left(x-2\right)^4 \\ = \dfrac{x^4}{24e^2}-\dfrac{x^3}{2e^2}+\dfrac{5x^2}{2e^2}-\dfrac{19x}{3e^2} + \dfrac{7}{e^2}$

b)

$P_4(x) = f(\pi ) + f'(\pi ) (x-\pi ) + \dfrac{f''(\pi )}{2!} (x-\pi )^2 + \dfrac{f^{(3)}(\pi ))}{3!} (x- \pi )^3 + \dfrac{f^{(4)}(\pi ))}{4!} (x- \pi )^4$

$f(x) = \sin(x/2)$ , $f'(x) = \dfrac{1}{2} \cos(x/2)$ , $f''(x) = - \dfrac{1}{4} \sin(x/2)$ , $f^{(3)}(x) = - \dfrac{1}{8} \cos(x/2)$ , $f^{(4)}(x) = \dfrac{1}{16} \cos(x/2)$

$P_4(x) = 1-\dfrac{1}{8}\left(x-\pi \right)^2+\dfrac{1}{384}\left(x-\pi \right)^4 \\ = \dfrac{x^4}{384}-\dfrac{\pi x^3}{96}-\dfrac{x^2}{8}+\dfrac{\pi ^2x^2}{64}+\dfrac{\pi x}{4}-\dfrac{\pi ^3x}{96}-\dfrac{48 \pi ^2+\pi ^4+384}{384}$

Part B
Maclaurin series are given by: $\quad f(0) + f'(0) x + \dfrac{f''(0)}{2!} x^2 + ... + \dfrac{f^{(n)}(0)}{n!} x^n + ...$
a)
$f(x) = \cos(x+\pi/2)$ , $f'(x) = - \sin(x+\pi/2)$ , $f''(x) = - \cos(x+\pi/2)$ , $f^{(3)}(x) = \sin(x+\pi/2)$ ...
Maclaurin series
$-x+\dfrac{1}{6}x^3-\dfrac{1}{120}x^5+\dfrac{1}{5040}x^7-\dfrac{1}{362880}x^9+\ldots \:$

b)
$f(x) = e^x + e^{-x}$ , $f'(x) = e^x - e^{-x}$ , $f''(x) = e^x + e^{-x}$ , $f^{(3)}(x) = e^x - e^{-x}$ ...
Maclaurin series
$2+x^2+\dfrac{1}{12}x^4+\dfrac{1}{360}x^6+\dfrac{1}{20160}x^8+ \ldots \:$

c)
$f(x) = e^{-x^2}$ , $f'(x) = -2e^{-x^2}x$ , $f''(x) = -2\left(-2e^{-x^2}x^2+e^{-x^2}\right)$ , $f^{(3)}(x) = -2\left(4e^{-x^2}x^3-6e^{-x^2}x\right)$
Maclaurin series
$1-x^2+\dfrac{1}{2}x^4-\dfrac{1}{6}x^6+\dfrac{1}{24}x^8+\ldots \:$

d)
$f(x) = \sin(x)$ , $f'(x) = \cos(x)$ , $f''(x) = -\sin(x)$ , $f^{(3)}(x) = - \cos(x)$ , ...
Maclaurin series
$x-\dfrac{1}{6}x^3+\dfrac{1}{120}x^5-\dfrac{1}{5040}x^7+\dfrac{1}{362880}x^9+\ldots \:$

e)
$f(x) = e^x - e^{-x}$ , $f'(x) = e^x + e^{-x}$ , $f''(x) = e^x - e^{-x}$ , $f^{(3)}(x) = e^x + e^{-x}$ ...
Maclaurin series
$2x+\dfrac{1}{3}x^3+\dfrac{1}{60}x^5+\dfrac{1}{2520}x^7+\dfrac{1}{181440}x^9+\ldots$

Part C
$P_5(x) = x+x^2+\frac{1}{3}x^3-\dfrac{1}{30}x^5$