NUMERICAL DIFFERENTIATION - BLOG PENCARI CAHAYA ILAHI
Download
Report
Transcript NUMERICAL DIFFERENTIATION - BLOG PENCARI CAHAYA ILAHI
NUMERICAL
DIFFERENTIATION
or
DIFFERENCE APPROXIMATION
• Used to evaluate derivatives of a
function using the functional
values at grid points. They are
important in the numerical
solution of both ordinary and
partial differential equations.
Methods of
Approximation
• Forward Difference
• Backward Difference
• Central Difference
Example:
Graph the first derivative from
equation
x
3
f ( x) e x 1
for x0 1
Mathematical formulas for those
three graphs are as follows:
f ( x0 h) f ( x0 )
f ' ( x0 )
• Forward Difference
h
f ( x0 ) f ( x0 h)
• Backward Difference f ' ( x0 )
h
• Central Difference
f ( x0 h) f ( x0 h)
f ' ( x0 )
2h
Question:
• How accurately of these formulas are
approximating the derivative ?
Taylor Expansion Method
• Start with notation
fi f ( xi )
where
fi1 f ( xi1 )
xi x0
f 'i f ' ( xi )
xi1 x0 h
• Thus, Taylor expansion of
about xi is
2
3
fi1
4
h '' h ''' h ''''
fi 1 fi hfi
fi
fi
fi
2!
3!
4!
'
• Solving equation above for f 'i
yields
2
3
f
f
h
h
h
'
''
'''
''''
i 1
i
fi
fi
fi
fi
h
2!
3!
4!
Truncated after first term yield
forward difference approximation
f i 1 f i
fi
h
'
The remainder terms constitute the
truncation error. Thus, the FDA is
expressed, including the truncation
error effect, as
f i 1 f i
h ''
fi
(h) where (h) f i
h
2
'
• The first derivative with backward
difference approximation is
approximated by using Taylor expansion
yield
2
3
4
h '' h ''' h ''''
fi 1 fi hfi
fi
fi
fi
2!
3!
4!
'
• Hence, the BDA is expressed, including
the truncation error effect, as
f i f i 1
h ''
fi
( h)
(
h
)
f
i
where
h
2
'
The Central difference approximation
derived by subtracting the Taylor
expansion of f
and f
i 1
i 1
Hence, we have
2
f
f
h '''
'
2 where
i 1
i 1
2
fi
( h )
( h )
fi
2h
6
Conclusion:
• The truncation error of FDA and BDA is
proportional to h and the truncation error of
2
h
CDA is proportional to . Hence, when h is
decreased, the error of CDA decreases more
rapidly than in the other.
Question:
• Could we derive a more accurate difference
approximation ?
• How about the derivative of higher degree ?
• As obtained above, a difference
( p)
f
approximation for i
needs at least p+1
data points. If more data points are used, a
more accurate difference approximation may
be derived.
Example:
• Three-point forward difference approximation
fi 2 4 fi1 3 fi
'
fi
(h 2 ) ,
2h
• Three-point backward difference
approximation
3 fi 4 fi 1 fi2
2
fi
(h ) ,
2h
'
2
h
(h 2 )
fi'''
3
2
h '''
(h )
fi
3
2
• To derive the difference approximation for
the n-th derivative, we must to eliminate the
first until (n-1)-th derivative from the Taylor
expansions.
Example:
Obtain a difference approximation for f i ''
using f i , fi 1 , and f i 2 . After adding the
Taylor expansions of
fi1 and f i 2
we
have
fi 2 2 f i1 fi
fi
(
h
)
,
2
h
''
(h) hfi
'''
• In a similar manner we can obtain the BDA
and CDA for f '' as follows:
i
Backward Difference Approximation
f i 2 f i 1 f i 2
'''
fi
(h) , (h) hfi
2
h
''
Central Difference Approximation
fi 1 2 f i f i1
1 2 ''''
2
2
fi
(
h
)
,
(
h
)
h
f
i
2
12
h
''
• Furthermore, by adding the number of points
we can derive a more accurate
approximation or higher order of derivation.
• Nevertheless, the method as we discuss
becomes more cumbersome as the number
of points or the order of derivative increases.
• For this reason, a more systematic algorithm
will be discussed in the next. This algorithm
is called Generic Algorithm.
GENERIC ALGORITHM
• Suppose that the total number of the grid
points is N and the grid points are numbered
as i 1, 2 , 3 ,, N . Assume N p 1
where p is the order of the derivative to be
approximated. The difference approximation
for the p-th derivative is written in the form:
fi
( p)
where
c1 f1 c2 f2 c N f N
h
E c1h
Np
fi
p
(N )
c2 h
N p 1
fi
E
( N 1)
•
, c1 and c2
c1 , c2 , c3 , , c N
are
the undetermined coefficients that to
determine.
Example:
Derive the difference approximation for
by using
f i , fi1 , f i 2
, and
f i 3
fi
'''
. By
Generic algorithm yields
ci f i ci 1 f i 1 ci 2 f i 2 ci 3 f i 3
fi
E
3
h
'''
• By introducing the Taylor expansion
of fi 1 , f i 2 , and f i 3
into equation
above yields
f i 3 f i 1 3 f i 2 f i 3
fi
(
h
)
3
h
'''
where
3 ''''
(h) hfi
2
Application
A function table is given as follows:
Question:
x
f
-0.1
4.157
0
4.020
0.2
4.441
1. Derive the best difference approximation
to calculate
2. Calculate
derived !
f ' (0) with the data given !
f ' (0) by the formula you
Answer:
Following the table we defined h = 0.1.
Therefore, we have i = 0, i -1 = -0.1
and i + 2 = 0.2. By using generic
algorithm yields
a1 f i 1 a2 f i a2 f i 2
fi
E
h
'
introducing the Taylor expansions of f i 1
and f i 2 into equation above yields
4 f i 1 3 f i f i 2
fi
E
6h
'
Hence, we have
4 f (0.1) 3 f (0) f (0.2)
f ' (0)
6(0.1)
0.2117
See you
next week