© Springer Nature Switzerland AG 2018
Michael Oberguggenberger and Alexander OstermannAnalysis for Computer ScientistsUndergraduate Topics in Computer Sciencehttps://doi.org/10.1007/978-3-319-91155-7_12

12. Taylor Series

Michael Oberguggenberger1   and Alexander Ostermann1  
(1)
University of Innsbruck, Innsbruck, Austria
 
 
Michael Oberguggenberger (Corresponding author)
 
Alexander Ostermann

Approximations of complicated functions by simpler functions play a vital part in applied mathematics. Starting with the concept of linear approximation we discuss the approximation of a function by Taylor polynomials and by Taylor series in this chapter. As important applications we will use Taylor series to compute limits of functions and to analyse various approximation formulas.

12.1 Taylor’s Formula

In this section we consider the approximation of sufficiently smooth functions by polynomials as well as applications of these approximations. We have already seen an approximation formula in Chap. 7: Let f be a function that is differentiable at a. Then
$$ f(x)\ \approx \ g(x) = f(a) + f'(a) \cdot (x-a), $$
for all x close to a. The linear approximation g is a polynomial of degree 1 in x, and its graph is just the tangent to f at a. We now want to generalise this approximation result.

Proposition 12.1

(Taylor’s formula1)   Let $$I \subseteq \mathbb R$$ be an open interval and f: $$I \rightarrow \mathbb R$$ an $$(n+1)$$-times continuously differentiable function (i.e., the derivative of order $$(n+1)$$ of f exists and is continuous). Then, for all $$x, a \in I$$,
$$\begin{aligned} f(x)&= f(a) + f'(a) \cdot (x-a) + \frac{f''(a)}{2!}\, (x-a)^2 +\cdots + \frac{f^{(n)}(a)}{n!}\, (x-a)^n \\&\quad + R_{n+1} (x, a) \end{aligned}$$
with the remainder term (in integral form)
$$ R_{n+1} (x, a) = \frac{1}{n!} \, \int ^x_a (x-t)^n f^{(n+1)}\, (t) \, \mathrm {d}t. $$
Alternatively the remainder term can be expressed by
$$ R_{n+1} (x, a) = \frac{f^{(n+1)} (\xi )}{(n+1)!}\, (x-a)^{n+1}, $$
where $$\xi $$ is a point between a and x (Lagrange’s2 form of the remainder term) .

Proof

According to the fundamental theorem of calculus, we have
$$ \int ^x_a \! f'(t)\, \mathrm {d}t = f(x) - f(a), $$
and thus
$$ f(x) = f(a) + \int ^x_a \!f'(t) \, \mathrm {d}t. $$
We apply integration by parts to this formula. Due to
$$ \int ^x_a \!u'(t)v(t)\, \mathrm {d}t = u(t) v(t) \Big |^x_a - \int ^x_a \!u(t) v'(t) \, \mathrm {d}t $$
with $$u(t) = t-x$$ and $$v(t) = f'(t)$$ we get
$$\begin{aligned} f(x)= & {} f(a) + (t-x) f'(t) \Big |^x_a - \int ^x_a \!(t-x) f''(t) \, \mathrm {d}t\\= & {} f(a)+ f'(a) \cdot (x-a) + \int ^x_a \!(x-t) f''(t) \, \mathrm {d}t. \end{aligned}$$
A further integration by parts yields
$$\begin{aligned} \int ^x_a \!(x-t) f''(t) \, \mathrm {d}t= & {} - \frac{(x-t)^2}{2} f''(t) \Big |^x_a + \int ^x_a \!\frac{(x-t)^2}{2} f'''(t)\, \mathrm {d}t\\= & {} \frac{f''(a)}{2} (x-a)^2 + \frac{1}{2} \int ^x_a \!(x-t)^2 f'''(t)\, \mathrm {d}t, \end{aligned}$$
and one recognises that repeated integration by parts leads to the desired formula (with the remainder term in integral form). The other representation of the remainder term follows from the mean value theorem for integrals [4, Chap. 5, Theorem 5.4].

$$\square $$

Example 12.2

(Important special case)   If one sets $$x = a+h$$ and replaces a by x in Taylor’s formula, then one obtains
$$ f(x+h) = f(x) + h \, f'(x) + \frac{h^2}{2}\, f''(x) +\cdots + \frac{h^n}{n!} \, f^{(n)} (x) + \frac{h^{n+1}}{(n+1)!}\, f^{(n+1)} (\xi ) $$
with a point $$\xi $$ between x and $$x+h$$. For small h this formula describes how the function f behaves near x.

Remark 12.3

Often one does not know the remainder term
$$ R_{n+1} (x, a) = \frac{f^{(n+1)} (\xi )}{(n+1)!}\,(x-a)^{n+1} $$
explicitly since $$\xi $$ is unknown in general. Let M be the supremum of $$\left| f^{(n+1)}\right| $$ in the considered interval around a. For x in this interval we obtain the bound
$$ \bigl |R_{n+1}(x, a)\bigr | \ \le \ \frac{M}{(n+1)!}(x-a)^{n+1}. $$
The remainder term is thus bounded by a constant times $$h^{n+1}$$, where $$h=x-a$$. In this situation, one writes for short
$$ R_{n+1}(a+h, a) = {\mathcal O}(h^{n+1}) $$
as $$h\rightarrow 0$$ and calls the remainder a term of order $$n+1$$. This notation is also used by maple.

Definition 12.4

The polynomial
$$ T_n (x, a) = f(a) + f'(a) \cdot (x-a) +\cdots + \frac{f^{(n)}(a)}{n!} (x-a)^n $$
is called nth Taylor polynomial of f around the point of expansion a.

The graphs of the functions $$y = T_n (x, a)$$ and $$y = f(x)$$ both pass through the point (af(a)). Their tangents in this point have the same slope $$T_n'(x, a) = f'(a)$$ and the graphs have the same curvature (due to $$T_n''(x, a) = f''(a)$$, see Chap. 14). It depends on the size of the remainder term how well the Taylor polynomial approximates the function.

Example 12.5

(Taylor polynomial of the exponential function)   Let $$f(x) = \mathrm {e}^x$$ and $$a = 0$$. Due to $$(\mathrm {e}^x)' = \mathrm {e}^x$$ we have $$f^{(k)} (0) = \mathrm {e}^0 = 1$$ for all $$k \ge 0$$ and hence
$$ \mathrm {e}^x = 1 + x + \frac{x^2}{2} +\cdots + \frac{x^n}{n!} + \frac{\mathrm {e}^{\xi }}{(n+1)!}\, x^{n+1}, $$
where $$\xi $$ denotes a point between 0 and x. We want to determine the minimal degree of the Taylor polynomial which approximates the function in the interval [0, 1], correct to 5 digits. For that we require the following bound on the remainder term
$$ \left| \,\mathrm {e}^x- 1 - x -\cdots - \frac{x^n}{n!}\,\right| = \frac{\mathrm {e}^{\xi }}{(n+1)!}\, x^{n+1} \le 10 ^{-5}. $$
Note that $$x\in [0,1]$$ as well as $$\mathrm {e}^\xi $$ are non-negative. The above remainder will be maximal for $$x = \xi = 1$$. Thus we determine n from the inequality $$\mathrm {e}/(n+1)!\le 10^{-5}$$. Due to $$\mathrm {e}\approx 3$$ this inequality is certainly fulfilled from $$n = 8$$ onwards; in particular,
$$ \mathrm {e}= 1 + 1 + \frac{1}{2} +\cdots + \frac{1}{8!} \pm 10^{-5}. $$
One has to choose $$n \ge 8$$ in order to determine the first 5 digits of $$\mathrm {e}$$ .

Experiment 12.6

Repeat the above calculations with the help of the maple worksheet mp12_1.mws. In this worksheet the required maple commands for Taylor’s formula are explained.

Example 12.7

(Taylor polynomial of the sine function)   Let $$f(x) = \sin x$$ and $$a = 0$$. Recall that $$(\sin x)' = \cos x$$ and $$(\cos x)' = - \sin x$$ as well as $$\sin 0 = 0$$ and $$\cos 0 = 1$$. Therefore,
$$\begin{aligned} \sin x= & {} \sum ^{2n+1}_{k=0} \, \frac{\sin ^{(k)}(0)}{k!}\, x^k + R_{2n+2} (x, 0)= \\= & {} x - \frac{x^3}{3!} + \frac{x^5}{5!} - \frac{x^7}{7!}+\cdots + (-1)^n \, \frac{x^{2n+1}}{(2n+1)!} + R_{2n+2} (x, 0). \end{aligned}$$
Note that the Taylor polynomial consists of odd powers of x only. According to Taylor’s formula, the remainder has the form
$$ R_{2n+2} (x, 0) = \frac{\sin ^{(2n+2)} (\xi )}{(2n + 2)!}\, x^{2n+2}. $$
Since all derivatives of the sine function are bounded by 1, we obtain
$$ | R_{2n+2} (x, 0)| \le \frac{x^{2n+2}}{(2n + 2)!}. $$
For fixed x the remainder term tends to zero as $$n \rightarrow \infty $$, since the expression $$x^{2n+2}/(2n+2)!$$ is a summand of the exponential series, which converges for all $$x \in \mathbb R$$. The above estimate can be interpreted as follows: For every $$x \in \mathbb R$$ and $$\varepsilon >0$$, there exists an integer $$N \in \mathbb N$$ such that the difference of the sine function and its nth Taylor polynomial is small; more precisely,
$$ |\sin t - T_n(t, 0)| \le \varepsilon $$
for all $$n\ge N$$ and $$t\in [-x, x]$$.

Experiment 12.8

Using the maple worksheet mp12_2.mws compute the Taylor polynomials of $$\sin x$$ around the point 0 and determine the accuracy of the approximation (by plotting the difference to $$\sin x$$). In order to achieve high accuracy for large x, the degree of the polynomials has to be chosen sufficiently high. Due to rounding errors, however, this procedure quickly reaches its limits (unless one increases the number of significant digits).

Example 12.9

The 4th degree Taylor polynomial $$T_4(x, 0)$$ of the function
$$ f(x) = {\left\{ \begin{array}{ll} \displaystyle \frac{x}{\mathrm {e}^x-1} \quad &{} x \ne 0,\\ \ 1 &{} x = 0, \end{array}\right. } $$
is given by
$$ T_4(x, 0) = 1 - \frac{x}{2} + \frac{1}{12}\, x^2 - \frac{1}{720}\, x^4. $$

Experiment 12.10

The maple worksheet mp12_3.mws shows that, for sufficiently large n, the Taylor polynomial of degree n gives a good approximation to the function from Example 12.9 on closed subintervals of $$(-2\pi , 2\pi )$$. For $$x \ge 2 \pi $$ (as well as for $$x \le - 2\pi $$) the Taylor polynomial is, however, useless.

12.2 Taylor’s Theorem

The last example gives rise to the question for which points the Taylor polynomial converges to the function as $$n \rightarrow \infty $$.

Definition 12.11

Let $$I \subseteq \mathbb R$$ be an open interval and let f: $$I \rightarrow \mathbb R$$ have arbitrarily many derivatives. Given $$a \in I$$, the series
$$ T(x,a, f) = \sum _{k=0}^\infty \, \frac{f^{(k)}(a)}{k!}\, (x-a)^k $$
is called Taylor series of f around the point a.

Proposition 12.12

(Taylor’s theorem)   Let f: $$I \rightarrow \mathbb R$$ be a function with arbitrarily many derivatives and let T(xaf) be its Taylor series around the point a. Then the function and its Taylor series coincide at $$x \in I$$, i.e.,
$$ f(x) = \sum _{k=0}^\infty \, \frac{f^{(k)} (a)}{k!} (x-a)^k, $$
if and only if the remainder term
$$ R_n(x, a) = \frac{f^{(n)}(\xi )}{n!}\, (x-a)^n $$
tends to 0 as $$n \rightarrow \infty $$.

Proof

According to Taylor’s formula (Proposition 12.1),
$$ f(x) - T_n(x, a) = R_{n+1} (x, a) $$
and hence
$$ f(x) = \lim _{n \rightarrow \infty } T_n (x,a) = T(x,a,f) \quad \Leftrightarrow \quad \lim _{n \rightarrow \infty } R_n (x, a) = 0, $$
which was to be shown. $$\square $$

Example 12.13

Let $$f(x) = \sin x$$ and $$a = 0$$. Due to $$R_n (x, 0) = \frac{\sin ^{(n)}(\xi )}{n!}\, x^n$$ we have
$$ |R_n (x, 0)| \le \frac{|x|^n}{n!} \rightarrow 0 $$
for x fixed and $$n \rightarrow \infty $$. Hence for all $$x \in \mathbb R$$
$$ \sin x = \sum ^\infty _{k =0} (-1)^k \, \frac{x^{2k +1}}{(2k+1)!} = x - \frac{x^3}{3!} + \frac{x^5}{5!} - \frac{x^7}{7!} + \frac{x^9}{9!} \mp \ldots $$

12.3 Applications of Taylor’s Formula

To complete this chapter we discuss a few important applications of Taylor’s formula.

Application 12.14

(Extremum test)   Let the function f: $$I \rightarrow \mathbb R$$ be n-times continuously differentiable in the interval I and assume that
$$ f'(a) = f''(a) =\cdots = f^{(n-1)} (a) = 0\ \;\text {and}\;\ f^{(n)} (a) \ne 0. $$
Then the following assertions hold:
  1. (a)

    The function f has an extremum at a if and only if n is even;

     
  2. (b)

    if n is even and $$f^{(n)}(a) > 0$$, then a is a local minimum of f;

    if n is even and $$f^{(n)}(a) < 0$$, then a is a local maximum of f.

     

Proof

Due to Taylor’s formula, we have
$$ f(x) - f(a) = \frac{f^{(n)} (\xi )}{n!} \, (x-a)^n, \qquad x\in I. $$
If x is close to a, $$f^{(n)}(\xi )$$ and $$f^{(n)}(a)$$ have the same sign (since $$f^{(n)}$$ is continuous). For n odd the right-hand side changes its sign at $$x = a$$ because of the term $$(x-a)^n$$. Hence an extremum can only occur for n even. If now n is even and $$f^{(n)}(a) > 0$$ then $$f(x) > f(a)$$ for all x close to a with $$x \ne a$$. Thus a is a local minimum. $$\square $$

Example 12.15

The polynomial $$f(x) = 6+4x+6x^2+4x^3+x^4$$ has the derivatives
$$ f'(-1) = f''(-1) = f'''(-1) = 0,\ f^{(4)}(-1) = 24 $$
at the point $$x=-1$$. Hence $$x=-1$$ is a local minimum of f.

Application 12.16

(Computation of limits of functions)   As an example, we investigate the function
$$ g(x) = \frac{x^2 \log (1+x)}{(1-\cos x)\sin x} $$
in the neighbourhood of $$x = 0$$. For $$x = 0$$ we obtain the undefined expression $$\frac{0}{0}$$. In order to determine the limit when x tends to 0, we expand all appearing functions in Taylor polynomials around the point $$a=0$$. Exercise 1 yields that $$\cos x = 1- \frac{x^2}{2} + {\mathcal O}(x^4)$$. Taylor’s formula for $$\log (1+x)$$ around the point $$a=0$$ reads
$$ \log (1+x) = x + {\mathcal O}(x^2) $$
because of $$\log 1 = 0$$ and $$\log (1+x)'|_{x=0} = 1$$. We thus obtain
$$ g(x) = \frac{x^2\bigl (x + {\mathcal O}(x^2)\bigr )}{\bigl (1-1+\frac{x^2}{2}+{\mathcal O}(x^4)\bigr )\bigl (x + {\mathcal O}(x^3)\bigr )} = \frac{x^3 + {\mathcal O}(x^4)}{\frac{x^3}{2} + {\mathcal O}(x^5)} = \frac{1+{\mathcal O}(x)}{\frac{1}{2} + {\mathcal O}(x^2)} $$
and consequently $$\displaystyle \lim _{x \rightarrow 0} g(x) = 2$$.

Application 12.17

(Analysis of approximation formulas)   When differentiating numerically in Chap. 7, we considered the symmetric difference quotient
$$ f''(x)\approx \frac{f(x+h) - 2f(x) + f(x-h)}{h^2} $$
as an approximation to the second derivative $$f''(x)$$. We are now in the position to investigate the accuracy of this formula. From
$$\begin{aligned} f(x+h)= & {} f(x) + h f'(x) + \frac{h^2}{2} f''(x) + \frac{h^3}{6} f'''(x) + {\mathcal O}(h^4),\\ f(x-h)= & {} f(x) - h f'(x) + \frac{h^2}{2} f''(x) - \frac{h^3}{6} f'''(x) + {\mathcal O}(h^4) \end{aligned}$$
we infer that
$$ f(x+h) + f(x-h) = 2f(x) + h^2 f''(x) + {\mathcal O}(h^4) $$
and hence
$$ \frac{f(x+h) - 2f(x) + f(x-h)}{h^2} = f''(x) + {\mathcal O}(h^2). $$
One calls this formula second-order accurate. If one reduces h by the factor $$\lambda $$, then the error reduces by the factor $$\lambda ^2$$, as long as rounding errors do not play a decisive role.

Application 12.18

(Integration of functions that do not possess elementary integrals)   As already mentioned in Sect. 10.​2 there are functions whose antiderivatives cannot be expressed as combinations of elementary functions. For example, the function $$f(x) = \mathrm {e}^{-x^2}$$ does not have an elementary integral. In order to compute the definite integral
$$ \int ^1_0 \mathrm {e}^{-x^2} \, \mathrm {d}x, $$
we approximate $$\mathrm {e}^{-x^2}$$ by the Taylor polynomial of degree 8
$$ \mathrm {e}^{-x^2} \ \approx \ 1 - x^2 + \frac{x^4}{2} - \frac{x^6}{6} + \frac{x^8}{24} $$
and approximate the integral sought after by
$$ \int ^1_0 \left( 1 - x^2 + \frac{x^4}{2} - \frac{x^6}{6} + \frac{x^8}{24}\right) \mathrm {d}x = \frac{5651}{7560}. $$
The error of this approximation is $$6.63 \cdot 10^{-4}$$. For more precise results one takes a Taylor polynomial of a higher degree.

Experiment 12.19

Using the maple worksheet mp12_4.mws repeat the calculations from Application 12.18. Subsequently modify the program such that you can integrate $$g(x) = \cos \!\big (x^2\big )$$ with it.

12.4 Exercises

1.

Compute the Taylor polynomials of degree 0, 1, 2, 3 and 4 of the function $$g(x) = \cos x $$ around the point of expansion $$a = 0$$. For which $$x \in \mathbb R$$ does the Taylor series of $$\cos x$$ converge?

2.

Compute the Taylor polynomials of degree 1, 3 and 5 of the function $$\sin x$$ around the point of expansion $$a=9\pi $$. Further, compute the Taylor polynomial of degree 39 with maple and plot the graph together with the graph of the function in the interval $$[0,18\pi ]$$. In order to be able to better distinguish the two graphs you should plot them in different colours.

3.

Compute the Taylor polynomials of degree 1, 2 and 3 of the function $$f(t) = \sqrt{1+t}$$ around the point of expansion $$a = 0$$. Further compute the Taylor polynomial of degree 10 with maple.

4.
Compute the following limits using Taylor series expansion:
$$\begin{aligned}&\lim _{x \rightarrow 0} \ \frac{x \sin x - x^2}{2 \cos x - 2 + x^2} , \qquad \lim _{x \rightarrow 0} \ \frac{\mathrm{e}^{2x} - 1 - 2x}{\sin ^{2}x},\\&\lim _{x\rightarrow 0}\frac{\text {e}^{-x^2}-1}{\sin ^2(3x)}, \qquad \qquad \qquad \lim _{x\rightarrow 0}\frac{x^2\bigl (\log (1-2x)\bigr )^2}{1-\cos (x^2)}. \end{aligned}$$
Verify your results with maple.
5.
For the approximate evaluation of the integral
$$ \int _0^1\frac{\sin (t^2)}{t} \,\text {d}t $$
replace the integrand by its Taylor polynomial of degree 9 and integrate this polynomial. Verify your result with maple.
6.
Prove the formula
$$ \mathrm {e}^{I\varphi } =\cos \varphi +I\sin \varphi $$
by substituting the value $$I\varphi $$ for x into the series of the exponential function
$$ \mathrm {e}^x = \sum _{k=0}^\infty \frac{x^k}{k!} $$
and separating real and imaginary parts.
7.

Compute the Taylor series of the hyperbolic functions $$f(x) = \sinh x$$ and $$g(x) = \cosh x$$ around the point of expansion $$a = 0$$ and verify the convergence of the series.

Hint. Compute the Taylor polynomials of degree $$n-1$$ and show that the remainder terms $$R_{n}(x, 0)$$ can be estimated by $$(\cosh M) M^{n} /n!$$ whenever $$|x|\le M$$.

8.
Show that the Taylor series of $$f(x) = \log (1+x)$$ around $$a= 0$$ is given by
$$ \log (1+x) = \sum _{k = 1}^\infty (-1)^{k-1}\frac{x^k}{k} = x - \frac{x^2}{2} + \frac{x^3}{3} - \frac{x^4}{4} \pm \ldots $$
for $$|x|<1$$.
Hint. A formal calculation, namely an integration of the geometric series expansion
$$ \frac{1}{1+t} = \frac{1}{1-(-t)} = \sum _{j=0}^\infty (-1)^j t^j $$
from $$t=0$$ to $$t = x$$, suggests the result. For a rigorous proof of convergence, the remainder term has to be estimated. This can be done by integrating the remainder term in the geometric series
$$ \frac{1}{1+t} - \sum _{j=0}^{n-1} (-1)^j t^j = \frac{1}{1+t} - \frac{1-(-1)^{n}t^{n}}{1+t} = \frac{(-1)^{n}t^{n}}{1+t}, $$
observing that $$1+t \ge \delta {\!} >{\!} 0$$ for some positive constant $$\delta $$ as long as $$|t|\le |x| < 1$$.