Skip to main content

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:

  1. Determine somehow a \(n_0\) such that \(|R_{n_0}(x)| \lt \varepsilon\text{.}\)
  2. 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{.}\)

Subsection 2.3.2 Final comments

There is no general recipe to find the best (or the simplest) upper bound to \(|f^{(n+1)}(\xi)|\text{.}\) The only way to find one is to "give a look" to the derivatives of \(f(x)\) and understanding their behavior.

This happens very often in numerical analysis: there is no general rule to solve in the optimal way all problems of a certain kind. There are general guidelines but ultimately each concrete problem needs some litte adjustments.