Week2 Truncation Err and Taylor Series
Week2 Truncation Err and Taylor Series
Examples:
Summation:
Chopped:
1
Round-off Error due to Arithmetic Operations
Examples:
2
Round-off Error due to Arithmetic Operations
Smearing
Occurs when individual terms are larger than summation
itself. Consider the exponential series with x = -10
5
Truncation Error
Error caused by the nature of the numerical technique
employed to approximate the solution.
Example:
Maclaurin series expansion of ex
2 3 4 5
x x x x
ex 1 x
2! 3! 4! 5!
x2
If we use a truncated version of the series: e 1 x
x
2!
x3 x 4 x5
Then the Truncation Error is:
3! 4! 5!
6
Taylor Series Expansion
Basic Idea:
Predict the value of a function, ƒ, at a point xi+1
based on the value of the function and all of its
derivatives, ƒ, ƒ', ƒ",… at a neighboring point xi
7
Taylor Series Expansion
General Form:
h2 h3 hn n
f (x i1 ) f (x i ) hf (x i ) f (x i ) f (x i ) f (x i ) R n
2! 3! n!
8
Taylor Series Expansion
h2 hn n
f (x i1 ) f (x i ) h f (x i ) f (x i ) f (x i ) O(h n 1)
2! n!
9
Taylor Series Expansion
f(x )
f(xi ) Zero order
f(xi+1 ) f(xi )
x
xi xi+1
h
10
Taylor Series Expansion
General Form:
h2 h3 hn n
f (x i1 ) f (x i ) hf (x i ) f (x i ) f (x i ) f (x i ) R n
2! 3! n!
11
Taylor Series Expansion
Remainder Term: What is ξ ?
If Zero- order approximation: f ( x i 1 ) f ( x i ) Ro Ro
f ' ( )
h
12
Taylor Series Example
Use zero-order to fourth-order Taylor series expansions to
approximate the function.
f(x)= -0.1x4 – 0.15x3 – 0.5x2 – 0.25x +1.2
From xi = 0 with h =1. Predict the function’s value at xi+1 =1.
Solution
f(xi)= f(0)= 1.2 , f(xi+1)= f(1) = 0.2 ………exact solution
• Zero- order approx. (n=0) f(xi+1)=1.2 f ( x i 1 ) f ( x i )
Et = 0.2 – 1.2 = -1.0
• First- order approx. (n=1) f(xi+1)= 0.95 f ( xi 1 ) f ( xi ) f ' ( xi )h
f(x)= -0.4x3 – 0.45x2 – x – 0.25, f’(0)= -0.25
f( xi+1)= 1.2- 0.25h = 0.95
Et = 0.2 - 0.95 = -0.75
13
Taylor Series Example
• Second- order approximation (n=2) f(xi+1)= 0.45
f ' ' ( x i )h 2
f ( x i 1 ) f ( x i ) f ( x i )h
'
2!
f’’(x) = -1.2 x2 – 0.9x -1 , f’’(0)= -1
f( xi+1)= 1.2 - 0.25h - 0.5 h2 = 0.45
Et = 0.2 – 0.45 = -0.25
• Third-order approximation (n=3) f(xi+1)= 0.3
f ' ' ( x i ) h 2 f ( 3) ( x i ) h 3
f ( x ) f ( x i ) f ( x i )h
'
2! 3!
i 1
14
Maclaurin Series
Maclaurin series is a special case of Taylor series
with the center of expansion a = 0.
The Maclauri n series expansion of f ( x ) :
( 2) ( 3)
f ( 0 ) f ( 0) 3
f ( 0) f ( 0) x
'
x
2
x ...
2! 3!
If the series converge, we can write :
∞
1 (k )
f ( x) ∑ k!
f ( 0) x k
k 0
2 3 4 5
x x x x
ex 1 x
2! 3! 4! 5!
15
Maclaurin Series – Example 1
f ( x) e x f ( 0) 1
f ' ( x) e x f ' ( 0) 1
f ( 2) ( x ) e x f ( 2 ) ( 0) 1
f (k ) ( x) e x f ( k ) (0) 1 for k 1
∞ ∞
1 (k ) xk x2 x3
ex ∑ k!
f ( 0) x ∑
k
k!
1 x
2!
3!
...
k 0 k 0
The series converges for x ∞.
16
3
Taylor Series
Example 1
2.5
exp(x)
1+x+0.5x 2
2
1+x
1.5
1
1
0.5
0
-1 -0.8 -0.6 -0.4 -0.2 0 0.2 0.4 0.6 0.8 1
17
Maclaurin Series – Example 2
3
x
0 sin(x)
-1
x-x 3/3!
-2
-3
-4
-4 -3 -2 -1 0 1 2 3 4
19
Numerical Differentiation from Taylor Series Expansion
Objective:
Evaluate the derivatives of function, ƒ(xi), without
doing it analytically.
When would we want to do this?
1. function is too complicated to differentiate
analytically:
2 cos(1 x ) 0.5x
e
1 0.5x
2. function is not defined by an equation,
i.e., given a set of data points (xi, ƒ(xi)), i=1,…,n
i 0 1 2 3 4
xi 1.0 3.0 5.0 7.0 9.0
ƒ(xi) 2.3 4.1 5.5 5.7 5.9
20
Numerical Differentiation from Taylor Series Expansion
Taylor series:
h2 h3 hn n
f (x i1 ) f (x i ) hf (x i ) f (x i ) f (x i ) f (x i ) R n
2! 3! n!
21
First Derivatives: Backward Difference
f ( xi ) f ( xi 1 )
f ' ( xi )
( xi xi 1 )
22
First Derivatives: Backward Difference
h2
f (x i1 ) f (x i ) (x i 1 x i )f '(x i ) f "( )
2
Letting h = xi - xi-1
h2
f (x i1 ) f (x i ) hf '(x i ) f "()
2
h2
hf '(x i ) f (x i ) f (x i 1 ) f "()
2
f (x i ) f (x i1 )
f '(x) O(h) 1st order error
h
first backward difference
23
Example of 1st Backward FDD
f (x1 ) f (x 0 )
f '(x) O(h)
h
4.1 2.3
f '(x1 ) O(h)
2
24
First Derivatives: Forward Difference
f ( x i 1 ) f ( x i )
f ' ( xi )
( x i 1 x i )
25
First Derivatives: Central Difference
f ( xi 1 ) f ( xi 1 )
f ' ( xi )
2h
26
Second Derivatives: Backward Difference
Second Derivative:
x i2 x i 2
f (x i 2 ) f (x i ) x i 2 x i f '(x) f "(x i )
2!
+ O([xi-2– xi]3)
f (x i ) 2f (x i 1 ) f (x i 2 ) O(h 3 )
f "(x i ) 1st order
h2 error
Second backward difference
28
Example of 2nd Backward FDD
29
Numerical Differentiation: Second Derivatives
- Higher order divided differences.
f '' ( xi ) 2
f ( xi 1 ) f ( xi ) f ' ( xi )h h
2!
f '' ( xi ) 2 addition
f ( xi 1 ) f ( xi ) f ' ( xi )h h
2!
30
Other Forms of Numerical Differentiation
Forward:
(x i1 ) (x i )
f '(x i ) O(h)
h 1st order error
(x i 2 ) 2 (x i 1 ) (x i )
f "(x i ) 2
O(h)
h
- f ( xi 2 ) 4 f ( xi 1 ) -3 f ( xi )
f '(x i ) = + O(h 2 ) 2nd order
2h error
Centered:
(x i1 ) (x i1 )
f '(x i ) O(h 2 )
2h 2nd order error
(x i 1 ) 2 (x i ) (x i 1 )
f "(x i ) O(h 2 )
h2
31
Numerical Differentiation: Second Derivatives
- Higher order divided differences.
f '' ( xi ) 2
f ( xi 1 ) f ( xi ) f ' ( xi )h h
2!
f '' ( xi ) 2 addition
f ( xi 1 ) f ( xi ) f ' ( xi )h h
2!
32
Other Forms of Numerical Differentiation
Backward:
…, ƒ(xi-2), ƒ(xi-1), ƒ(xi), ƒ(xi+1), ƒ(xi+2), …
Forward:
…, ƒ(xi-2), ƒ(xi-1), ƒ(xi), ƒ(xi+1), ƒ(xi+2), …
Centered:
…, ƒ(xi-2), ƒ(xi-1), ƒ(xi), ƒ(xi+1), ƒ(xi+2), …
33
Taylor Series and Truncation errors
Questions:
• Which is a better approximation?
Forward, Centered, or Backward?
• Why?
Note:
We also can get higher order forward, centered, and
backward difference derivative approximations
[C&C Chapter 23, tabulated in Figs. 23.1-3]
34
Example Problem 4.4
35
Error Propagation
Error Propagation
Errors which appear because we are basing current
calculations on previous calculations which also incurred
some form of error.
Example:
36
Error Propagation
Stability and Condition Number
Numerically Unstable: Computations which are so
sensitive to round-off errors that errors grow
uncontrollably during calculations.
Condition: sensitivity to such uncertainty; "well
conditioned" vs. "ill conditioned"
Condition Number: measure of the condition; i.e.,
extent to which uncertainty in x is amplified by ƒ(x).
37
Example Combining Roundoff and Truncation Error
ˆ (x h).
(1 ) (x i (1 ) h
).
As a result: f ' =
i
"()
h 2
Roundoff (x i h) (x i ) 2 (x i )
Error h h
38
Example Combining Roundoff and Truncation Error
h 2 f (x i )
E = | Total Error | f "() +
2 h
39
Example Combining Roundoff and Truncation Error
40
46