Truncation
Errors and
Truncation Errors and
Taylor Series
Taylor Series
By
Dr Ali Ja arneh
Dr Ali Jawarneh
Dr Ali Jawarneh 1
Taylor Series
It provides a mean to predict a function value at one point in terms of the function
value and it’s derivative at another point. In particular, the theorem states that any
f
function can be approximated as a polynomial.
i b i d l i l
∞
1 (n )
f ( x) = ∑ am ( x − x 0 ) n
w e e an = f (x0 )
where
n=0 n!
(x − x0 ) ( x − x 0 )2 ( x − x 0 )3
f ( x) = f ( x 0 ) + f ' (xo ) + f " (xo ) + f " ' ( x o ) + ...
1! 2! 3!
n: Order of the Taylor series or nth‐
n: Order of the Taylor series or nth order approximation
order approximation
Dr Ali Jawarneh 2
Forward Taylor
f " (xi ) 2 f "' (xi ) 3 f (n ) (xi ) n
f ( x i +1 ) = f ( x i ) + f ' ( x i )h + h + h + ... + h + Rn
2! 3! n!
Reminder: R n = O(h n +1 ) St
Step size :
i
f ( n +1) (ξ ) n +1 h = x i +1 − x i
Rn = h Truncation error is of
(n + 1)! the order of hn+1
Reminder term is included to account for all terms from n+1 to infinity.
ξ :is a value of x that lies somewhere between xi and xi+1
O(h): Truncation
Zero order approximation (n=0): f ( x i +1 ) = f ( x i ) + O(h ) error of order h
1st order approximation (n
order approximation (n=1):
1): f ( x i +1 ) = f ( x i ) + f ' ( x i )h + O(h 2 )
f " (xi ) 2
2nd order approximation (n=2): f ( x i +1 ) = f ( x i ) + f ' ( x i )h + h + O( h 3 )
2!
And so on…
Dr Ali Jawarneh 3
Example: Use zero‐through second‐order forward Taylor series
expansions to approximate the function:
expansions to approximate the function:
f(x)=‐0.1x4‐0.15x3‐0.5x2‐0.25x+1.2
At x=1 with h=1.
Solution
xi=0 because h=1 and xi+1=1
Dr Ali Jawarneh 4
True value: f(0)=1.2, f(1)=0.2
Zero order approximation (n=0): f ( x i +1 ) = f ( x i ) + O(h ) f (1) ≅ 1.2
Et = 0.2 − 1.2 = −1.0
1st order approximation (n=1): f ( x i +1 ) = f ( x i ) + f ' ( x i )h + O(h 2 )
f ' ( x i ) = −0.4x 3 − 0.45x 2 − x − 0.25 f ' (0) = −0.25
f (1) = f (0) + f ' (0)[1] = 1.2 − 0.25 * 1 = 0.95
Et = 0.2 − 0.95 = −0.75
2nd order approximation (n=2): f " (xi ) 2
f ( x i +1 ) = f ( x i ) + f ' ( x i )h + h + O( h 3 )
2!
f ' ( x i ) = −0.4x 3 − 0.45x 2 − x − 0.25 f " ( x i ) = −1.2x 2 − 0.9x 2 − 1
f " (0) = −1 f (1) = 1.2 − 0.25(1) + − 1 (1)2 = 0.45 E = 0.2 − 0.45 = −0.25
t
2! 5
Dr Ali Jawarneh
Example: Approximate y= cos(x) from zero-order to six-
order forward Taylor at x=π/3 using a step size oh h= π/12.
π/12
Solution: Switch your calculator to radian
xi=π/4 h π /12 and x
/4 because h=
b d i+1= π/3
/3
Zero order approximation (n=0): f ( x i + 1 ) = f ( x i ) + O( h )
f ( π / 3) = f ( π / 4) = cos( π / 4) = 0.707106781
1st order approximation (n=1):
f ( x i +1 ) = f ( x i ) + f ' ( x i )h + O(h 2 ) f ' ( x i ) = − sin( x i )
f ( π / 3) = cos(π / 4) − sin( π / 4)[π / 12] = 0.521986659
2nd order approximation (n=2):
h + O(h 3 ) f ' ( x i ) = − sin( x i ) f " ( x i ) = − cos( x i )
f "(xi ) 2
f ( x i +1 ) = f ( x i ) + f ' ( x i )h +
2!
f ( π / 3) = cos( π / 4) − sin( π / 4)[π / 12] − cos( π / 4)[π / 12]2 = 0.407754491
Dr Ali Jawarneh 6
Order f(n) (x) f(π/3) |εt|
n
0 cosx 0.707106781
0 707106781 41.4
41 4
1 ‐sinx 0.521986659 4.4
2 ‐cosx 0 407754491
0.407754491 0 449
0.449
3 sinx 0.499869147 0.0262
4 cosx 0.500007551 0.00151
5 ‐sinx 0.500000304 0.0000608
6 ‐cosx 0.499999988 0.00000240
True value: f ( π / 3) = 0.5
Dr Ali Jawarneh 7
Two ways to decrease the
truncation error:
(1) Decrease the step size
(2) Use a higher-order formula
that employs more points
Dr Ali Jawarneh 8
NUMERICAL DIFFERENTIATION
Taylor series
It provides a mean to predict a function value at one point in terms of the
function value and it’s derivative at another point. Taylor series expansions
are used to derive finite-divided-difference approximations of derivatives.
True derivative
f (x)
h=xi+1-xi=xi-xi-1
forward
backward centered
h h
x
x i −1 xi x i +1
(old) (present) (new)
Dr Ali Jawarneh 9
Taylor ∞
f ( x) = ∑ am ( x − x 0 ) n 1 (n )
where a n = f ( x 0 )
Series n=0
n= n!
(x − x0 ) ( x − x 0 )2 ( x − x 0 )3
f ( x) = f ( x 0 ) + f ' (xo ) + f " (xo ) + f " ' ( x o ) + ...
1! 2! 3!
n: is order of the series
Forward Taylor
f "(xi )
f ( x i +1 ) = f ( x i ) + f ' ( x i )( x i +1 − x i ) + ( x i +1 − x i )2 +
2!
(n) h = x i +1 − x i
f "' (xi ) f (xi )
( x i +1 − x i ) 3 + ... + ( x i + 1 − x i )n
3! n!
Backward Taylor
f "(xi )
f ( x i −1 ) = f ( x i ) − f ' ( x i )( x i − x i −1 ) + ( x i − x i −1 ) 2 −
2!
(n )
h = x i − x i −1
f "' (xi ) f (xi )
( x i − x i −1 ) 3 + ... − ... + ( x i − x i −1 )n
3! n!
Dr Ali Jawarneh 10
Forward Taylor
f " (xi ) 2 f "' (xi ) 3 f (n ) (xi ) n
f ( x i +1 ) = f ( x i ) + f ' ( x i )h + h + h + ... + h (1)
2! 3! n!
Zero order ((n=0): ) f ( x i+ i + 1 ) = f ( x i ) + O(h ) O(h): Truncation
error of order h
1st order (n=1): f ( x i +1 ) = f ( x i ) + f ' ( x i )h + O(h 2 )
f " (xi ) 2
2nd order (n=2): f ( x i +1 ) = f ( x i ) + f ' ( x i )h + h + O( h 3 )
2!
Backward Taylor
f " (xi ) 2 f "' (xi ) 3 f (n ) (xi ) n
f ( x i −1 ) = f ( x i ) − f ' ( x i )h + h − h + ... − ... + h (2)
2! 3! n!
Zero order: f ( x i −1 ) = f ( x i ) + O(h )
1st order: f ( x i −1 ) = f ( x i ) − f ' ( x i )h + O(h 2 ) Dr Ali Jawarneh
2nd order: f " (xi ) 2
f ( x i −1 ) = f ( x i ) − f ' ( x i )h + h + O( h 3 )
2! 11
Forward Approximation
f "(xi ) 2 (3)
from (1) f ( x i +1 ) = f ( x i ) + f ' ( x i )h + h + ...
2!
f ( x i +1 ) − f ( x i ) f " ( x i )
f ' (xi ) = + h + ...
h 2!
f ( x i +1 ) − f ( x i )
f ' (xi ) = + O( h ) Forward , 1st derivative of order h
h
f "(xi ) ((4))
Similar to (1) f ( x i + 2 ) = f ( x i ) + f ' ( x i )( 2h ) + ( 2h ) 2 + ...
2!
Multiplication Eq.(3) with 2, then subtract the result from (4), you will get:
f ( x i + 2 ) − 2f ( x i +1 ) + f ( x i ) Forward
F d , 2nd
2 d derivative
d i ti
f "(xi ) = 2
+ O(h ) of order h
h
Dr Ali Jawarneh 12
from (1) f " (xi ) 2 f "' (xi ) 3
f ( x i +1 ) = f ( x i ) + f ' ( x i )h + h + h + ...
2! 3!
Use also Forward , 2nd derivative of order h
f ( x i +1 ) − f ( x i ) f " ( x i ) h 2
f ' (xi ) = − + O( h 2 )
h 2! h
f ( x i +1 ) − f ( x i ) [f ( x i + 2 ) − 2f ( x i +1 ) + f ( x i )] h 2
= − 2
+ O ( h 2
)
h h 2! h
Collecting terms:
− f ( x i + 2 ) + 4f ( x i +1 ) − 3f ( x i ) Forward , 1st derivative
f ' (xi ) = + O( h 2 ) of order h2
2h
Dr Ali Jawarneh 13
Backward Approximation
From (2) f ( x i −1 ) = f ( x i ) − f ' ( x i )h +
f " (xi ) 2 f "' (xi ) 3
h − h + ... (5)
2! 3!
f ( x i ) − f ( x i −1 )
f ' (xi ) = + O(h ) Backward , 1stt derivative of order h
h
f " (xi )
Similar to (2)
f ( x i − 2 ) = f ( x i ) − f ' ( x i )( 2h ) + ( 2h ) 2 − ... (6)
2!
Multiplication Eq.(5) with 2, then subtract the result from (6), you will get:
f ( x i ) − 2f ( x i −1 ) + f ( x i − 2 ) b k
backwardd , 2nd
2 d derivative
d i ti off
f " (xi ) = = O ( h )
h2 order h
Dr Ali Jawarneh 14
from (2) f " (xi ) 2 f "' (xi ) 3
f ( x i −1 ) = f ( x i ) − f ' ( x i )h + h − h +
2! 3!
Use also Backward , 2nd derivative of order h
f ( x i ) − f ( x i −1 ) f ( x i ) − 2f ( x i −1 ) + f ( x i − 2 ) h 2 1
f ' (xi ) = +[ 2
]
h h 2! h
Collecting terms:
3f ( x i ) − 4f ( x i −1 ) + f ( x i − 2 )
f ' (xi ) = 2 + O( h 2 )
h
Dr Ali Jawarneh 15
Centered Approximation
Subtract (1) from (2)
f ( x i + 1 ) − f ( x i −1 )
f ' (xi ) = + O( h 2 )
2h
Dr Ali Jawarneh 16
Simple Comparison
f ( x i +1 ) − f ( x i )
f ' (xi ) = + O( h ) Forward , 1st derivative of order h
h
f ( x i ) − f ( x i −1 )
f ' (xi ) = + O(h ) Backward , 1st derivative of order h
h
f ( x i + 1 ) − f ( x i −1 )
f ' (xi ) = + O( h 2 ) Centered , 1st derivative of order h2
2h
For example, if we halve the step size using a forward
or backward difference, we would approximately halve
the truncation error, whereas for the central difference,
the error would be quartered
Dr Ali Jawarneh 17
Summary of Finite-Divided-Difference Formulas
(1) Forward Finite-Divided-Difference
Finite Divided Difference Formulas
f ( x i +1 ) − f ( x i )
1st derivative: f ' (xi ) = + O( h )
h
− f ( x i + 2 ) + 4f ( x i +1 ) − 3f ( x i )
f ' (xi ) = + O( h 2 ) More accurate
2h
2nd derivative:
f ( x i + 2 ) − 2f ( x i +1 ) + f ( x i )
f "(xi ) = 2
+ O( h )
h
− f ( x i + 3 ) + 4f ( x i + 2 ) − 5f ( x i +1 ) + 2f ( x i )
f "(xi ) = 2
+ O ( h 2
)
h
More accurate
Dr Ali Jawarneh 18
(2) Backward Finite-Divided-Difference
Finite Divided Difference Formulas
f ( x i ) − f ( x i −1 )
1st derivative: f ' (xi ) = + O( h )
h
3f ( x i ) − 4f ( x i −1 ) + f ( x i − 2 )
f ' (xi ) = + O( h 2 ) More accurate
2h
2nd derivative:
f ( x i ) − 2f ( x i −1 ) + f ( x i − 2 )
f "(xi ) = 2
+ O( h )
h
2f ( x i ) − 5f ( x i −1 ) + 4f ( x i − 2 ) − f ( x i − 3 )
f "(xi ) = 2
+ O ( h 2
)
h
More accurate
Dr Ali Jawarneh 19
(3) Centered Finite-Divided-Difference
Finite Divided Difference Formulas
f ( x i + 1 ) − f ( x i −1 )
1st derivative: f ' (xi ) = + O( h 2 )
2h
− f ( x i + 2 ) + 8f ( x i +1 ) − 8f ( x i −1 ) + f ( x i − 2 ) More accurate
f ' (xi ) = + O( h )
4
12h
2nd derivative:
f ( x i +1 ) − 2f ( x i ) + f ( x i −1 )
f "(xi ) = 2
+ O ( h 2
)
h
− f ( x i + 2 ) + 16f ( x i +1 ) − 30f ( x i ) + 16f ( x i −1 ) − f ( x i − 2 )
f "(xi ) = 2
+ O ( h 4
)
12h
More accurate
Dr Ali Jawarneh 20
Two ways to improve derivative
estimates when employing
finite divided differences
(1) Decrease the step size
(2) Use a higher-order formula
that employs more points
Dr Ali Jawarneh 21
Example: Find the first derivative of
f(x)=‐0 1x4‐0.15x
f(x)=‐0.1x ‐0 15x3‐0.5x
‐0 5x2‐0.25x+1.2
‐0 25x+1 2
at x=0.5 using a step size of h= 0.5. Use forward and
backward approximations of O(h), and central difference
i ti off O(h2)
approximation
Solution
f ( x i +1 ) − f ( x i )
Forward f ' ( x i ) = + O( h )
h
f (1) − f (0.5) 0.2 − 0.925 x i −1 xi x i +1
f ' ( 0 .5 ) = = = −1.45 | ε t |= 58.9%
h 0 .5
0 0.5 1
Backward f ( x i ) − f ( x i −1 )
f ' (xi ) = + O(h ) | ε t |= 39.7%
h
f (0.5) − f (0) 0.925 − 1.2
f ' ( 0 .5 ) = = = −0.55
h 0 .5
f ( x i + 1 ) − f ( x i −1 ) f (1) − f (0) 0.2 − 1.2
f ' (xi ) = + O( h 2 ) f ' ( 0 .5 ) = = = − 1 .0
Centered 2h 2h 1
| ε t |= 9.6%
Dr Ali Jawarneh 22
Example: Do the previous example for a step size of
h= 0.25
0 25
Solution
Forward
0.63632813 − 0.925
f ' ( 0 .5 ) = = −1.155 | ε t |= 26.5%
0.25
Backward x i −1
xi x i +1
f ' ( 0 .5 ) =
0.925 − 1.10351563
= −0.714 | ε t |= 21.7%
0.25 0.5 0.75
0.25
0.63632813 − 1.10351563
Centered f ' ( 0 .5 ) = = −0.934 | ε t |= 2.4%
0 .5
Comments on the last two examples:
Comments on the last two examples:
For both step size, the centered difference approximation is more accurate than
forward or backward differences. Also, as predicted by the Taylor series analysis,
halving the step size approximately halves the error of the backward and forward
differences and quarters the error of the centered difference.
Dr Ali Jawarneh 23
Dr Ali Jawarneh 24
Dr Ali Jawarneh 25