0% found this document useful (0 votes)
32 views9 pages

T Ti E DTHTL Si Truncation Errors and The Taylor Series

The document discusses how CPUs approximate non-elementary functions like trigonometric, exponential, and logarithmic functions using Taylor series. It explains that Taylor series provides a means to predict the value of a function at one point based on its value and derivatives at another point. It then provides examples of using Taylor series to approximate the exponential and cosine functions. It notes that adding more terms improves the approximation and that only a few terms are needed for practical purposes.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
32 views9 pages

T Ti E DTHTL Si Truncation Errors and The Taylor Series

The document discusses how CPUs approximate non-elementary functions like trigonometric, exponential, and logarithmic functions using Taylor series. It explains that Taylor series provides a means to predict the value of a function at one point based on its value and derivatives at another point. It then provides examples of using Taylor series to approximate the exponential and cosine functions. It notes that adding more terms improves the approximation and that only a few terms are needed for practical purposes.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

T

Truncation
ti Errors
E andd the
th Taylor
T l Series
S i
Chapter 4

1
How does a CPU compute the following functions for a specific x
va ue?
value?
cos(x) sin(x) ex log(x) etc.

 Non-elementary functions such as trigonometric, exponential, and


others are expressed in an approximate fashion using Taylor series
when their values, derivatives, and integrals are computed.

 Taylor series provides a means to predict the value of a function at


one point in terms of the function value and its derivatives at
another point.

2
Taylor Series (nth order approximation):

f ' ( xi ) f " ( xi ) f ( n ) ( xi )
f ( xi 1 )  f ( xi )  ( xi 1  xi )  ( xi 1  xi )   
2
( xi 1  xi ) n  Rn
1! 2! n!

The Reminder term, Rn, accounts for all terms from (n+1) to infinity.

f ( n 1) ( ) ( n 1)
Rn  h
(n  1)!

Define the step size as h=(xi+1- xi), the series becomes:


f ' ( xi ) f " ( xi ) 2 f ( n ) ( xi ) n
f ( xi 1 )  f ( xi )  h h  h  Rn
1! 2! n!

3
Any smooth function can be approximated as a polynomial.
Take x = xi+1 Then f(x) ≈ f(xi) zero order approximation

f (x)  f (xi )  f ' (xi )(x  xi ) first order approximation

Second order approximation:


f ' ( xi ) f " ( xi )
f ( x)  f ( xi )  ( x  xi )  ( x  xi ) 2
1! 2!
nth order approximation:
f ' ( xi ) f " ( xi ) f ( n ) ( xi )
f ( x)  f ( xi )  ( x  xi )  ( x  xi )   
2
( x  xi ) n  Rn
1! 2! n!

• Each additional term will contribute some improvement to the approximation. Only
if an infinite number of terms are added will the series yield an exact result.

• In most cases, only a few terms will result in an approximation that is close enough
to the true value for practical purposes
Example
Approximate the function f(x) = 1.2 - 0.25x - 0.5x2 - 0.15x3 - 0.1x4
from xi = 0 with h = 1 and predict f(x) at xi+1 = 1.

5
Example:
computing f(x) = ex using Taylor Series expansion
f ' ( xi ) f " ( xi ) f ( n ) ( xi )
f ( xi 1 )  f ( xi )  ( xi 1  xi )  ( xi 1  xi )   
2
( xi 1  xi ) n  Rn
1! 2! n!

Choose x = xi+1 and xi = 0 Then f(xi+1) = f(x) and (xi+1 – xi) = x

Since First Derivative of ex is also ex :


(2.) (ex )” = ex (3.) (ex)”’ = ex, … (nth.) (ex)(n) = ex

As a result we get:
2 3 n Looks familiar?
x x x
e  1 x    ... 
x
M l i series
Maclaurin i for
f ex
2! 3! n!
6
Yet another example:
computing f(x) = cos(x) using Taylor Series expansion
Choose x=xi+1 and xi=0 Then f(xi+1) = f(x) and (xi+1 – xi) = x
Derivatives of cos(x):
(1.) (cos(x) )’ = -sin(x) (2.) (cos(x) )” = -cos(x),
(3.) (cos(x) )”’ = sin(x) (4.) (cos(x) )”” = cos(x),
……
A a result
As lcoswe get:
x2
x  1 
x 4

x6

2! 4! 6!

7
Notes on Taylor expansion:

• Each additional term will contribute some improvement to the


approximation.
i i Only O l if an infinite
i fi i number
b off terms are added
dd d will
ill the
h
series yield an exact result.

• In
I mostt cases, only
l a few
f terms
t will
ill result
lt iin an approximation
i ti that
th t is
i
close enough to the true value for practical purposes

 Reminder value R represents the truncation error


 The order of truncation error is hn+1  R=O(hn+1),
If R=O(h),
( ) halvingg the step
p size will halve the error.
If R=O(h2), halving the step size will quarter the error.

8
Error Propagation
 Let xfl refer to the floating point representation of the real number x.
 Since computer has fixed word length, there is a difference between x and xfl
((round-off
d ff error))
and we would like to estimate the error in the calculation of f(x) :

f ( x fl )  f ( x)  f ( x fl )
• Both x and f(x) are unknown.
• If xfl is close to x, then we can use first order Taylor expansion and compute:

f ( x)  f ( x fl )  f ( x fl )( x  x fl )

f ( x fl )  f ( x fl ) * x
(xfl) and x are known
Result: If ff’(x known, then we can estimate the error using this formula
Solve from Example 4.5 p.95
9

You might also like