Finite Difference Method
Finite Difference Method Motivation For a given smooth function ! - - PowerPoint PPT Presentation
Finite Difference Method Motivation For a given smooth function ! - - PowerPoint PPT Presentation
Finite Difference Method Motivation For a given smooth function ! " , we want to calculate the derivative ! " at a given value of ". I = -0 Suppose we dont know how to compute the analytical expression for ! " , or
Motivation
For a given smooth function ! " , we want to calculate the derivative !′ " at a given value of ". Suppose we don’t know how to compute the analytical expression for !′ " ,
- r it is computationally very expensive. However you do know how to evaluate
the function value: We know that:
!′ # = lim
!→#
! # + ℎ − !(#) ℎ
Can we just use !′ " ≈
! "#$ %! " $
as an approximation? How do we choose ℎ? Can we get estimate the error of our approximation?
=
I
N
I
For a differentiable function !: ℛ → ℛ, the derivative is defined as:
&′ ( = lim
!→#& ( + ℎ − &(() ℎ
Taylor Series centered at %, where ̅ % = % + ℎ
& ( + ℎ = & ( + &$ ( ℎ + &′′ (
!! % +&′′′ ( !" & + ⋯& ( + ℎ = & ( + &$ ( ℎ + 3(ℎ%)
We define the Forward Finite Difference as: Therefore, the truncation error of the forward finite difference approximation is bounded by:
Finite difference method
f-
'
Cx)
= fGth7h-f# tO Ch)
- ff (x)
→
f
'G) = dfCx) to Ch )- I fKH
- df Cx)
/ f M h
In a similar way, we can write: ! % − ℎ = ! % − !! % ℎ + +(ℎ") → !! % = ! % − ! % − ℎ ℎ + +(ℎ) And define the Backward Finite Difference as: .! % = ! % − ! % − ℎ ℎ → !! % = .! % + +(ℎ) And subtracting the two Taylor approximations ! % + ℎ = ! % + !! % ℎ + !′′ %
#! " +!′′′ % #" $ + ⋯! % − ℎ = ! % − !! % ℎ + !′′ %
#! " −!′′′ % #" $ + ⋯! % + ℎ − ! % − ℎ = 2!! % ℎ + !′′′ % ℎ% 6 + +(ℎ&) !! % = ! % + ℎ − ! % − ℎ 2ℎ + +(ℎ") And define the Central Finite Difference as: .! % = % + ℎ − ! % − ℎ 2ℎ → !! % = .! % + +(ℎ")
#
EEO
§=
=
÷ h
Forward Finite Difference: .! % =
' ()# *' ( #→ !! % = .! % + +(ℎ) Backward Finite Difference: .! % =
' ( *' (*# #→ !! % = .! % + +(ℎ) Central Finite Difference: .! % = ' ()# *' (*#
"#→ !! % = .! % + +(ℎ") How accurate is the finite difference approximation? How many function evaluations (in additional to ! % )? Our typical trade-off issue! We can get better accuracy with Central Finite Difference with the (possible) increased computational cost.
How small should the value of !?
Truncation error: +(ℎ) Cost: 1 function evaluation Truncation error: +(ℎ) Cost: 1 function evaluation Truncation error: +(ℎ") Cost: 2 function evaluation2
HAI
I
Example
! # = -$ − 2 !′ # = -$ /!01123# = (-$%!−2) − (-$−2) ℎ
- 2232(ℎ) = 045(!′ # − /!01123#)
We want to obtain an approximation for !′ 1
ℎ 34454
Truncation error
f-(xth) = e' 'the 2
If = f(Xthh)-f#
t
q
= =
=
Example
Should we just keep decreasing the perturbation ℎ, in order to approach the limit ℎ → 0 and
- btain a better approximation for the derivative?
Uh-Oh!
What happened here? ! # = -$ − 2, !′ # = -$ → !′ 1 ≈ 2.7
.! 1 = ! 1 + ℎ − !(1) ℎ
Forward Finite Difference
- cancelation !
.!(%) = ! % + ℎ − !(%) ℎ ≤ 8+ |! % | ℎ
When computing the finite difference approximation, we have two competing source of errors: Truncation errors and Rounding errors
- och)
→
?
I
Eml H
F -
O
Optimal “h” Loss of accuracy due to rounding
- 2232~> ℎ
Truncation error: Rounding error:
- 2232~ ?&|! # |
ℎ
Minimize the total error 34454 ~ 8+|! % | ℎ + ;ℎ Gives ℎ = 8+|! % |/;
/
e:
I
→ to
'
Finite Difference Method
- Review :
f2 →Ee
df
= fCxth)-S←
→ f)Cx)E
h
%
- f
FCK)
- ft
Iz
, Is ,- ' In )
=
=
=giant
'
÷÷÷I
- ⇐
t.it?tSCxth#-f
E -
- µ
:o) Ei
?)
h
⇐
⇐i
:*
f- (x, , Xz)
= 2X, txixz the*
is"""
⇐t.ie/Hx-tngy#=y--f7sI%fCkthIz)-fCx
)
- h
f : Bing - pin
÷÷i÷÷÷÷÷÷÷÷÷÷
:
÷÷÷¥⇐÷÷,
:*
.