Section 2.3 Case study 2: evaluating the value of a function
The problem we discuss here is: how to evaluate non-polynomial functions? For instance, how to evaluate \(\cos(0.15)\text{?}\) This is a problem of continuous mathematics because \(\cos(x)\) is defined over a continuous set (the real line, or the complex plane if you are brave enough). Polynomial and rational functions can be easily evaluated using just the four operations, but what can we do about trascendental functions such as \(\cos(x)\text{?}\) The answer to the question above comes from TheoremĀ 2.2.1. The term
\begin{equation*}
T_n(x)=f(x_0) + f'(x_0)(x-x_0) + \frac{f''(x_0)}{2!}(x-x_0)^2+\dots+\frac{f^{(n)}(x_0)}{n!}(x-x_0)^n
\end{equation*}
is called the \(n\)-th Taylor polynomial of \(f(x)\) at \(x_0\text{.}\) The term
\begin{equation*}
R_n(x) = \frac{f^{(n+1)}(\xi)}{(n+1)!}(x-x_0)^{n+1}
\end{equation*}
is the remainder term. This is not a polynomial term because \(\xi\) depends, in general, on \(x\) in a trascendental way. We can use Taylor polynomials to evaluate functions and then use the remainder term to evaluate the error due to the approximation. A possible algorithm to evaluate \(f(x)\) from a known value \(f(x_0)\) with an error not larger than \(\varepsilon\) would be the following:
- Determine somehow a \(n_0\) such that \(|R_{n_0}(x)| \lt \varepsilon\text{.}\)
- Evaluate the polynomial \(T_{n_0}(x)\text{.}\)
Subsection 2.3.1 A worked-out example
Let us evaluate \(\cos(0.15)\) with an error not larger than \(\epsilon=0.00001\text{.}\) We know the values of the \(cosine\) function and all its derivatives at the origin, so we will use \(x_0=0\text{.}\) Clearly, \(x=0.15\text{.}\) Recall that
\begin{equation*}
\cos'x=-\sin x, \cos''x=-\cos x,
\end{equation*}
\begin{equation*}
\cos'''x=\sin x, \cos''''x=\cos x.
\end{equation*}
Hence, the Taylor series of \(\cos x\) about \(x_0=0\) is
\begin{equation*}
1-\frac{1}{2!}x^2+\frac{1}{4!}x^4-\frac{1}{6!}x^6+\dots+(-1)^n\frac{1}{(2n)!}x^{2n}
\end{equation*}
The remainder term is
\begin{equation*}
R_n(x)=\frac{\cos^{(n+1)}(\xi)}{(n+1)!}x^{n+1}.
\end{equation*}
Since the derivatives of \(\cos x\) are either \(\pm\cos x\) or \(\pm\sin x\text{,}\)
\begin{equation*}
|\cos^{(n+1)}(\xi)|\leq1
\end{equation*}
no matter what \(\xi\) is. Hence
\begin{equation*}
|R_n(x)|\leq \frac{1}{(n+1)!}x^{n+1}
\end{equation*}
To solve the problem, we just need to find a \(n_0\) such that
\begin{equation*}
\frac{1}{(n_0+1)!}0.15^{n_0+1} \lt 0.00001
\end{equation*}
We use trial & error: for \(n_0=2\text{,}\)
\begin{equation*}
\frac{1}{(n_0+1)!}0.15^{n_0+1} = 0.0005... \hbox{ too big!}
\end{equation*}
For \(n_0=3\text{,}\)
\begin{equation*}
\frac{1}{(n_0+1)!}0.15^{n_0+1} = 0.00002... \hbox{ still too big!}
\end{equation*}
For \(n_0=4\text{,}\)
\begin{equation*}
\frac{1}{(n_0+1)!}0.15^{n_0+1} = 0.0000007... \hbox{ good!}
\end{equation*}
So... what did we find out? That \(T_4(0.15)\) provides an approximation of \(\cos(0.15)\) with an error not larger than \(0.00001\text{.}\) Let's verify this:
\begin{equation*}
T_4(0.15) = 1-\frac{x^2}{2}+\frac{x^4}{24}\bigg|_{x=0.15}=0.988771093...
\end{equation*}
An independent estimate of \(\cos(0.15)\) with 10 exact digits gives
\begin{equation*}
\cos(0.15) = 0.9887710779.
\end{equation*}
Hence actually
\begin{equation*}
|\cos(0.15)-T_4(0.15)| = 0.00000001...
\end{equation*}
which is well below \(0.00001\text{.}\)