Professional Documents
Culture Documents
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.
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)!
3
Any smooth function can be approximated as a polynomial.
Take x = xi+1 Then f(x) ≈ f(xi) zero order approximation
• 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!
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:
• 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
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