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:
- Determine somehow a n0 such that |Rn0(x)|<Ξ΅.
- 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.