9th Numerical Differentiation - Part I
9th Numerical Differentiation - Part I
9th Numerical Differentiation - Part I
f (x0 + h) − f (x0 )
f 0 (x0 ) = lim
h→0 h
Using this formula for ”small enough” h values, the formula
f (x0 + h) − f (x0 )
f 0 (x0 ) ≈
h
is simply an approximation to the numerical derivative of f (x) at x = x0 .
Similarly, derivative at a point x = x0 can be defined by approaching from
either the right or left. Also, the derivative from the left can be given by
f (x0 ) − f (x0 − h)
f 0 (x0 ) = lim
h→0 h
In this case, an approximation to the derivative of f (x) at x = x0 is
f (x0 ) − f (x0 − h)
f 0 (x0 ) ≈
h
f 00 (c)
The error in this approximation is h2 , for some c ∈ [x0 , x0 + h].
2!
Substituting this error back in the approximation, we get an exact
equation instead:
f 00 (c)
f (x0 + h) = f (x0 ) + hf 0 (x0 ) + h2 .
2!
0
Solving this equation for f (x0 ) gives
f (x0 + h) − f (x0 ) f 00 (c)
f 0 (x0 ) = +h .
h 2!
Definition (Forward Difference Formula)
f (x0 + h) − f (x0 )
f 0 (x0 ) ≈ is an approximation to the derivative with
00
h
f (c)
an error h .
2!
f 00 (c) M
Error = h ≤h .
2 2
Remark
If we know the maximum value of the second derivative of the function
on the interval [x0 , x0 + h], we can control the error by scaling h values.
Then, f 000 (c) ≤ M , for all c ∈ [x0 − h, x0 + h], and hence, the error due
to central difference formula has an upper bound:
f 000 (c) M
Error = h2 ≤ h2 .
3! 3!
Remark
If we know the maximum value of the third derivative of the function on
the interval [x0 − h, x0 + h], we can control the error by scaling h values.
Remark
The error due to the forward/backward difference formula is given by
some constant times a small number h, while it is some other constant
times h2 for the central difference formula. Neglecting the constants, and
comparing the numbers h and h2 , we observe that h2 < h for
0 < h << 1, and hence, the error due to the central difference is much
less than the error caused by the forward/backward difference.
Technically, the error due to the forward/backward difference formula is
said to be O(h) (first order of accuracy), while it is O(h2 ) (second order
of accuracy) with the central difference3 .
3
The forward and backward difference formulas are O(h) accurate. It means
that when the value of h is halved, the error will reduce by half, as well. Also,
since the central difference formula is O(h2 ) accurate, cutting the value of h to
its half will reduce the error to its quarter.
Dr. Mustafa Ağgül Hacettepe University
Taylor’s Theorem and Numerical Derivative
MAT307 Numerical Analysis Forward and Backward Difference Formula
Central Difference Formula
Example
Find the forward, backward and central difference approximations of the
derivative of f (x) = x3 , at x0 = 1. Take h = 0.1 and h = 0.05, and
compute absolute errors and upper bound of the error for each.
For h = 0.1:
f (1 + h) − f (1) f (1.1) − f (1)
Forward Dif. f 0 (1) ≈ =
h 0.1
1.331 − 1
= = 3.31
0.1
f (1) − f (1 − h) f (1) − f (0.9)
Backward Dif. f 0 (1) ≈ =
h 0.1
1 − 0.729
= = 2.71
0.1
f (1 + h) − f (1 − h) f (1.1) − f (0.9)
Central Dif. f 0 (1) ≈ =
2h 0.2
1.331 − 0.7291
= = 3.01
0.2
Example
Find the forward, backward and central difference approximations of the
derivative of f (x) = x3 , at x0 = 1. Take h = 0.1 and h = 0.05, and
compute absolute errors and upper bound of the error for each.
For h = 0.05:
f (1 + h) − f (1) f (1.05) − f (1)
Forward Dif. f 0 (1) ≈ =
h 0.05
1.157625 − 1
= = 3.1525
0.05
f (1) − f (1 − h) f (1) − f (0.95)
Backward Dif. f 0 (1) ≈ =
h 0.05
1 − 0.857375
= = 2.8525
0.05
f (1 + h) − f (1 − h) f (1.05) − f (0.95)
Central Dif. f 0 (1) ≈ =
2h 0.1
1.157625 − 0.857375
= = 3.0025
0.1
Example
The exact value of the derivative at x0 = 1 is needed for the accuracy
analysis:
f 00 (x) = 3x2 ⇒ f 0 (1) = 3.
Example
For the upper bounds of errors, we need the second and third derivatives
of f (x) = x3 :
f 00 (x) = 6x and f 000 (x) = 6.
Remark
As can be seen from the tables, the reduction of the h value by half cuts
the errors caused by the forward and backward difference formulas by
half. On the other hand, the central difference formula reduced its error
to 1/4 when the h value reduced to its half. These computation results
numerically verify our theoretical findings.