03 Truncation Errors
03 Truncation Errors
Truncation Errors
Key Concepts
Truncation errors
Taylor's Series
To approximate functions
To estimate truncation errors
Introduction
How do we calculate
sin( x), cos( x), e x , x y ,
...
...
2! 3!
n! ( n 1)!
Introduction
x2 x3
xn
x n 1
e 1 x
...
...
2! 3!
n! ( n 1)!
x
Taylor's Theorem
Taylor's Theorem: If the function f and its first n+1
derivatives are continuous on an interval containing a
and x, then the value of the function at x is given by
( 3)
f " (a)
f
(a)
2
f ( x) f (a ) f ' (a )( x a)
( x a)
( x a)3 ...
2!
3!
f ( n ) (a)
( x a) n Rn
n!
where the remainder Rn is defined as
Rn
( x t ) n ( n 1)
f
(t )dt
n!
f
(c )
Rn
( x a) n 1
(n 1)!
Taylor Series
( 3)
f " (a )
f
(a )
2
f ( x ) f ( a ) f ' (a )( x a )
( x a)
( x a ) 3 ...
2!
3!
f ( n ) (a )
( x a ) n Rn
n!
Note:
Taylor series of a function f at 0 is also known as the
Maclaurin series of f.
9
n x
( 1)
( 2n )!
n 0
10
Question
2
3
n
n 1
x
x
x
x
ex 1 x
...
...
2! 3!
n! ( n 1)!
11
Truncation Errors
Truncation errors are the errors that result from
using an approximation in place of an exact
mathematical procedure.
Approximation
Truncation Errors
2
3
n
n 1
x
x
x
x
ex 1 x
...
...
2! 3!
n! ( n 1)!
12
...
...
2! 3!
n! ( n 1)!
( x a) n Rn
n!
13
f
(c )
Rn
( x a ) n 1
for some c between a and x
(n 1)!
For f(x) = ex and a = 0, we have f(n+1)(x) = ex. Thus
ec
Rn
x n 1 for some c in [0 , x]
(n 1)!
x
x n 1
(n 1)!
Example
Estimate the truncation error if we calculate e as
1 1 1
1
e 1 ...
1! 2! 3!
7!
Observation
For the same problem, with n = 8, the bound of the truncation
error is
e
R8
9!
0.7491 105
e
R10
0.6810 107
11!
More terms used implies better approximation.
16
17
f ( x ) e x f ( n 1) ( x ) e x
0.01
ec
e
1.1
n 1
n 1
Rn
x
(0.01)
(0.01) n 1
( n 1)!
( n 1)!
( n 1)!
Note:1.1100 is about 13781 > e
1. 1
n 1
12
(0.01) 10
( n 1)!
n=3 Rn=4.583333e-10
n=4 Rn=9.166667e-13
18
f ( x ) e x f ( n 1) ( x ) e x
0.5
ec
e
1.7
n 1
n 1
Rn
x
(0.5)
(0.5) n 1
( n 1)!
( n 1)!
( n 1)!
Note:1.72 is 2.89 > e
n=5 Rn=3.689236e-05
n=0 Rn=8.500000e-01
n=6 Rn=2.635169e-06
n=1 Rn=2.125000e-01
n=7 Rn=1.646980e-07
n=2 Rn=3.541667e-02
n=8 Rn=9.149891e-09
n=3 Rn=4.427083e-03
n=9 Rn=4.574946e-10
n=4 Rn=4.427083e-04
n=10 Rn=2.079521e-11
n=11 Rn=8.664670e-13
20
Exercise
If we want to approximate e10.5 with an error less
than 10-12 using the Taylor series for f(x)=ex at 10,
at least how many terms are needed?
The Taylor series expansion of f ( x ) at 10 is
f ' (10)
f " (10)
f ( n ) (10)
2
f ( x ) f (10)
( x 10)
( x 10) ...
( x 10) n Rn
1!
2!
n!
2
n
(
x
10
)
(
x
10
)
e10 (1 ( x 10)
...
) Rn
2!
n!
f ( n 1) ( c )
Rn
( x 10) n 1 for some c between 10 and x
( n 1)!
Observation
A Taylor series converges rapidly near the
point of expansion and slowly (or not at
all) at more remote points.
22
f " (a) 2
f (a) n
f ( x) f (a) f ' (a)h
h ...
h Rn
2!
n!
f ( n 1) (c) n 1
Rn
h
(n 1)!
f ( n 1) (c ) n 1
n 1
Rn
h O (h )
(n 1)!
Summary
To reduce truncation errors, we can reduce h or/and increase
n.
If we reduce h, the error will get smaller quicker (with less n).
This relationship has no implication on the magnitude of the
errors because the constant term can be huge! It only give us
an estimation on how much the truncation error would reduce
when we reduce h or increase n.
26
Rn
1. By Geometry Series
2. By Integration
3. Alternating Convergent Series Theorem
Note: Some Taylor series expansions may exhibit
certain characteristics which would allow us to use
different methods to approximate the truncation
errors.
27
Rn
tn 1 tn 2 tn 3 ...
tn 1 k tn 1 k 2 tn 1 ...
tn 1 (1 k k 2 k 3 ...)
tn 1
1 k
k tn
Rn
1 k
28
2 4
j 2 j ...
j 2 j
Solution:
Is there a k (0 k < 1) s.t.
|tj+1| k|tj| or |tj+1|/|tj| k
for all j n (n=6)?
If you can find this k, then
k tn
Rn
1 k
3 6 ...
t j 1
tj
t j 1
tj
j 1 2 j 2
2 j
j
1 2
1
6
0.11
k 0.11,
1 2
j 6
t6 3 10 6
k tn
0.11
R6
3 10 6
1 k
1 0.11
29
j n 1
f ( j)
j n 1
f ( x )dx
n
30
S t j
where
j 1
t j ( j 3 1) 1
Solution:
We can pick f(x) = x3 because it would provide a
tight bound for |tj|. That is
1
1
3
j
1 j3
So
Rn
j 1
1
1
dx
3
x
2n 2
31
x2 x3 x4
x
S x ... ( 1)n 1
2
3 4
n
n 1
( 1 x 1)
With n 5,
1 1 1 1
0.7833333340
2 3 4 5
ln 2 0.693
1
R S ln 2 0.09 0.16666
6
Actual error
S 1
Eerror
estimated
using the
althernating
convergent
series
theorem
33
x2 x4 x6
x
S 1 ... ( 1)n
2! 4! 6!
( 2n 1)!
n 0
With n 5,
12 14 16 18
S 1 0.5403025793
2! 4! 6! 8!
cos(1) 0.5403023059
1
7
S cos(1) 2.73 10
2.76 107
10!
Actual error
Eerror
estimated
using the
althernating
convergent
series
theorem
34
Exercise
If the sine series is to be used to compute sin(1) with an
error less than 0.5x10-14, how many terms are needed?
13 15 17 19 111 113 115 117
sin(1) 1
...
3! 5! 7! 9! 11! 13! 15! 17!
R0
R 1 R2
R3
R4
R5
R6
R7
Solution:
This series satisfies the conditions of the Alternating
Convergent Series Theorem.
Solving
1
1
Rn
10 14
( 2n 3)!
2
Exercise
1
1
1
1 4 4 4 ...
90
2
3
4
How many terms should be taken in order to compute
4/90 with an error of at most 0.5x10-8?
Rn tn 1 tn 2
1
...
4
j n 1 ( j 1)
( x 1) 4 dx
Solution (by
integration):
3
3
( x 1)
( n 1)
1
1
8
10
( n 1) 406 n 405
3
3( n 1)
2
Note: If we use f(x) = x-3 (which is easier to analyze) instead of f(x) =
(x+1)-3 to bound the error, we will get n >= 406 (just one more term).
36
Summary
Understand what truncation errors are
Taylor's Series
Derive Taylor's series for a "smooth" function
Understand the characteristics of Taylor's Series
approximation
Estimate truncation errors using the remainder term