Numerical Differentiation of Continuous Functions
Numerical Differentiation of Continuous Functions
Continuous Functions
f (x)
x x + ∆x x
Example 1
The velocity of a rocket is given by
14 × 104
ν (t ) = 2000 ln 4 − 9.8t , 0 ≤ t ≤ 30
14 × 10 − 2100t
where ν is given in m/s and t is given in seconds. At t = 16 s ,
a) use the forward difference approximation of the first derivative of ν(t ) to calculate the
acceleration. Use a step size of ∆t = 2 s .
b) find the exact value of the acceleration of the rocket.
c) calculate the absolute relative true error for part (b).
Solution
ν (ti +1 ) −ν (ti )
(a) a(ti ) ≈
∆t
ti = 16
Δt = 2
t i +1 = t i + Δt
= 16 + 2
=18
Continuous Differentiation
ν (18) −ν (16)
a(16 ) ≈
2
14 × 10 4
ν (18) = 2000 ln − 9.8(18)
14 × 10 − 2100(18)
4
= 453.02 m/s
14 × 104
ν (16) = 2000 ln − 9.8(16 )
14 × 10 − 2100(16 )
4
= 392.07 m/s
Hence
ν (18) − ν (16)
a(16) ≈
2
453.02 − 392.07
=
2
= 30.474 m/s 2
f (x)
x − ∆x x x
Example 2
The velocity of a rocket is given by
14 × 10 4
ν (t ) = 2000 ln 4 − 9.8t , 0 ≤ t ≤ 30
14 × 10 − 2100t
(a) Use the backward difference approximation of the first derivative of ν(t ) to calculate the
acceleration at t = 16 s . Use a step size of ∆t = 2 s .
(b) Find the absolute relative true error for part (a).
Solution
ν (ti ) − ν (ti −1 )
a(t ) ≈
∆t
ti = 16
Δt = 2
t i −1 = t i − Δt
= 16 − 2
= 14
ν (16) − ν (14)
a(16 ) ≈
2
14 × 10 4
ν (16) = 2000 ln − 9.8(16)
14 × 10 4
− 2100(16 )
= 392.07 m/s
14 × 10 4
ν (14 ) = 2000 ln − 9.8(14 )
14 × 10 − 2100(14 )
4
= 334.24 m/s
ν (16) − ν (14)
a(16 ) ≈
2
392.07 − 334.24
=
2
= 28.915 m/s 2
(b) The exact value of the acceleration at t = 16 s from Example 1 is
a(16 ) = 29.674 m/s 2
The absolute relative true error for the answer in part (a) is
29.674 − 28.915
∈t = × 100
29.674
= 2.5584%
2 f ′′′( xi )
f ( xi +1 ) − f ( xi −1 ) = f ′(xi )(2Δx ) + (Δx )3 +
3!
f ( xi +1 ) − f ( xi −1 ) f ′′′( xi )
f ′( xi ) = − (∆x )2 +
2∆x 3!
f ( xi +1 ) − f ( xi −1 )
+ O(∆x )
2
=
2∆x
hence showing that we have obtained a more accurate formula as the error is of the order of
O(∆x ) .
2
f (x)
x − ∆x x x + ∆x x
Example 3
The velocity of a rocket is given by
14 × 10 4
ν (t ) = 2000 ln 4 − 9.8t , 0 ≤ t ≤ 30 .
14 × 10 − 2100t
(a) Use the central difference approximation of the first derivative of ν (t ) to calculate the
acceleration at t = 16 s . Use a step size of ∆t = 2 s .
(b) Find the absolute relative true error for part (a).
Solution
ν (ti +1 ) −ν (ti −1 )
a(ti ) ≈
2∆t
ti = 16
∆t = 2
ti +1 = ti + ∆t
= 16 + 2
= 18
ti −1 = ti − ∆t
= 16 − 2
= 14
ν (18) − ν (14)
a(16 ) ≈
2(2 )
ν(18) − ν(14 )
=
4
14 × 10 4
ν (18) = 2000 ln − 9.8(18)
14 × 10 − 2100(18)
4
= 453.02 m/s
14 × 10 4
ν (14 ) = 2000 ln − 9.8(14 )
14 × 10 − 2100(14 )
4
= 334.24 m/s
ν (18) − ν (14)
a(16 ) ≈
4
453.02 − 334.24
=
4
= 29.694 m/s2
(b) The exact value of the acceleration at t = 16 s from Example 1 is
a(16 ) = 29.674 m/s 2
The absolute relative true error for the answer in part (a) is
29.674 − 29.694
∈t = × 100
29.674
= 0.069157%
The results from the three difference approximations are given in Table 1.
Clearly, the central difference scheme is giving more accurate results because the
order of accuracy is proportional to the square of the step size. In real life, one would not
Continuous Differentiation
know the exact value of the derivative – so how would one know how accurately they have
found the value of the derivative? A simple way would be to start with a step size and keep
on halving the step size until the absolute relative approximate error is within a pre-specified
tolerance.
Take the example of finding v ′(t ) for
14 × 10 4
ν (t ) = 2000 ln 4 − 9.8t
14 × 10 − 2100t
at t = 16 using the backward difference scheme. Given in Table 2 are the values obtained
using the backward difference approximation method and the corresponding absolute relative
approximate errors.
Table 2 First derivative approximations and relative errors for different ∆t values of
backward difference scheme.
∆t v ′(t ) ∈a %
2 28.915
1 29.289 1.2792
0.5 29.480 0.64787
0.25 29.577 0.32604
0.125 29.625 0.16355
From the above table, one can see that the absolute relative approximate error
decreases as the step size is reduced. At ∆t = 0.125 , the absolute relative approximate error
is 0.16355%, meaning that at least 2 significant digits are correct in the answer.
= 517.35 m/s
14 × 10 4
ν (18) = 2000 ln − 9.8(18)
14 × 10 − 2100(18)
4
= 453.02 m/s
14 × 10 4
ν (16) = 2000 ln − 9.8(16)
14 × 10 − 2100(16)
4
= 392.07 m/s
The formula given by Equation (5) is a forward difference approximation of the second
derivative and has an error of the order of O(∆x ) . Can we get a formula that has a better
accuracy? Yes, we can derive the central difference approximation of the second derivative.
The Taylor series is
f ′′( xi )
(∆x )2 + f (xi ) (∆x )3 + f (xi ) (∆x )4 + ...
′′′ ′′′′
f (xi +1 ) = f (xi ) + f ′(xi )∆x + (6)
2! 3! 4!
where
xi +1 = xi + Δx
f ′′(xi )
(∆x )2 − f (xi ) (∆x )3 + f (xi ) (∆x )4 −
′′′ ′′′′
f ( xi −1 ) = f (xi ) − f ′(xi )∆x + (7)
2! 3! 4!
where
xi −1 = xi − Δx
Adding Equations (6) and (7), gives
Example 5
The velocity of a rocket is given by
14 × 10 4
ν (t ) = 2000 ln 4 − 9.8t , 0 ≤ t ≤ 30 ,
14 × 10 − 2100t
(a) Use the central difference approximation of the second derivative of ν(t ) to calculate the
jerk at t = 16 s . Use a step size of ∆t = 2 s .
Solution
The second derivative of velocity with respect to time is called jerk. The second order
approximation of jerk then is
ν (t ) − 2ν (ti ) + ν (ti −1 )
j (ti ) ≈ i +1
(∆t )2
ti = 16
∆t = 2
ti +1 = ti + ∆t
= 16 + 2
= 18
ti + 2 = ti − ∆t
= 16 − 2
= 14
14 × 10 4
ν (18) = 2000 ln − 9.8(18)
14 × 10 − 2100(18)
4
= 453.02 m/s
14 × 10 4
ν (16) = 2000 ln − 9.8(16)
14 × 10 − 2100(16)
4
= 392.07 m/s
14 × 10 4
ν (14 ) = 2000 ln − 9.8(14 )
14 × 10 − 2100(14 )
4
= 334.24 m/s
ν (18) − 2ν (16) + ν (14)
j (16 ) ≈
(2)2
453.02 − 2(392.07 ) + 334.24
=
4
3
= 0.77969 m/s
The absolute relative true error is
0.77908 − 0.77969
∈t = × 100
0.77908
= 0.077992%