0% found this document useful (0 votes)
211 views

Numerical Differentiation of Continuous Functions

This document discusses numerical differentiation of continuous functions. It provides formulas for approximating the first derivative using forward, backward, and central finite difference approximations derived from Taylor series expansions. Examples are included to demonstrate calculating the acceleration of a rocket using the different approximation methods and comparing to the exact derivative. Higher order derivatives can also be approximated using this approach.

Uploaded by

Ethan Losano
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
211 views

Numerical Differentiation of Continuous Functions

This document discusses numerical differentiation of continuous functions. It provides formulas for approximating the first derivative using forward, backward, and central finite difference approximations derived from Taylor series expansions. Examples are included to demonstrate calculating the acceleration of a rocket using the different approximation methods and comparing to the exact derivative. Higher order derivatives can also be approximated using this approach.

Uploaded by

Ethan Losano
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 13

Numerical Differentiation of

Continuous Functions

After reading this module, you should be able to:

1. derive formulas for approximating the first derivative of a function,


2. derive formulas for approximating derivatives from Taylor series,
3. derive finite difference approximations for higher order derivatives, and
4. use the developed formulas in examples to find derivatives of a function.

The derivative of a function at x is defined as


f ( x + ∆x ) − f (x )
f ′( x ) = lim
∆x →0 ∆x
To be able to find a derivative numerically, one could make ∆x finite to give,
f (x + ∆x ) − f ( x )
f ′( x ) ≈ .
∆x
Knowing the value of x at which you want to find the derivative of f ( x ) , we choose a value
of ∆x to find the value of f ′( x ) . To estimate the value of f ′( x ) , three such approximations
are suggested as follows.

Forward Difference Approximation of the First Derivative


From differential calculus, we know
f ( x + ∆x ) − f ( x )
f ′( x ) = lim
∆x →0 ∆x
For a finite ∆x ,
f (x + ∆x ) − f (x )
f ′(x ) ≈
∆x
The above is the forward divided difference approximation of the first derivative. It is called
forward because you are taking a point ahead of x . To find the value of f ′( x ) at x = xi , we
may choose another point ∆x ahead as x = xi +1 . This gives
f ( xi +1 ) − f ( xi )
f ′( xi ) ≈
∆x
f ( xi +1 ) − f ( xi )
=
xi +1 − xi
where
∆x = xi +1 − xi

f (x)

x x + ∆x x

Figure 1 Graphical representation of forward difference approximation of first derivative.

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

(b) The exact value of a(16 ) can be calculated by differentiating


 14 × 10 4 
ν (t ) = 2000 ln  4  − 9.8t
14 × 10 − 2100t 
as
d
a(t ) = [ν(t )]
dt
Knowing that
d
[ln(t )] = 1 and d 1 = − 12
dt t dt  t  t
 14 × 10 4 − 2100t  d  14 × 10 4 
a (t ) = 2000 4

 
 4
 − 9.8
 14 × 10  dt  14 × 10 − 2100t 
 14 × 10 4 − 2100t   14 × 10 4 
= 2000 4

 (− 1)
 (14 × 10 4 − 2100t ) 
2
(− 2100) − 9.8
 14 × 10   
− 4040 − 29.4t
=
− 200 + 3t
− 4040 − 29.4(16 )
a(16 ) =
− 200 + 3(16 )
= 29.674 m/s 2
(c) The absolute relative true error is
True Value − Approximate Value
∈t = × 100
True Value
29.674 − 30.474
= × 100
29.674
= 2.6967%

Backward Difference Approximation of the First Derivative


We know
f ( x + ∆x ) − f (x )
f ′( x ) = lim
∆x →0 ∆x
For a finite ∆x ,
f ( x + ∆x ) − f (x )
f ′(x ) ≈
∆x
If ∆x is chosen as a negative number,
f ( x + ∆x ) − f (x )
f ′(x ) ≈
∆x
f ( x ) − f ( x − Δx )
=
Δx
This is a backward difference approximation as you are taking a point backward from x . To
find the value of f ′( x ) at x = xi , we may choose another point ∆x behind as x = xi −1 . This
gives
f (xi ) − f ( xi −1 )
f ′(xi ) ≈
∆x
f (xi ) − f ( xi −1 )
=
xi − xi −1
where
Δx = xi − xi −1
Continuous Differentiation

f (x)

x − ∆x x x

Figure 2 Graphical representation of backward difference approximation of first derivative.

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%

Forward Difference Approximation from Taylor Series


Taylor’s theorem says that if you know the value of a function f (x) at a point xi and all its
derivatives at that point, provided the derivatives are continuous between xi and xi +1 , then
f ′′(xi )
f (xi +1 ) = f (xi ) + f ′(xi )(xi +1 − xi ) + (xi +1 − xi )2 + 
2!
Substituting for convenience Δx = xi +1 − xi
f ′′( xi )
f ( xi +1 ) = f (xi ) + f ′(xi )Δx + (Δx )2 + 
2!
f ( xi +1 ) − f ( xi ) f ( xi )
′′
f ′( xi ) = − (∆x ) + 
∆x 2!
f ( xi +1 ) − f ( xi )
f ′( xi ) = + O(∆x )
∆x
The O(∆x ) term shows that the error in the approximation is of the order of ∆x .
Can you now derive from the Taylor series the formula for the backward divided difference
approximation of the first derivative?
As you can see, both forward and backward divided difference approximations of the
first derivative are accurate on the order of O(∆x ) . Can we get better approximations? Yes,
another method to approximate the first derivative is called the central difference
approximation of the first derivative.
From the Taylor series
f ′′( xi ) ′′′( )
f ( xi +1 ) = f ( xi ) + f ′( xi )Δx + (Δx )2 + f xi (Δx )3 +  (1)
2! 3!
and
f ′′( xi ) ′′′( )
f ( xi −1 ) = f ( xi ) − f ′( xi )Δx + (Δx )2 − f xi (Δx )3 +  (2)
2! 3!
Subtracting Equation (2) from Equation (1)
Continuous Differentiation

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

Figure 3 Graphical representation of central difference approximation of first derivative.

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.

Table 1 Summary of a(16 ) using different difference approximations


Type of difference a(16 )
∈t %
approximation (
m/s 2 )
Forward 30.475 2.6967
Backward 28.915 2.5584
Central 29.695 0.069157

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.

Finite Difference Approximation of Higher Derivatives


One can also use the Taylor series to approximate a higher order derivative. For example, to
approximate f ′′( x ) , the Taylor series is
f ′′(xi ) ′′′( )
f ( xi + 2 ) = f ( xi ) + f ′(xi )(2Δx ) + (2Δx )2 + f xi (2Δx )3 +  (3)
2! 3!
where
xi + 2 = xi + 2Δx
f ′′(xi ) ′′′( )
f ( xi +1 ) = f ( xi ) + f ′( xi )(∆x ) + (∆x )2 + f xi (∆x )3  (4)
2! 3!
where
xi −1 = xi − Δx
Subtracting 2 times Equation (4) from Equation (3) gives
f ( xi + 2 ) − 2 f ( xi +1 ) = − f ( xi ) + f ′′( xi )(Δx ) + f ′′′( xi )(Δx ) 
2 3
f ( xi + 2 ) − 2 f ( xi +1 ) + f ( xi )
f ′′( xi ) = − f ′′′(xi )(Δx ) + 
(Δx )2
f ( xi + 2 ) − 2 f (xi +1 ) + f (xi )
f ′′( xi ) ≈ + O(∆x ) (5)
(∆x )2
Example 4
The velocity of a rocket is given by
 14 × 10 4 
ν (t ) = 2000 ln  4  − 9.8t , 0 ≤ t ≤ 30
14 × 10 − 2100t 
Use the forward 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
ν (ti + 2 ) − 2ν (ti +1 ) + ν (ti )
j (ti ) ≈
(∆t )2
ti = 16
∆t = 2
ti +1 = ti + ∆t
= 16 + 2
= 18
ti + 2 = ti + 2(∆t )
= 16 + 2(2 )
= 20
ν (20) − 2ν (18) + ν (16)
j (16 ) ≈
(2)2

14 × 10 4 
ν (20) = 2000 ln   − 9.8(20)
14 × 10 − 2100(20)
4

= 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

517.35 − 2(453.02 ) + 392.07


j (16 ) ≈
4
= 0.84515 m/s 3
Continuous Differentiation

The exact value of j (16) can be calculated by differentiating


 14 × 10 4 
ν (t ) = 2000 ln  4  − 9.8t
 14 × 10 − 2100t 
twice as
d
a(t ) = [ν(t )] and
dt
d
j (t ) = [a(t )]
dt
Knowing that
d
[ln(t )] = 1 and
dt t
d 1 1
  =− 2
dt  t  t
 14 × 10 4 − 2100t  d  14 × 10 4 
a (t ) = 2000 4
  4
 − 9.8
 14 × 10  dt  14 × 10 − 2100t 
 14 × 10 4 − 2100t   14 × 10 4 
= 2000  (− 1) (− 2100) − 9.8
 (14 × 10 − 2100t ) 
14 × 10 4   4 2 
 
− 4040 − 29.4t
=
− 200 + 3t
Similarly it can be shown that
d
j (t ) = [a(t )]
dt
18000
=
(−200 + 3t ) 2
18000
j (16 ) =
[−200 + 3(16)]2
= 0.77909 m/s 3
The absolute relative true error is
0.77909 − 0.84515
∈t = × 100
0.77909
= 8.4797%

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

f ( xi +1 ) + f ( xi −1 ) = 2 f ( xi ) + f ′′(xi )(∆x ) + f ′′′(xi )


2 (∆x )4 + ...
12
f (xi +1 ) − 2 f (xi ) + f (xi −1 ) f ′′′′( xi )(∆x )
2
f ′′( xi ) = − + ...
(∆x )2 12
f ( xi +1 ) − 2 f ( xi ) + f ( xi −1 )
+ O(∆x )
2
=
(∆x ) 2

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

ν (18) − 2ν (16) + ν (14)


j (16 ) ≈
(2)2
Continuous Differentiation

 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%

You might also like