Lecture 4 Numerical Differentiation
Lecture 4 Numerical Differentiation
𝐺𝑖𝑣𝑒𝑛 𝐹𝑢𝑛𝑐𝑡𝑖𝑜𝑛
Derivative
where:
ℎ = 𝑥𝑖+1 − 𝑥𝑖
𝑅𝑛 = remainder term
First Derivative Approximations
Forward Difference
from Taylor series expansion
(1)
′
𝑓 𝑥𝑖+1 − 𝑓 𝑥𝑖 Δ𝑓𝑖
𝑓 𝑥 ≈ =
𝑥𝑖+1 − 𝑥𝑖 ℎ
Where:
Δ𝑓𝑖 = 𝑓𝑖𝑟𝑠𝑡 𝑓𝑜𝑟𝑤𝑎𝑟𝑑 𝑑𝑖𝑓𝑓𝑒𝑟𝑒𝑛𝑐𝑒
ℎ = 𝑠𝑡𝑒𝑝 𝑠𝑖𝑧𝑒
First Derivative Approximations
Example:
Estimate the first derivative of 𝑓 𝑥 = −0.1𝑥 4 − 0.15𝑥 3 − 0.5𝑥 2 − 0.25𝑥 + 1.2 at 𝑥 = 0.5 using a
step size ℎ = 0.5.
Solution:
𝑥𝑖 = 0.5 𝑓(𝑥𝑖 ) = 0.925
𝑓 𝑥𝑖+1 −𝑓 𝑥𝑖 0.2−0.925
𝑓′ 𝑥 ≈ = = −𝟏. 𝟒𝟓
ℎ 0.5
First Derivative Approximations
Backward Difference
from Taylor series expanded backward
(2)
′
𝑓 𝑥𝑖 − 𝑓 𝑥𝑖−1 𝛻𝑓𝑖
𝑓 𝑥 ≈ =
𝑥𝑖 − 𝑥𝑖−1 ℎ
Where:
𝛻𝑓𝑖 = 𝑓𝑖𝑟𝑠𝑡 𝑏𝑎𝑐𝑘𝑤𝑎𝑟𝑑 𝑑𝑖𝑓𝑓𝑒𝑟𝑒𝑛𝑐𝑒
ℎ = 𝑠𝑡𝑒𝑝 𝑠𝑖𝑧𝑒
First Derivative Approximations
Example:
Estimate the first derivative of 𝑓 𝑥 = −0.1𝑥 4 − 0.15𝑥 3 − 0.5𝑥 2 − 0.25𝑥 + 1.2 at 𝑥 = 0.5 using a
step size ℎ = 0.5.
Solution:
𝑥𝑖 = 0.5 𝑓(𝑥𝑖 ) = 0.925
Centered Difference
Subtracting (2) from (1), we get
′
𝑓 𝑥𝑖+1 − 𝑓 𝑥𝑖−1
𝑓 𝑥 ≈
𝑥𝑖+1 − 𝑥𝑖−1
𝑓 𝑥𝑖+1 − 𝑓 𝑥𝑖−1
𝑓′ 𝑥 ≈
2ℎ
First Derivative Approximations
Example:
Estimate the first derivative of 𝑓 𝑥 = −0.1𝑥 4 − 0.15𝑥 3 − 0.5𝑥 2 − 0.25𝑥 + 1.2 at 𝑥 = 0.5 using a
step size ℎ = 0.5.
Solution:
𝑥𝑖 = 0.5 𝑓(𝑥𝑖 ) = 0.925
𝑥𝑖−1 = 0.5 − ℎ = 0.5 − 0.5 = 0 𝑓(𝑥𝑖−1 ) = 1.2
𝑥𝑖+1 = 0.5 + ℎ = 0.5 + 0.5 = 1 𝑓(𝑥𝑖+1 ) = 0.2
We get
𝑑𝑢 1
where: 𝑢′ = 𝑑𝑥 = ℎ
Based on Newton’s Forward Interpolation Formula
and from
We get
and so on..
Example
We get
and so on..
Example
Based on Stirling’s Interpolation Formula
From
We get
and so on..
Example