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

BCHE201L: Computational Methods in Chemical Engineering

Dr. Shishir Kumar Behera


School of Chemical Engineering (SCHEME)
VIT Vellore
Module – 5: Integration and Differentiation
Integration (Newton cotes)

• Trapezoidal method
• Simpson’s method

Differentiation
• Forward difference
• Central difference
• Backward difference

Dr. S K Behera BCHE201L CMCE 2


Numerical Differentiation
o In general, engineers continuously deal with systems and processes that
change i.e. change of the dependent variable with respect to independent
variable.

o The function to be differentiated or integrated will typically be in one


of the following three forms:

i. A simple continuous function such as polynomial, an exponential, or


a trigonometric function

ii. A complicated continuous function that is difficult or impossible to


differentiate or integrate directly

iii. A tabulated function where values of x and y=f(x) are given at a


number of discrete points, such as those with experimental or
field data

Dr. S K Behera BCHE201L CMCE 3


• In the first case, the derivative of a simple function may be evaluated

analytically using calculus.

• For the second case, analytical solutions are often impractical, and

sometimes impossible to obtain. In these instances, as well as in the

third case of discrete data, approximate methods must be employed.

Dr. S K Behera BCHE201L CMCE 4


A non-computer method for determining derivatives from data is called
equal-area graphical differentiation.

Dr. S K Behera BCHE201L CMCE 5


Numerical Differentiation
• When a function y = f(x) is unknown but its values are given at some
points like (x0 , y0), (x1, y1), .......... (xn, yn) or in the form of a table, then
we can differentiate using numerical differentiation.
• Sometimes it is difficult to differentiate a composite or complicated
function which can be done easily in less time and less number of steps
by numerical differentiation.

Dr. S K Behera BCHE201L CMCE 6


Solving the numerical differentiation problem

• Numerical differentiation is the process of evaluating derivative of the interpolating


polynomial at some particular value of the variate.
• The choice of the interpolating formula for derivative employing differences are the
same as in the case of interpolation.
• For equidistant value of the independent variable, generally we employ Newton's
Forward Difference formula for finding the value of the derivative at the beginning
and Newton Backward Difference formula for finding the value of the derivative at
the end of the interval.
• When the value of the derivative is desired in the middle of the table, Stirling’s
formula of central differences are employed.
• In case of unequidistant value of independent variables, Lagrange’s interpolation
techniques are preferably employed for finding the derivative of a function.
Dr. S K Behera BCHE201L CMCE 7
Example 1:
Obtain dy/dx and d2y/dx2 for x = 4 from the following table:
x 0 10 20 30 40
y 7 18 32 51 87

Solution:

Here x0 = 0, x1 = 10, x2 = 20, x3 = 30, x4 = 40


Example: 2
Obtain dy/dx and d2y/dx2 for x = 12 from the following table:
x 0 10 20 30 40
y 7 18 32 51 87

Solution:

Here x0 = 0, x1 = 10, x2 = 20, x3 = 30, x4 = 40


Dr. S K Behera BCHE201L CMCE 16
Example 3:
Obtain dy/dx and d2y/dx2 for x = 1.1 and 1.6 from the following table:

x 1 1.1 1.2 1.3 1.4 1.5 1.6


y 7.989 8.403 8.781 9.129 9.451 9.750 10.031

Solution:

As the value of y(x) is required at the ends, we have to follow forward


difference formula for derivative at x = 1.1 and backward difference
formula for derivative at x = 1.6.
The difference table is:
Example 4:
A slider in a machine moves along a fixed straight rod. Its distance x cm
along the rod is given below for various values of the time t seconds.
Find the velocity and acceleration of the slider when t = 0.3 seconds.
t 0 0.1 0.2 0.3 0.4 0.5 0.6
x 30.13 31.62 32.87 33.64 33.95 33.81 33.24

Solution:
As the derivatives are required near the middle of variate range, we
use Stirling’s formula.
Hence, the velocity is 5.34 cm/s and acceleration is –45.6 cm/s2.
Practice Problem 1:
Obtain dy/dx and d2y/dx2 for x = 1.2 from the following table:

Solution:

dy/dx = 3.3205 and


d2x/dy2 =3.318
Practice Problem 2:
Obtain dy/dx and d2y/dx2 at x = 2.2 and dy/dx at x = 2 from the following table:

Solution:
xn = 2.2, yn = 9.0250 and h = 0.2 Use the difference Table in PP-1

dy/dx = 9.0228 and d2x/dy2 =8.992 (at x = 2.2) dy/dx = 7.3896 (at x = 2.0)
Forward difference
Forward difference

df f (x  h)  f (x)
 lim
dx h0 h
Taylor’s Theorem
2

f x  h   f x  hf  x  f x 
h 
2
3 4
h
f  x  
h f  x ............
3! 4!
f x  h   f x 
 f  x  O(h) Forward difference
h approximation of first

f x  h  f x 
derivative
f  x    O(h)
h
Dr. S K Behera BCHE201L CMCE 27
Backward difference
Backward difference

df f (x)  f (x  h)
 lim
dx h0 h
Taylor’s Theorem
2

f x  h   f x  hf  x   f x 
h 
2
3 4
h
f  x  
h f  x ............
3! 4!
f x   f x  h 
 f  x  O(h) Backward difference
h approximation of first

f x   f x  h 
derivative
f  x    O(h)
h
Dr. S K Behera BCHE201L CMCE 28
Centered difference
Centered difference

df f (x  h)  f (x)
 lim
dx h0 h
Taylor’s Theorem 2

f x  h   f x  hf  x  f x 
h 
2
3 4
h
f  x   
h f  x ............ (1)
3! 4!
2 3 4

f x - h  f x - hf  x  f x - f  x  f  x -............ (2)
h  h h
2 3! 4!
Eq. (1) – Eq. (2):

f x  h  f x  h 
f  x    O(h2 )
2h
Dr. S K Behera BCHE201L CMCE 29
High accuracy differentiation formulas
High-accuracy finite-difference formulas can be generated by including additional
terms from the Taylor series expansion.

Example: High-accuracy forward-difference formula for the first derivative:

f ‘xi  2
f xi1   f x i  f x i h  h ..... Terms refers to
2!
f (xi1 )  f (x  h)
Solve for f’(x) f (xi1 )  f (x  h)
f xi1  f xi  f “xi 
f xi 
h

2!
h O h2 
f xi2  2 f xi1  f xi 
f “xi    Oh 
Substitute the
forward-difference
h2
approx. of f”(x)

 f xi2  4 f xi1 3 f xi  High-accuracy


f xi  Oh 2  forward-difference
2h formula

Dr. S K Behera BCHE201L CMCE 30


Forward finite divided-difference formula
Improved versions of the forward difference
for the approximations of the higher
1.
derivatives can be developed and are listed
here:
2.
1 Normal forward-divided difference formula
2 High accuracy forward-divided difference
1. formula (including more terms)

2.

1.

2.

1.

2.

The latter version incorporates more terms of the Taylor series expansion and is more accurate.
Backward finite divided-difference formula
Improved versions can be developed for the
1. backward formulas as well as for the
approximations of the higher derivatives:
2. 1 Normal backward-divided difference formula
2 High accuracy backward-divided difference
formula (including more terms)
1.

2.

1.

2.

1.

2.

Dr. S K Behera BCHE201L CMCE 32


Centered finite divided-difference formula
Improved versions can be developed for the
centered formulas as well as for the
1.
approximations of the higher derivatives:
2. 1 Normal centered-divided difference formula
2 High accuracy centered-divided difference
formula (including more terms)
1.

2.

1.

2.

1.

2.

Dr. S K Behera BCHE201L CMCE 33


o Both forward and Backward differentiations have error which is
proportional to the order of 'h'. i.e. error decreases linearly with the
decrease of h.
o Centered differentiation has an error which is proportional to the
order of h2 i.e. the error decreases quadratically with the decrease of
'h'.

o The notation O(h) and O(h2) respectively means that the error is of
order 'h' and h2.

Dr. S K Behera BCHE201L CMCE 34


Example
f ( x )  0.1x 4  0.15 x 3  0.5 x 2  0.25 x  1.2

Find f’(x) at x = 0.5 with h = 0.5 and 0.25 (exact sol. = - 0.9125)

Solution:
f x  h  f x 
f  x   h  O(h)

Forward difference

h  0.5, f (0.5)  f (1)  f (0.5)  0.2  0.925  1.45,  t  58.9%


 1 0.5 0.5


 f (0.75)  f (0.5) 0.63632813  0.925
h  0.25, f (0.5)    1.155,  t  26.5%
 0.75  0.5 0.25

Dr. S K Behera BCHE201L CMCE 35


f x   f x  h 
Backward difference f  x    O(h)
h
h  0.5, f (0.5)  f (0.5)  f (0)  0.925 1.2  0.55,  t  39.7%
 0.5  0 0.5


 f (0.5)  f (0.25) 0.925 1.10351563
h  0.25, f (0.5)    0.714,  t  21.7%
 0.5  0.25 0.25

Centered difference
h  0.5, f (0.5)  f (1)  f (0)  0.2 1.2  1.0,f  x  f x  h  f x  h   O(h2 )
 
 1 0 1 2h
 t  9.6%


h  0.25, f (0.5)  f (0.75)  f (0.25)  0.63632813  1.10351563  -0.934,   2.4%
 0.75  0.25 0.5
t

Basic formulas h = 0.25 Forward O(h) Backward O(h) Centered O(h2)

True Value Estimate -1.155 -0.714 -0.934


-0.9125 |t| 26.5% 21.7% 2.4%

Dr. S K Behera BCHE201L CMCE 36


Example
f ( x )  0.1x 4  0.15 x 3  0.5 x 2  0.25 x  1.2
Find f’(x) at x = 0.5 with h = 0.25 (exact sol. = -0.9125) using high-accuracy finite-difference formulas.

Forward divided difference


0.2  4(0.6363281)  3(0.925)
f  0.5    0.8594
2(0.25) x f(x)
Backward divided difference xi-2= 0.0 f(0.0) = 1.2
3(0.925)  4(1.035156) 1.2
f 0.5   0.8781 xi-1= 0.25 f(0.25) = 1.103516
2(0.25)
xi = 0.5 f(0.5) = 0.925
Centered divided difference xi+1 = 0.75 f(0.75) = 0.63633
 0.2  8(0.636328)  8(1.035156)
f 0.5   0.9125 xi+2 = 1.0 f(1.0) = 0.2
12(0.25)

High accuracy h = 0.25 Forward O(h2) Backward O(h2) Centered O(h4)


differentiation Estimate -0.859375 -0.878125 -0.9125
formulas
|t| 5.82% 3.77% 0%

Dr. S K Behera BCHE201L CMCE 37


Example: Estimate the first derivative of f (x) = 0.2 + 25x - 200x 2 + 675x 3 - 900x 4
+ 400x 5 at x = 0.5 using finite divided differences and a step size of h = 0.25; true
value is -0.9125.

Solution: The data needed for this problem are:

The forward difference of accuracy O(h2) is computed as:

Et = (-0.9125+0.859375)×100/-0.9125 = 5.82%
The backward difference of accuracy O(h2) is computed as:

Et = (-0.9125+0.878125)×100/-0.9125 = 3.77%

The centered difference of accuracy O(h4) is computed as:

Et = 0%

You might also like