Skip to main content

Exploring Calculus with Maple Introductory Calculus

Section 17.3 Taylor and Maclaurin Series

One use of series is to find the Taylor series expansion of a function. Recall that the Taylor series of a function \(f(x)\) centred at \(x=a\text{,}\) is the sum
\begin{equation*} \sum_{k=0}^{\infty} \dfrac{f^{(k)}(a)}{k!}(x-a)^k\text{.} \end{equation*}
A special case of a Taylor series that is centred at \(a=0\) is known as a Maclaurin series.
In Maple, the taylor() command outputs the first few terms of the Taylor series. It uses β€œbig O” notation as a placeholder to represent the remaining terms of higher degree. The number of terms displayed may be specified. In this example, we can see the Taylor series expansion of \(f(x)=sin(x)\) centred at \(x=5\text{,}\) with terms up to (but not including) degree four.
> taylor(sin(x), x = 5, 4);
\begin{equation*} \begin{array}{l}\displaystyle \sin \left( 5 \right) +\cos \left( 5 \right) \left( x-5 \right) -\frac{1}{2}\,\sin \left( 5 \right) \left( x-5 \right) ^{2}\\ \displaystyle -\frac{1}{6}\,\cos \left( 5 \right) \left( x-5 \right) ^{3}+O \left( \left( x-5 \right) ^{4} \right) \end{array} \end{equation*}
The first \(n\) terms of a Taylor series is known as an \(n\)th degree Taylor polynomial approximation of \(f(x)\text{.}\) Depending on the convergence of the series, this polynomial approximation will have a very similar shape to the function in an interval centred at \(x=a\text{.}\) The convert() command can be used to eliminate higher terms of the series and give a Taylor polynomial of a desired degree.

Example 17.1. Maclaurin Series of \({ e}^x\).

The function \(f(x)=e^x\) has a very simple pattern with its higher derivatives, particularly evaluated at \(x=0\text{,}\) so it provides for a very simple example of a Maclaurin series. Since a Maclaurin series is a Taylor series centred at \(a=0\text{,}\) we must specify \(x=0\) in the taylor() command.
> taylor(exp(x), x = 0);
\begin{equation*} \displaystyle 1+x+\frac{1}{2}\,{x}^{2}+\frac{1}{6}\,{x}^{3}+\frac{1}{24}\,{x}^{4}+\frac{1}{120}\,{x}^{5}+O \left( {x}^{6} \right) \end{equation*}
By default, Maple has given \(7\) terms as an output here. The \(O(x^6)\) term in this expression means "plus a bunch more terms with power \(6\) and higher". We can specify the order (related to number of terms) of the Taylor series by adding a number as the final argument to the command.
> taylor(exp(x), x = 0, 10);
\begin{equation*} \begin{array}{l}\displaystyle 1+x+\frac{1}{2}\,{x}^{2}+\frac{1}{6}\,{x}^{3}+\frac{1}{24}\,{x}^{4}+\frac{1}{120}\,{x}^{5}\\ \displaystyle +{\frac {1}{720}}\,{x}^{6}+{\frac {1}{5040}}\,{x}^{7}+{\frac {1}{40320}}\,{x}^{8}+{\frac {1}{362880}}\,{x}^{9}+O \left( {x}^{10} \right) \end{array} \end{equation*}
Using this additional option, Maple has displayed all the terms with powers less than \(10\text{.}\)

Example 17.2. Comparing a Function to its Taylor Polynomial.

We can see how closely the a Taylor polynomial resembles the original function by plotting them on the same axes. In this example, we will compare the graph of \(f(x)=\sin(x)\) to its Taylor polynomial approximation centred at \(x=0\text{.}\)
To begin, we construct the Taylor series expansion of \(\sin(x)\text{,}\) which will output the series using β€œbig O” notation. This needs to be converted to a polynomial with finitely many terms. The convert() command lets Maple know that we wish for the
> taylor(sin(x), x = 0, 10); poly := convert(%);
\begin{equation*} \displaystyle x-\frac{1}{6}\,{x}^{3}+{\frac {1}{120}}\,{x}^{5}-{\frac {1}{5040}}\,{x}^{7}+{\frac {1}{362880}}\,{x}^{9}+O \left( {x}^{11} \right) \end{equation*}
\begin{equation*} \displaystyle poly\, := \,x-\frac{1}{6}\,{x}^{3}+{\frac {1}{120}}\,{x}^{5}-{\frac {1}{5040}}\,{x}^{7}+{\frac {1}{362880}}\,{x}^{9} \end{equation*}
Now that we have assigned a name to the Taylor polynomial, it can be plotted alongside \(\sin(x)\) to see how the shape of the Taylor polynomial expression converges to the function around \(x=0\text{.}\)
> plot( [sin(x), poly], x = -4*Pi..4*Pi, y = -10..10);
As we can see the Taylor polynomial and the original function \(\sin(x)\) have a very similar shape around the origin.