Вы находитесь на странице: 1из 20

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 )
• Forward Difference f ' ( x0 ) 
h
f ( x0 )  f ( x0  h)
• Backward Difference f ' ( x0 ) 
h
f ( x0  h)  f ( x0  h)
• Central Difference f ' ( x0 ) 
2h
Question:
• How accurately of these formulas are
approximating the derivative ?
Taylor Expansion Method
• Start with notation

f i  f ( xi ) f i 1  f ( xi 1 ) f 'i  f ' ( xi )
where xi  x0 xi 1  x0  h

• Thus, Taylor expansion of f i 1


about xi is
2 3 4
' h '' h ''' h ''''
f i 1  f i  hfi  fi  fi  fi 
2! 3! 4!
• Solving equation above for f 'i yields
2 3
f  f h h h
f i '  i 1 i
 f i ''  f i '''  f i '''' 
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 ''''
f i 1  f i  hf i  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
h where 2
The Central difference approximation
derived by subtracting the Taylor
expansion of f i 1 and f i 1
Hence, we have
2
' f i 1  f i 1 2 h
fi   (h ) where (h 2 )   f i '''
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)
approximation for i f 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
2
'  f i 2  4 f i 1  3 f i 2 2 h '''
fi   ( h ) , ( h )  fi
2h 3
• Three-point backward difference
approximation
2
' 3 f i  4 f i 1  f i 2 h '''
fi   ( h 2 ) , 2
( h )  fi
2h 3
• 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 i f
using f i , f i 1 , and f i  2 . After adding the
Taylor expansions of f i 1 and f i  2 we
have
'' f i  2  2 f i 1  f i '''
fi  2
  ( h ) , (h)  hf i
h
• In a similar manner we can obtain the BDA
''
and CDA for f i as follows:

Backward Difference Approximation

'' f i  2 f i 1  f i 2 '''
fi  2
 (h) , ( h)  hf i
h
Central Difference Approximation

'' f i 1  2 f i  f i 1 2 2 1 2 ''''
fi  2
 ( h ) , ( h )   h f i
h 12
• 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:

( p) c1 f1  c 2 f 2    c N f N
fi  p
E
h
where Np (N ) N  p 1 ( N 1)
E  c1h fi  c2 h fi
• c1 , c 2 , c3 ,  , c N , c1 and c2 are
the undetermined coefficients that to
determine.

Example:
'''
Derive the difference approximation for fi
by using f i , f i 1 , f i  2 , and f i 3 . By
Generic algorithm yields
'''ci f i  ci 1 f i 1  ci  2 f i  2  ci 3 f i 3
fi  3
 E
h
• By introducing the Taylor expansion
of f i 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  3
  ( h )
h
3 ''''
where (h)   hf i
2
Application
A function table is given as follows:

x f
-0.1 4.157
0 4.020
Question: 0.2 4.441

1. Derive the best difference approximation to


calculate with the data given !
f ' ( 0)
2. Calculate by the formula you
f ' ( 0)
derived !
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
f iand
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

Вам также может понравиться