Processing math: 100%
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)?

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)?

The answer to the question above comes from Theorem 2.2.1. The term
Tn(x)=f(x0)+fβ€²(x0)(xβˆ’x0)+fβ€³(x0)2!(xβˆ’x0)2+β‹―+f(n)(x0)n!(xβˆ’x0)n
is called the n-th Taylor polynomial of f(x) at x0.

The term
Rn(x)=f(n+1)(ΞΎ)(n+1)!(xβˆ’x0)n+1
is the remainder term. This is not a polynomial term because ΞΎ 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(x0) with an error not larger than Ξ΅ would be the following:

  1. Determine somehow a n0 such that |Rn0(x)|<Ξ΅.
  2. Evaluate the polynomial Tn0(x).

Subsection 2.3.1 A worked-out example

Let us evaluate cos(0.15) with an error not larger than Ο΅=0.00001. We know the values of the cosine function and all its derivatives at the origin, so we will use x0=0. Clearly, x=0.15.

Recall that
cosβ€²x=βˆ’sinx,cosβ€³x=βˆ’cosx,
cos‴x=sinx,cos⁗x=cosx.
Hence, the Taylor series of cosx about x0=0 is
1βˆ’12!x2+14!x4βˆ’16!x6+β‹―+(βˆ’1)n1(2n)!x2n
The remainder term is
Rn(x)=cos(n+1)(ΞΎ)(n+1)!xn+1.
Since the derivatives of cosx are either Β±cosx or Β±sinx,
|cos(n+1)(ΞΎ)|≀1
no matter what ΞΎ is.

Hence
|Rn(x)|≀1(n+1)!xn+1
To solve the problem, we just need to find a n0 such that
1(n0+1)!0.15n0+1<0.00001
We use trial & error: for n0=2,
1(n0+1)!0.15n0+1=0.0005... too big!
For n0=3,
1(n0+1)!0.15n0+1=0.00002... still too big!
For n0=4,
1(n0+1)!0.15n0+1=0.0000007... good!
So... what did we find out? That T4(0.15) provides an approximation of cos(0.15) with an error not larger than 0.00001.

Let's verify this:
T4(0.15)=1βˆ’x22+x424|x=0.15=0.988771093...
An independent estimate of cos(0.15) with 10 exact digits gives
cos(0.15)=0.9887710779.
Hence actually
|cos(0.15)βˆ’T4(0.15)|=0.00000001...
which is well below 0.00001.

Subsection 2.3.2 Final comments

There is no general recipe to find the best (or the simplest) upper bound to |f(n+1)(ΞΎ)|. 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.