Application: Using Taylor's Theorem to Approximate Functions.

The material for the remainder of this book was taken from Sean Mauch's Applied mathematics text13.9.

Theorem 13.15.1   Taylor's Theorem of the Mean. If $ f(x)$ is $ n+1$ times continuously differentiable in $ (a,b)$ then there exists a point $ x = \xi \in (a,b)$ such that

$\displaystyle f(b) = f(a) + (b-a) f'(a) + \frac{(b-a)^2}{2!} f''(a) + \cdots + \frac{(b-a)^n}{n!} f^{(n)}(a) + \frac{(b-a)^{n+1}}{(n+1)!} f^{(n+1)}(\xi).$ (13.20)

For the case $ n = 0$, the formula is

$\displaystyle f(b) = f(a) + (b-a) f'(\xi),
$

which is just a rearrangement of the terms in the theorem of the mean,

$\displaystyle f'(\xi) = \frac{f(b) - f(a)}{b-a}.
$

One can use Taylor's theorem to approximate functions with polynomials. Consider an infinitely differentiable function $ f(x)$ and a point $ x = a$. Substituting $ x$ for $ b$ into Equation 13.20 we obtain,

$\displaystyle f(x) = f(a) + (x-a) f'(a) + \frac{(x-a)^2}{2!} f''(a) + \cdots +
\frac{(x-a)^n}{n!} f^{(n)}(a)
+ \frac{(x-a)^{n+1}}{(n+1)!} f^{(n+1)}(\xi).
$

If the last term in the sum is small then we can approximate our function with an $ n^{th}$ order polynomial.

$\displaystyle f(x) \approx f(a) + (x-a) f'(a) + \frac{(x-a)^2}{2!} f''(a) + \cdots +
\frac{(x-a)^n}{n!} f^{(n)}(a)
$

The last term in Equation 13.15 is called the remainder or the error term,

$\displaystyle R_n = \frac{(x-a)^{n+1}}{(n+1)!} f^{(n+1)}(\xi).
$

Since the function is infinitely differentiable, $ f^{(n+1)}(\xi)$ exists and is bounded. Therefore we note that the error must vanish as $ x \to 0$ because of the $ (x-a)^{n+1}$ factor. We therefore suspect that our approximation would be a good one if $ x$ is close to $ a$. Also note that $ n!$ eventually grows faster than $ (x-a)^n$,

$\displaystyle \lim_{n \to \infty} \frac{(x-a)^n}{n!} = 0.
$

So if the derivative term, $ f^{(n+1)}(\xi)$, does not grow to quickly, the error for a certain value of $ x$ will get smaller with increasing $ n$ and the polynomial will become a better approximation of the function. (It is also possible that the derivative factor grows very quickly and the approximation gets worse with increasing $ n$.)

Example 13.15.1   Consider the function $ f(x) = e^x$. We want a polynomial approximation of this function near the point $ x = 0$. Since the derivative of $ e^x$ is $ e^x$, the value of all the derivatives at $ x = 0$ is $ f^{(n)}(0) = e^0 = 1$. Taylor's theorem thus states that

$\displaystyle e^x = 1 + x + \frac{x^2}{2!} + \frac{x^3}{3!} + \cdots + \frac{x^n}{n!}
+ \frac{x^{n+1}}{(n+1)!} e^\xi,
$

for some $ \xi \in (0,x)$. The first few polynomial approximations of the exponent about the point $ x = 0$ are

$\displaystyle f_1(x)$ $\displaystyle = 1$    
$\displaystyle f_2(x)$ $\displaystyle = 1 + x$    
$\displaystyle f_3(x)$ $\displaystyle = 1 + x + \frac{x^2}{2}$    
$\displaystyle f_4(x)$ $\displaystyle = 1 + x + \frac{x^2}{2} + \frac{x^3}{6}$    

The four approximations are graphed in Figure 13.7.

Figure 13.7: Finite Taylor Series Approximations of $ 1$, $ 1+x$, $ 1+x+\frac {x^2}{2}$ to $ e^x$.
\includegraphics[height=6cm,width=8cm]{tayexp3.eps}

Note that for the range of $ x$ we are looking at, the approximations become more accurate as the number of terms increases.

Here is one way to compute these approximations using Sage:

[fontsize=\scriptsize,fontfamily=courier,fontshape=tt,frame=single,label=\sage]

sage: x = var("x")
sage: y = exp(x)
sage: a = lambda n: diff(y,x,n)(0)/factorial(n)
sage: a(0)
1
sage: a(1)
1
sage: a(2)
1/2
sage: a(3)
1/6
sage: taylor = lambda n: sum([a(i)*x^i for i in range(n)])
sage: taylor(2)
x + 1
sage: taylor(3)
x^2/2 + x + 1
sage: taylor(4)
x^3/6 + x^2/2 + x + 1

Example 13.15.2   Consider the function $ f(x) = \cos x$. We want a polynomial approximation of this function near the point $ x = 0$. The first few derivatives of $ f$ are

$\displaystyle f(x)$ $\displaystyle = \cos x$    
$\displaystyle f'(x)$ $\displaystyle = - \sin x$    
$\displaystyle f''(x)$ $\displaystyle = - \cos x$    
$\displaystyle f'''(x)$ $\displaystyle = \sin x$    
$\displaystyle f^{(4)}(x)$ $\displaystyle = \cos x$    

It's easy to pick out the pattern here,

$\displaystyle f^{(n)}(x) =
\begin{cases}
(-1)^{n/2} \cos x &\text{for even } n, \\
(-1)^{(n+1)/2} \sin x & \text{for odd } n.
\end{cases} $

Since $ \cos(0) = 1$ and $ \sin(0) = 0$ the $ n$-term approximation of the cosine is,

$\displaystyle \cos x = 1 - \frac{x^2}{2!} + \frac{x^4}{4!} - \frac{x^6}{6!} + \...
...(-1)^{2(n-1)} \frac{x^{2(n-1)}}{(2(n-1))!}
+ \frac{x^{2n}}{(2n)!} \cos \xi.
$

Here are graphs of the one, two, three and four term approximations.

Figure 13.8: Taylor Series Approximations of $ 1$, $ 1-\frac {x^2}{2}$, $ 1-\frac {x^2}{2}+\frac {x^4}{4!}$ to $ \cos x$.
\includegraphics[height=4cm,width=7cm]{taycos3.eps}

Note that for the range of $ x$ we are looking at, the approximations become more accurate as the number of terms increases. Consider the ten term approximation of the cosine about $ x = 0$,

$\displaystyle \cos x = 1 - \frac{x^2}{2!} + \frac{x^4}{4!} - \cdots - \frac{x^{18}}{18!}
+ \frac{x^{20}}{20!} \cos \xi.
$

Note that for any value of $ \xi$, $ \vert\cos \xi\vert \leq 1$. Therefore the absolute value of the error term satisfies,

$\displaystyle \vert R \vert = \left\vert \frac{x^{20}}{20!} \cos \xi \right\vert \leq \frac{\vert x\vert^{20}}{20!}.
$

Note that the error is very small for $ x < 6$, fairly small but non-negligible for $ x \approx 7$ and large for $ x > 8$. The ten term approximation of the cosine, plotted below, behaves just we would predict.

Figure 13.9: Taylor Series Approximation of $ 1-\frac {x^2}{2}+\frac {x^4}{4!}-\frac {x^6}{6!}+\frac {x^8}{8!}$ to $ \cos x$.
\includegraphics[height=4cm,width=7cm]{taycos10b.eps}

The error is very small until it becomes non-negligible at $ x \approx 7$ and large at $ x \approx 8$.

Example 13.15.3   Consider the function $ f(x) = \ln x$. We want a polynomial approximation of this function near the point $ x=1$. The first few derivatives of $ f$ are

$\displaystyle f(x)$ $\displaystyle = \ln x$    
$\displaystyle f'(x)$ $\displaystyle = \frac{1}{x}$    
$\displaystyle f''(x)$ $\displaystyle = - \frac{1}{x^2}$    
$\displaystyle f'''(x)$ $\displaystyle = \frac{2}{x^3}$    
$\displaystyle f^{(4)}(x)$ $\displaystyle = - \frac{3}{x^4}$    

The derivatives evaluated at $ x=1$ are

$\displaystyle f(1) = 0, \qquad f^{(n)}(1) = (-1)^{n-1} (n-1)!,\ \ \ $    for $\displaystyle n \geq 1.
$

By Taylor's theorem of the mean we have,

$\displaystyle \ln x = (x-1) - \frac{(x-1)^2}{2} + \frac{(x-1)^3}{3} - \frac{(x-...
...-1} \frac{(x-1)^n}{n}
+ (-1)^n \frac{(x-1)^{n+1}}{n+1} \frac{1}{\xi^{n+1}}.
$

Below are plots of the 1, 2, and 3 term approximations.

Figure 13.10: Taylor series (about $ x=1$) approximations of $ x-1$, $ x-1-\frac {(x-1)^2}{2}$, $ x-1-\frac {(x-1)^2}{2}+\frac {(x-1)^3}{3}$ to $ \ln x$.
\includegraphics[height=6cm,width=10cm]{taylnt3.eps}

Note that the approximation gets better on the interval $ (0, 2)$ and worse outside this interval as the number of terms increases. The Taylor series converges to $ \ln x$ only on this interval.

david joyner 2008-11-22