### Subsection3.4.6Some Examples

Let us return to our running example of $e^x\text{:}$

The constant, linear and quadratic approximations we used above were the first few Maclaurin polynomial approximations of $e^x\text{.}$ That is

\begin{align*} T_0 (x) & = 1 & T_1(x) &= 1+x & T_2(x) &= 1+x+\frac{x^2}{2} \end{align*}

Since $\diff{}{x} e^x = e^x\text{,}$ the Maclaurin polynomials are very easy to compute. Indeed this invariance under differentiation means that

\begin{align*} f^{(n)}(x) &= e^x & n=0,1,2,\dots && \text{so}\\ f^{(n)}(0) &= 1 \end{align*}

Substituting this into equation 3.4.10 we get

\begin{align*} T_n(x) &= \sum_{k=0}^n \frac{1}{k!} x^k \end{align*}

Thus we can write down the seventh Maclaurin polynomial very easily:

\begin{align*} T_7(x) &= 1 + x + \frac{x^2}{2} + \frac{x^3}{6} + \frac{x^4}{24} + \frac{x^5}{120} + \frac{x^6}{720} + \frac{x^7}{5040} \end{align*}

The following figure contains sketches of the graphs of $e^x$ and its Taylor polynomials $T_n(x)$ for $n=0,1,2,3,4\text{.}$

Also notice that if we use $T_7(1)$ to approximate the value of $e^1$ we obtain:

\begin{align*} e^1 \approx T_7(1) &= 1 + 1 + \frac{1}{2} + \frac{1}{6} + \frac{1}{24} + \frac{1}{120} + \frac{1}{720} + \frac{1}{5040}\\ &= \frac{685}{252} = 2.718253968\dots \end{align*}

The true value of $e$ is $2.718281828\dots\text{,}$ so the approximation has an error of about $3\times10^{-5}\text{.}$

Under the assumption that the accuracy of the approximation improves with $n$ (an assumption we examine in Subsection 3.4.9 below) we can see that the approximation of $e$ above can be improved by adding more and more terms. Indeed this is how the expression for $e$ in equation 2.7.4 in Section 2.7 comes about.

Now that we have examined Maclaurin polynomials for $e^x$ we should take a look at $\log x\text{.}$ Notice that we cannot compute a Maclaurin polynomial for $\log x$ since it is not defined at $x=0\text{.}$

Compute the $5^\mathrm{th}$ Taylor polynomial for $\log x$ about $x=1\text{.}$

Solution We have been told $a=1$ and fifth degree, so we should start by writing down the function and its first five derivatives:

\begin{align*} f(x) &= \log x & f(1) &= \log 1 = 0\\ f'(x) &= \frac{1}{x} & f'(1) &= 1\\ f''(x) &= \frac{-1}{x^2} & f''(1) &= -1\\ f'''(x) &= \frac{2}{x^3} & f'''(1) &= 2\\ f^{(4)}(x) &= \frac{-6}{x^4} & f^{(4)}(1) &= -6\\ f^{(5)}(x) &= \frac{24}{x^5} & f^{(5)}(1) &= 24 \end{align*}

Substituting this into equation 3.4.10 gives

\begin{align*} T_5(x)&= 0 + 1\cdot (x-1) + \frac{1}{2} \cdot (-1) \cdot (x-1)^2 + \frac{1}{6} \cdot 2 \cdot (x-1)^3\\ \amp\hskip0.5in+ \frac{1}{24} \cdot (-6) \cdot (x-1)^4 + \frac{1}{120} \cdot 24 \cdot (x-1)^5\\ &= (x-1) - \frac{1}{2}(x-1)^2 + \frac{1}{3}(x-1)^3 - \frac{1}{4}(x-1)^4 + \frac{1}{5}(x-1)^5 \end{align*}

Again, it is not too hard to generalise the above work to find the Taylor polynomial of degree $n\text{:}$ With a little work one can show that

\begin{align*} T_n(x) &= \sum_{k=1}^n \frac{(-1)^{k+1}}{k} (x-1)^k. \end{align*}

For cosine:

Find the 4th degree Maclaurin polynomial for $\cos x\text{.}$

Solution We have $a=0$ and we need to find the first 4 derivatives of $\cos x\text{.}$

\begin{align*} f(x) &= \cos x & f(0) &= 1\\ f'(x) &= -\sin x & f'(0) &= 0\\ f''(x) &= -\cos x & f''(0) &= -1\\ f'''(x) &= \sin x & f'''(0) &= 0\\ f^{(4)}(x) &= \cos x & f^{(4)}(0) &= 1 \end{align*}

Substituting this into equation 3.4.10 gives

\begin{align*} T_4(x)&= 1 + 1\cdot (0) \cdot x + \frac{1}{2} \cdot (-1) \cdot x^2 + \frac{1}{6} \cdot 0 \cdot x^3 + \frac{1}{24} \cdot (1) \cdot x^4\\ &= 1 - \frac{x^2}{2} + \frac{x^4}{24} \end{align*}

Notice that since the $4^\mathrm{th}$ derivative of $\cos x$ is $\cos x$ again, we also have that the fifth derivative is the same as the first derivative, and the sixth derivative is the same as the second derivative and so on. Hence the next four derivatives are

\begin{align*} f^{(4)}(x) &= \cos x & f^{(4)}(0) &= 1\\ f^{(5)}(x) &= -\sin x & f^{(5)}(0) &= 0\\ f^{(6)}(x) &= -\cos x & f^{(6)}(0) &= -1\\ f^{(7)}(x) &= \sin x & f^{(7)}(0) &= 0\\ f^{(8)}(x) &= \cos x & f^{(8)}(0) &= 1 \end{align*}

Using this we can find the $8^\mathrm{th}$ degree Maclaurin polynomial:

\begin{align*} T_8(x) &= 1 - \frac{x^2}{2} + \frac{x^4}{24} -\frac{x^6}{6!} + \frac{x^8}{8!} \end{align*}

Continuing this process gives us the $2n^\mathrm{th}$ Maclaurin polynomial

\begin{align*} T_{2n}(x) &= \sum_{k=0}^n \frac{(-1)^k}{(2k)!} \cdot x^{2k} \end{align*}
###### Warning3.4.15

The above formula only works when x is measured in radians, because all of our derivative formulae for trig functions were developed under the assumption that angles are measured in radians.

Below we plot $\cos x$ against its first few Maclaurin polynomial approximations:

The above work is quite easily recycled to get the Maclaurin polynomial for sine:

Find the 5th degree Maclaurin polynomial for $\sin x\text{.}$

Solution We could simply work as before and compute the first five derivatives of $\sin x\text{.}$ But set $g(x) = \sin x$ and notice that $g(x) = - f'(x)\text{,}$ where $f(x) =\cos x\text{.}$ Then we have

\begin{align*} g(0) &= -f'(0) = 0\\ g'(0) &= -f''(0) = 1\\ g''(0) &= -f'''(0) = 0\\ g'''(0) &= -f^{(4)}(0) = -1\\ g^{(4)}(0) &= -f^{(5)}(0) = 0\\ g^{(5)}(0) &= -f^{(6)}(0) = 1 \end{align*}

Hence the required Maclaurin polynomial is

\begin{align*} T_5(x) &= x - \frac{x^3}{3!} + \frac{x^5}{5!} \end{align*}

Just as we extended to the $2n^\mathrm{th}$ Maclaurin polynomial for cosine, we can also extend our work to compute the $(2n+1)^\mathrm{th}$ Maclaurin polynomial for sine:

\begin{align*} T_{2n+1}(x) &= \sum_{k=0}^n \frac{(-1)^k}{(2k+1)!} \cdot x^{2k+1} \end{align*}
###### Warning3.4.17

The above formula only works when x is measured in radians, because all of our derivative formulae for trig functions were developed under the assumption that angles are measured in radians.

Below we plot $\sin x$ against its first few Maclaurin polynomial approximations.

To get an idea of how good these Taylor polynomials are at approximating $\sin$ and $\cos\text{,}$ let's concentrate on $\sin x$ and consider $x$'s whose magnitude $|x|\le 1\text{.}$ There are tricks that you can employ  13 If you are writing software to evaluate $\sin x\text{,}$ you can always use the trig identity $\sin(x)=\sin(x-2n\pi)\text{,}$ to easily restrict to $|x|\le\pi\text{.}$ You can then use the trig identity $\sin(x)=-\sin(x\pm\pi)$ to reduce to $|x|\le\tfrac{\pi}{2}\text{.}$ Finally you can use the trig identity $\sin(x)=\mp\cos(\tfrac{\pi}{2}\pm x))$ to reduce to $|x|\le\tfrac{\pi}{4} \lt 1\text{.}$ to evaluate sine and cosine at values of $x$ outside this range.

If $|x|\le 1$ radians  14 Recall that the derivative formulae that we used to derive the Taylor polynomials are valid only when $x$ is in radians. The restriction $-1 \leq x \leq 1$ radians translates to angles bounded by $\tfrac{180}{\pi}\approx 57^\circ\text{.}$, then the magnitudes of the successive terms in the Taylor polynomials for $\sin x$ are bounded by

\begin{alignat*}{3} |x|&\le 1 & \tfrac{1}{3!}|x|^3&\le\tfrac{1}{6} & \tfrac{1}{5!}|x|^5&\le\tfrac{1}{120}\approx 0.0083\\ \tfrac{1}{7!}|x|^7&\le\tfrac{1}{7!}\approx 0.0002\quad & \tfrac{1}{9!}|x|^9&\le\tfrac{1}{9!}\approx 0.000003\quad & \tfrac{1}{11!}|x|^{11}&\le\tfrac{1}{11!}\approx 0.000000025 \end{alignat*}

From these inequalities, and the graphs on the previous pages, it certainly looks like, for $x$ not too large, even relatively low degree Taylor polynomials give very good approximations. In Section 3.4.9 we'll see how to get rigorous error bounds on our Taylor polynomial approximations.