Module 9: Numerical Differentiation

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 4

CENGR 3140

Numerical Solutions to CE Problems

MODULE 9: NUMERICAL DIFFERENTIATION

The need for numerical differentiation

 When the function is given as a simple mathematical expression, the derivative


can be determined analytically.
 When analytical differentiation of the expression is difficult or not possible,
numerical differentiation has to be used.

Approaches to numerical differentiation

For a given set of points, two approaches can be used to calculate a numerical
approximation of the derivative at one of the points.

The first approach is to use a finite difference approximation.

Finite difference approximation of a derivative at a point x, is an approximate calculation


based on the value of points in the neighborhood of xi.

The derivative at point xi is


approximated by the slope of the
line that connects the point
before xi with the point after xi.

Note: The accuracy of a finite difference


approximation depends on the 1) accuracy of
the data points, 2) the spacing between the
points, 3) and the specific formula used for the
approximation.

The second approach is to approximate the points with an analytical expression that can
be easily differentiated, and then to calculate the derivative by differentiating the analytical
expression. The approximate analytical expression can be derived by using the curve
fitting.

The points are curve fitted by f(x), and the


derivative at point xi is obtained by analytically
differentiating the approximating function and
evaluating the result at the point xi.

engr.mryjnprz
CENGR 3140
Numerical Solutions to CE Problems

FINITE DIFFERENCE APPROXIMATION OF THE DERIVATIVE


The derivative f’(x) of a function f(x) at the point x = a is defined by:

𝑑𝑓(𝑥) 𝑓(𝑥) − 𝑓(𝑎)


= 𝑓 (𝑎) = 𝑙𝑖𝑚
𝑑𝑥 → 𝑥−𝑎

Graphically speaking:

The derivative is the value of the slope of the


tangent line to the function at x = a.

Derivative is obtained by taking a point x near


x = a and calculating the slope of the line that
connects the two points.

Note: Values of the function at different points in the


neighborhood of the point x = a are used for
estimating the slope.

Forward, backward, and central difference formulas for the first derivative
Note: The derivative at point (xi) is calculated from the values of two points. The derivative is estimated as
the value of the slope of the line that connects the two points.

Forward difference – slope of the line that connects points (xi, f(xi)) and (xi+1, f(xi+1)).

𝑑𝑓 𝑓(𝑥 ) − 𝑓(𝑥 )
=
𝑑𝑥 𝑥 −𝑥

Backward difference – slope of the line that connects points (xi-1, f(xi-1)) and (xi, f(xi)).

𝑑𝑓 𝑓(𝑥 ) − 𝑓(𝑥 )
=
𝑑𝑥 𝑥 −𝑥

Central difference – slope of the line that connects points (xi-1, f(xi-1)) and (xi+1, f(xi+1)).

𝑑𝑓 𝑓(𝑥 ) − 𝑓(𝑥 )
=
𝑑𝑥 𝑥 −𝑥

engr.mryjnprz
CENGR 3140
Numerical Solutions to CE Problems

Sample Problem:

Consider the function f(x) = x3. Calculate its first derivative at point x = 3 numerically with
forward, backward, and central finite difference formulas and using:

a) Points x = 2, x = 3, and x = 4.
b) Points x = 2.75, x = 3, and x = 3.25.

Compare the results with the exact (analytical) derivative.

Solution:

Analytical Differentiation:

f’(x) = 3x2

Value of the derivative at x = 3:

f’(3) = 3 (3)2 = 27

Numerical Differentiation:

a) The points used for numerical differentiation are:


x: 2 3 4
f(x): 8 27 64

Forward finite difference:


𝑑𝑓 𝑓(4) − 𝑓(3) 64 − 27
= = = 37
𝑑𝑥 4−3 1

37 − 27
𝑒𝑟𝑟𝑜𝑟 = ⋅ 100 = 37.04%
27

Backward finite difference:


𝑑𝑓 𝑓(3) − 𝑓(2) 27 − 8
= = = 19
𝑑𝑥 3−2 1

19 − 27
𝑒𝑟𝑟𝑜𝑟 = ⋅ 100 = 29.63%
27

Backward finite difference:


𝑑𝑓 𝑓(4) − 𝑓(2) 64 − 8
= = = 28
𝑑𝑥 4−2 2

28 − 27
𝑒𝑟𝑟𝑜𝑟 = ⋅ 100 = 3.704%
27

engr.mryjnprz
CENGR 3140
Numerical Solutions to CE Problems

b) The points used for numerical differentiation are:


x: 2.75 3 3.25
3
f(x): 2.75 3 3 3.253

Forward finite difference:


𝑑𝑓 𝑓(3.25) − 𝑓(3) 3.25^3 − 27
= = = 29.3125
𝑑𝑥 3.25 − 3 0.25

29.3125 − 27
𝑒𝑟𝑟𝑜𝑟 = ⋅ 100 = 8.565%
27

Backward finite difference:


𝑑𝑓 𝑓(3) − 𝑓(2.75) 27 − 2.75^3
= = = 24.8125
𝑑𝑥 3 − 2.75 0.25

24.8125 − 27
𝑒𝑟𝑟𝑜𝑟 = ⋅ 100 = 8.102%
27

Backward finite difference:


𝑑𝑓 𝑓(3.25) − 𝑓(2.75) 3.25^3 − 2.75^3
= = = 27.0625
𝑑𝑥 3.25 − 2.75 0.5

27.0625 − 27
𝑒𝑟𝑟𝑜𝑟 = ⋅ 100 = 0.2315%
27

Note: Smaller separation between the points gives a significantly more accurate approximation.

engr.mryjnprz

You might also like