Numerical Differentiation

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 8

Topic: Numerical Differentiation

Learning Outcomes:
At the end of the topic, the students have:
1. derived the formulas of the three methods of differentiation,
namely; backward difference, forward difference and centered
difference.
2. calculated the approximate derivative of a given function.
3. Determined the improved derivative of a given function.

Concept:
The first derivative of a function at a given point is also the
tangent or slope of the function at that specified point. There are some
engineering functions whose derivative cannot be determined by the
exact differentiation formulas or by canned software.

The derivative of a function can be estimated by three methods


numerically, namely;

1. Forward Difference Approximation


2. Backward Difference Approximation
3. Centered Difference Approximation

The complete term is Forward-Finite-Divided- Difference


Approximation. The other methods follow the same.

The first Derivative Formulas:


1. Forward Differentiation
Forward differentiation requires a point xi+1 forward of a
specified point, xi with interval, h called as step size to estimate
the derivative of a function (see figure below). The approximate
slope is the line connecting the points in the curve f(xi) and
f(xi+1).

True Slope

Approximate Slope
f(xi)
f(xi+1)
f(x)
h
(step size)

0 xi xi+1

'
f ( x i+1 ) −f ( xi )
f (x )=
h

where f ' (x ) is the first derivative of a function.

2. Backward Differentiation
Forward differentiation requires a point xi-1 backward of a
specified point, xi with interval, h called as step size to estimate
the derivative of a function (see figure below). The approximate
slope is the line connecting the points in the curve f(xi-1) and
f(xi).

True Slope
Approximate Slope

f(xi)
f(xi-1)
f(x)
h
(step size)

0 xi-1 xi

'
f ( x i )−f ( x i−1)
f (x )=
h

3. Centered Differentiation
Centered differentiation requires two points forward and
backward of a specified point, xi with intervals, h to estimate
the derivative of a function (see figure below). The approximate
slope is the line connecting the points in the curve f(xi-1) and
f(xi+1).

True Slope

Approximate Slope
f(xi)
f(xi-1) f(xi+1)
f(x)
h h

0 xi-1 xi xi+1

'
f ( x i+1 ) −f ( xi−1 )
f (x )=
2h

Example 1:

Estimate the first derivative of the function given below at x =


0.5 with a step size of 0.2
f(x) = x2 + cos x = 0
where x is in radians. Use the three approximation formulas.

Solution:
h = 0.2
Needed data:
x f(x)
xi-1 0.3 1.045336
xi 0.5 1.127582
xi+1 0.7 1.254842

x i−1=0.5−0.2=0.3
f ( x i−1 )= ( 0.3 )2+ cos( 0.3¿)=1.045336 ¿

1. Forward Differentiation

1.254842−1.127582
f ' ( x )= =0.636298
0.20

2. Backward Differentiation

1.127582−1.045336
f ' ( x )= =0.411230
0.20

3. Centered Differentiation

1.254842−1.045336
f ' ( x )= =0.523764
2(0.20)

Comments:

a. The difference in the answers are large.


b. The exact derivative is 0.520574.
c. The percentage of true error of the answers are 22.25%,
21% and 0.61%, respectively.

exact f ' ( x )−computed f ' (x )


True error = | exact f ' ( x)
∗100 % |
d. Centered differentiation gives a better answer but still
unacceptable.

Ways to Improve the Derivatives:

1. Use a smaller step size.


2. Use High-Accuracy Formulas.
3. Use extrapolation.

The High-Accuracy Differentiation Formulas for the 1st derivatives:


1. Forward Differentiation

'
−f ( x i+ 2) + 4 f ( xi +1 )−3 f ( x i)
f (x )=
2h

2. Backward Differentiation
'
3 f ( x i )−4 f ( x i−1 ) + f (x i−2)
f (x )=
2h

3. Centered Differentiation
'
−f ( x i+ 2) + 8 f ( x i+1 )−8 f ( x i−1) + f (x i−2)
f (x )=
12h

Example 2:

Use the High-Accuracy Differentiation formulas to solve


the same problem in example 1.

Solution:

Needed Data with h=0.2:


x f(x)

xi-2 0.1 1.005004


xi-1 0.3 1.045336
xi 0.5 1.127582
xi+1 0.7 1.254842
xi+2 0.9 1.431610

1. Forward Differentiation
'
−f ( x i+ 2) + 4 f ( xi +1 )−3 f ( x i)
f (x )=
2h

−1.431610+4 (1.254842 ) −3 (1.127582 )


f ' ( x )= =0.512528
2 ( 0.2 )
2. Backward Differentiation
'
3 f ( x i )−4 f ( x i−1 ) + f (x i−2)
f (x )=
2h

3 (1.127582 ) −4 ( 1.045336 )+1.005004


f ' ( x )= =0.516015
2(0.2)

3. Centered Differentiation
'
−f ( x i+ 2) + 8 f ( x i+1 )−8 f ( x i−1) + f (x i−2)
f (x )=
12h

f ' ( x )=−1.431610+8 ¿ ¿

Comments:
a. The answers have small differences.
b. The true errors are 1.54%, 0.88% and 0.005%, respectively.
c. The answers are much better that using the approximate
formulas.
d. Centered differentiation gives the best answer.

The Richardson’s extrapolation.

Extrapolation is used to improve the approximate


derivatives and integrals. It uses the approximate centered
derivatives to arrive at a better result. The formula is

4 1
D= D ( h 2) − D ( h1 )
3 3

where D = improved derivative


h1 and h2 = interval or step size
1
h2 = h1
2
D ( h1 ) = approximate derivative as a function of h1
D ( h2 ) = approximate derivative as a function of h2
Example 3:
Improve the derivative calculated in example 1 using
extrapolation with the approximate centered derivatives.

Solution:

For h1 = 0.2;

D1 = 0.523764

h1
For h2 = = 0.1;
2

Needed data:
x f(x)
xi-1 0.4 1.081061
xi 0.5 1.127582
xi+1 0.6 1.185336

1.185336−1.081061
D 2= =0.521375
2(0.10)

4 1
D= ( 0.521375 )− ( 0.523764 )=0.520579
3 3

True error = 0.00096%

References:

Chapra (2005). Applied Numerical Methods with MATLAB.


Musto, J and Howard, W. (2009). Engineering Computation: An Introduction using
MATLAB & EXCEL.
Chapra and Canale (2002).Numerical Methods for Engineers.

You might also like