Professional Documents
Culture Documents
Engineering CHAPTER 6
Subject: Chemical
Engineering
Mathematics 2 NUMERICAL
DIFFERENTIATION
Author:
Andrew KUMORO
AND
INTEGRATION
Dept. of FOR CHEMICAL
Chemical
Engineering ENGINEERS
Diponegoro
University
2013
Specific Study Objectives
y y xi x y xi
x xi 1 xi
Y =f(x)
f xi x
y
f xi
x
x x + x x
dy y f xi x f xi
dx x x
The derivative of f (x) at x0 is:
Limit f x0 x f ( x0 )
f x0
x 0 x
An approximation to this is:
f x0 x f ( x0 )
f x0 for small
x values of h.
Forward Difference
Formula
The methods of derivation of f (x) at x0
Forward finite divided
are to be difference
made using the followings:
Backward finite divided
difference
Center finite divided
difference
f ' ' xi 2
f xi 1 f xi f ' xi x x .........
2!
f xi 1 f xi
f ' xi O x most
x used
f xi 1 f xi f ' ' xi
f ' xi
x
2
x O x 2
rarely
used
Forward Finite Difference
f xi 1 f xi f i
f ' xi O xi 1 xi O x
xi 1 xi x
f(x)
What is
(xi, yi) derivative at
this point?
x
Forward Finite Difference
f xi 1 f xi f i
f ' xi O xi 1 xi O h
xi 1 xi h
f(x)
(x i+1,y i+1)
x
Forward Finite Difference
f xi 1 f xi f i
f ' xi O xi 1 xi O x
xi 1 xi x
f(x)
How does this (x i+1,y i+1)
i mat e
compare to est
the actual first (xi, yi)
derivative at
xi?
x
Forward Divided Difference
f xi 1 f xi f i
f ' xi O xi 1 xi O x
xi 1 xi x
f(x)
x
Forward Divided Difference
f i
f ' xi O x Error is proportional to
x
the step size
First
first forward divided
forward divided difference
difference formula
O(x2) error is proportional to the square of the step size
f xi f xi 1 f
f ' xi i
x x
c tu al
a
(xi,yi)
e
at
stim
e
(xi-1,yi-1)
x
Centered Difference Approximation of
the
First Derivative
al
actu
(xi+1,yi+1)
(xi,yi)
t im ate
es
(xi-1,yi-1)
x
f(x) f(x)
forward
true derivative
finite divided
difference approx.
x x
f(x) f(x)
backward centered
finite divided finite divided
difference approx. difference approx.
x x
Example
1.Given the following function to determine
the derivative at x = 0.5 by taking x =
0.25.
f(x) = -0.1x4 -00.15x - 0.5x2 - 0.25x +1.2
0.5 31.0
Note:
0.25 0.75
f(0) = 1.2
f(0.25) =1.1035
Compare the actual value
f(0.75) = 0.636
(analytical difference) with
f(1) = 0.2 the forward, backward and
2. Try also findcentered differences.of f(x) =
the derivatives
1/3x3+1/4x2+1 at x = 0.2. Take x = 0.01
Compare the actual value (analytical
difference) with the forward, backward and
centered differences.
Case: interpretation of experimental data
Derivative and Integral Estimates for
Data with Errors
In addition to unequal spacing, the other problem
related to differentiating empirical data is
measurement error
dy /dt
y
1 00 10
50
0 0
0 5 10 15 0 10
t t
250 40
2 00 30
150
dy /dt
20
y
1 00
50 10
0 0
0 5 10 15 0 10
t t
Let f ( x ) ln x and x0 1.8
Find an approximate f 1.8
value for
x f (1.8 x) f (1.8 x) f (1.8)
f (1.8)
0.1 0.58778 0.6418 0.5406720
x
67 539
0.01 0.58778 0.5933 0.5540100
67 268
0.00 0.58778 0.5883 0.5554000
1 67 421
The exact valuef 1.8 0.55 5
of
Assume that a function goes through three
points:
x0 , f x0 , x1 , f x1 and x2 , f x2 .
f ( x) P( x)
P x L0 x f x0 L1 x f x1 L2 x f x2
Lagrange Interpolating
Polynomial
Derivatives of Unequally Spaced Data
( x x1 )( x x2 )
P x f x0
( x0 x1 )( x0 x2 )
( x x0 )( x x2 )
f x1
( x1 x0 )( x1 x2 )
( x x0 )( x x1 )
f x2
( x2 x0 )( x2 x1 )
f ( x ) P ( x )
2 x x1 x2
P x f x0
( x0 x1 )( x0 x2 )
2 x x0 x2
f x1
( x1 x0 )( x1 x2 )
2 x x0 x1
f x2
( x2 x0 )( x2 x1 )
If the points are equally spaced, i.e.,
x1 x0 h and x2 x0 2h
2 x0 ( x0 h) ( x0 2h)
P x0 f x0
x0 ( x0 h) x0 ( x0 2h)
2 x0 x0 ( x0 2h)
f x1
( x0 h) x0 ( x0 h) ( x0 2h)
2 x0 x0 ( x0 h)
f x2
( x0 2h) x0 ( x0 2h) ( x0 h)
3h 2h h
P x0 f x0 f x1 2 f x 2
2h 2
h 2
2h
1
P x0 3 f x0 4 f x1 f x2
2h
Three-point formula:
1
f x0 3 f x0 4 f x0 h f x0 2h
2h
If the points are equally spaced with x0
in the middle:
x1 x0 h and x 2 x0 h
2 x0 ( x0 h) ( x0 h)
P x0 f x0
x0 ( x0 h) ( x0 ( x0 h)
2 x0 x0 ( x0 h)
f x1
( x0 h) x0 ( x0 h) ( x0 h)
2 x0 x0 ( x0 h)
f x2
( x0 h) x0 ( x0 h) ( x0 h)
0 h h
P x0 f x0 2 f x1 2 f x 2
h 2
2h 2h
1
f x0 f x0 h f x0 h
2h
Alternate approach (Error estimate)
f x h f x h 2 h2 3
f x f x f x
h 2 3!
..............
(1)
f x h f x
f x O h
h
f x h f x
f x O h
h
f x h f x Forward
f x
h Difference
Formula
h 2 h2 3
O h f x f x
2 3!
4h 2 2 8h 3 3
f x 2h f x 2hf x f x f x
2 3!
4h 2 2 8h 3 3
f x 2h f x 2hf x f x f x
2 3!
f x 2h f x 2h 2 4h 2 3
f x f x f x
2h 2 3!
................
. (2)
f x h f x h 2 2
h 3
f x f x f x
h 2 3!
..............
(1)
f x 2h f x 2h 2 4h 2 3
f x f x f x
2h 2 3!
................
. (2)
2 Eqn. (1) Eqn. (2)
f x h f x f x 2 h f x
2
h 2h
2 h2 3 6 h3 4
f x f x f x
3! 4!
f x 2 h 4 f x h 3 f x
2h
2 h2 3 6 h3 4
f x f x f x
3! 4!
f x O h2
f x 2h 4 f x h 3 f x
2h
f x O h 2
f x 2h 4 f x h 3 f x
f x
2h
O h2
f x 2h 4 f x h 3 f x
f x
2h
Three-point
Formula
O h2
2 3
2 h 6 h
f 3 x f 4 x
3! 4!
THE SECOND THREE-POINT
FORMULA
Take Taylor series expansion of f(x+h)
about x: 2 3
h 2 h 3
f x h f x hf x f x f x
2 3!
Take Taylor series expansion of f(x-h)
about x: 2 3
h 2 h 3
f x h f x hf x f x f x
2 3!
Subtract one expression from another
2h 3 3 2h 6 6
f x h f x h 2hf x f x f x
3! 6!
2h 3 3 2h 6 6
f x h f x h 2hf x f x f x
3! 6!
f x h f x h h2 3 h5 6
f x f x f x
2h 3! 6!
f x h f x h h 2 3 h5 6
f x f x f x
2h 3! 6!
f x h f x h
f x
2h
O h2
2 5
h h
O h2 f 3 x f 6 x
3! 6!
f x h f x h
f x
2h
Second Three-point
Formula
Summary of Errors
f x h f x Forward
f x
h Difference
Formula
h 2 h2 3
Error O h f x f x
term 2 3!
Summary of Errors continued
First Three-point
Formula f x 2h 4 f x h 3 f x
f x
2h
2 3
2 h 6 h
Error O h2 f 3 x f 4 x
term 3! 4!
Summary of Errors continued
Second Three-point
Formulaf x h f x h
f x
2h
2 5
h h
Error O h2 f 3 x f 6 x
3! 6!
term
Example:
f x xe x
Find the approximate f 2 with h 0.1
value of
x f x
1.9
12.70319
9
2.0
14.77811
2
2.1
Using the Forward Difference
formula:
1
f x0 f x0 h f x0
h
1
f 2
0.1
f 2.1 f 2
1
17.148957 14.778112
0.1
23.708450
Using the 1st Three-point formula:
1
f x0 3 f x0 4 f x0 h f x0 2h
2h
1
f 2 3 f ( 2) 4 f ( 2.1) f ( 2.2)
2 0.1
1
3 14.778112 4 17.148957
0.2
19.855030
22.032310
Using the 2nd Three-point
formula:
1
f x0 f x0 h f x0 h
2h
1
f 2 f ( 2.1) f (1.9)
2 0.1
1
17.148957 12.703199
0.2
22.228790
The exact value f 2 is : 22.167168
of
Comparison of the results with
h = 0.1
The exact f 2 is
value of 22.167168
Formula f 2 Error
Forward 23.70845 1.541282
Difference 0
1st Three- 22.03231 0.134858
point 0
2nd Three- 22.22879 0.061622
point 0
Second-order Derivative
h2 2 h3 3
f x h f x hf x f x f x
2 3!
h2 2 h3 3
f x h f x hf x f x f x
2 3!
Add these two equations.
2h 2 2 2h4 4
f x h f x h 2 f x f x f x
2 4!
2h2 2 2 h4 4
f x h 2 f x f x h f x f x
2 4!
f x h 2 f x f x h 2 h 2
2
f 2
x f 4
x
h 4!
f 2 x
f x h 2 f x f x h
2 h 2
f 4
x
2
h 4!
f x h 2 f x f x h
f 2
x
h2
NUMERICAL INTEGRATION
I f x dx
f(x)
a
a b x
Mathematical Background
d d x
sin x ? e ?
dx dx
d d x
cos x ? a ?
dx dx
d d n
tan x ? x ?
dx dx
d
ln x ?
dx
if u and v are functions of x
d n d
u ? (uv ) ?
dx dx
Mathematical Background
udv ?
u du ?
n
a dx ?
bx
dx
x ?
dx ?
ax
e
Newton-Cotes Integration
Formulas
Riemann Rule
Trapezoidal rule
Simpsons Rules
Rarely used in
Unequal Segments chem eng
Open Integration
NEWTON-COTES INTEGRATION
I f x dx f n x dx
a a
f n x a0 a1 x .... an x n
b b
I f x dx f n x dx
a a
5 5
4 4
3 3
f(x )
f(x )
2 2
1 1
0 0
0 5 10 0 5 10
x x
The approximation of an integral by the area under
- a first order polynomial
- a second order polynomial
5 5
4 4
3 3
f(x )
f(x )
2 2
1 1
0 0
0 5 10 0 5 10
x x
3
f(x )
2
0
0 1 2 3 4 5 6 7 8 9 10
x
f(x ) 3
0
0 1 2 3 4 5 6 7 8 9 10
x
4 4
3 3
f(x )
f(x )
2 2
1 1
0 0
0 1 2 3 4 5 6 7 8 9 10 0 1 2 3 4 5 6 7 8 9 10
x x
Trapezoidal Rule
I f x dx f 1 x dx
a a
f n x a0 a1 x
Trapezoidal Rule
b b
I f x dx f 1 x dx
a a
f n x a0 a1 x
f b f a
f 1 x f a x a
ba
Area= (b-a) f(a) + (b-a) (f(b) f(a))
= (b-a) (f(a)- f(a)+ f(b))
y
(b-a) (f(b) f(a))f(b)
f(x)
x 0 =a x 0 =b x
AREA OF THE
TRAPEZOID
The length of the two parallel sides of the
trapezoid are: f(a) and f(b)
The height is b-a
I f x dx f 1 x dx
a a
b
f b f a
f a x a dx
a
ba
1
Et f ' ' b a
3
12
where a b
x n 1
Area . f x0 2 f xi f xn
2 i 1
where there are n+1 equally spaced base points.
Multiple Application of the Trapezoidal
Rule
x1 x2 xn
f x0 f x1 f x1 f x2 f xn 1 f xn
I h h h
2 2 2
f x0 f x1 f x1 f x2 f xn 1 f xn
I h h h
2 2 2
n 1
f x0 2 f xi f xn
I (b a) i 1
2n
}
}
2n
}
}
e
x2
I dx 25
1 20
f(x)
15
ba
h 10
n 5
0
0 0.3 0.6 0.9 1 .2 1 .5 1 .8
x
n 1
f x0 2 f xi f xn
I b a i 1
2n
Simpsons 1/3 Rule
I f x dx f 2 x dx
a a
f n x a0 a1 x a2 x 2
Simpsons 1/3 Rule
I f x dx f 2 x dx
a a
x2
x x1 x x2
f x0 ....... dx
x 0
0
x x1 x0 x2
Simpsons 1/3 Rule
I1
I3
Simpsons 1/3 Rule
h
I f x0 4 f x1 f x2
3
f x0 4 f x1 f x2
b a
}
6
}
12
where a b
2880
Multiple Application of Simpsons 1/3
Rule
x1 x2 xn
I b a i 1, 3,5.. j 2 , 4 , 6..
3n
Ea
b a
5
f 4
180n 4
n 1 n 2
f x0 4 f x 2 f x f x
i j n
I b a i 1, 3,5.. j 2 , 4 , 6..
3n
The odd points represent the middle term for each
application. Hence carry the weight 4.
x
Simpsons 3/8 Rule
f n x a 0 a1 x a 2 x a 3 x
2 3
3h
I f x 0 3f x1 3f x 2 f x 3
8
Composite Numerical
Integration
Riemann Sum (Rectangular
Subdivided Area)
The area under the curve is
subdivided into n subintervals. Each
subinterval is treated as a rectangle.
The area of all subintervals are
added to determine the area under
the curve.
There are several variations of
Riemann sum as applied to
composite integration.
Left
xIn b a / n
x1 Riemann
a
sum, the
x2 a x
left-side
sample of
x3 the
a function
2 x
M
is used as
the height
xi ofathe
i 1 x
individual
rectangle.
n
f x dx f x x
b
a i
i 1
x
In Right
b a / n
x1 a xsum,
Riemann
the right-side
x2 a of
sample 2the
x
function is
x3 aas
used
3the
x
M of the
height
individual
xi a i x
rectangle.
f x dx f x x
b
a i
i 1
x In bthe
a / n
Midpoint Rule,
a 2sample
x1 the 1 1 xat/ 2
a 2middle
x2 the 2 1 ofx / 2
the
a 2 3 1 xis/ 2
x3 subinterval
Mused as the
xi height
a 2 i of
1 the
x / 2
individual
rectangle.
n
f x dx f xi x
b
a
i 1
Composite Trapezoidal Rule:
Divide the interval into n
subintervals and apply Trapezoidal
Rule in each subinterval.
b
h n 1
f ( x )dx f a 2 f ( x k ) f (b )
a
2 k 1
whe
re
ba
h and x k a kh for k 0, 1, 2, ... , n
n
h
b ( n / 2 ) 1
f ( x )dx f a 2 f (x 2k )
a
3 k 1
n/ 2
4 f ( x 2 k 1 ) f (b )
k 1
9
2k
0 sin( x )dx 60 sin 0 2
k 1
sin
20
10
( 2k 1)
4 sin sin( )
k 1 20
2.000006
Integration of Unequal Segments
2n
f x0 f x1 f x1 f x2 f xn 1 f xn
I h h h
2 2 2
Integration of Unequal Segments
trapezoidal
rule
Integration of Unequal Segments
1/3
trapezoidal rule
rule
Integration of Unequal Segments
1/3
trapezoidal rule
rule 3/8
rule
Integration of Unequal Segments
trapezoidal
1/3 rule
trapezoidal rule
rule 3/8
rule
Trapezoidal rule integration
with Excel
Riemann
Sum rule
integration
with Excel
n
f x dx f x x
b
a i
i 1
x n 1
I f x0 2 f xi f xn Trapezoidal
2 i 1 Sum rule
integration
The endpoints (initial and terminal) of the interval,
and the number of divisions are entered in the cells
A2, B2, C2, respectively. The value of h is calculated
in the cell D2 by entering the formula = (B2-A2)/C2.
1
x2
b. x .e dx
0
If it is taken as x = 0.25
Compare their calculation results with the
exact value and make a remark.
2. Do problem No. 17 Chapter 3 Chemical
Reaction Engineering by Levenspiel on
catalytic reaction of sucrose.
THE END
1.5
x2
Example: I ce 1.00000
dx (if c = 1.517858)
0.2
n Trap. Simp. 1/3 Simp. 3/8
1 1.05191
2 1.00499* 0.98935
3 1.00187* 0.99561
4 1.00099 0.99965*
6 1.00042 0.99994* 0.99985
8 1.00023 0.99998*
9 1.00019 0.99998*
12 1.00011 1.00000* 1.00000*
15 1.00008 1.00000*
16 1.00006 1.00000*
32 1.00001
64 1.00000
Asterisk (*) denotes the more accurate answer for each n.