Chapter6 (MBI) El
Chapter6 (MBI) El
Chapter6 (MBI) El
!y f ( xi + !x) " f ( xi ) = !x !x
where; y and f(x) = dependent variable x = independent variable
------ (6.1)
Numerical Methods for Chemical Engineers If x approach zero (shown in Fig 1 a - c) the difference becomes derivative;
Numerical Methods for Chemical Engineers Inverse of differentiation is integration. Integrate means (dictionary): to bring together, to unite or to indicate the total amount. Mathematically, integration is represented by:
b
I = ! f ( x) dx
a
-------- (6.2)
where, I = integral the function f(x) with respect to independent variable x evaluated between limits x = a to x = b. Fig. 2 represent a graphical concept of integral, where integral of f(x) between limit x = a to x = b, represents to the area under the curve.
Numerical Methods for Chemical Engineers Function to be differentiated or integrated will be in one of three forms: 1. Simple continuous function such as polynomial, an exponential or trigonometric. 2. Complicated continuous function - difficult to differentiate or integrate directly 3. Tabulated function values x and f(x) are given as discrete points i.e experimental data or field data. Quick Example: Find the integral below.
0.8
Answer:
0.8
Numerical Methods for Chemical Engineers 6.2 Newton-Cotes Integration Formulas The most common numerical integration schemes. Based on strategy of replacing a complicated function or tabulated data with an approximating function that is easy to integrate.
b b
where; fn(x) = polynomial in the form of fn(x) = ao + a1x + a2x2 + . . . .an-1 x n-1 + anxn n = order of polynomial
Numerical Methods for Chemical Engineers Fig.3a ; first order polynomial is used as approximation (as straight line) Fig.3b ; parabola is employed
Numerical Methods for Chemical Engineers Integral can also be computed using a series of polynomial or data over segments of constant length. Fig.4 ; Three straight line segments are used to approximate the integral (also called as strip method)
Fig. 4 Newton-Cotes formulas can be divided into 2 forms; a. Closed forms - data points at beginning and end of the limits of integration are known (shown in Fig.5a) b. Open forms - integration limits extended beyond the range of the data (shown in Fig.5b) Chapter 6 is only emphasizes the closed forms.
7
Fig. 5 (a) and (b) Open Newton-Cotes, generally are not used for definite integration, they are utilized for evaluating improper integrals and for solution of Ordinary Differential equations (ODE) - as discussed later in Chapter 7.
Numerical Methods for Chemical Engineers 6.2.1 Trapezoidal Rule The first of Newton-Cotes closed integration formula. For 1st order polynomial integration:
f (b) ! f (a ) f1 ( x) = f (a ) + ( x ! a) b!a
Integral forms (area under straight line between the limits a and b)
f (a ) + f (b) I = (b ! a ) 2
Numerical Methods for Chemical Engineers Geometrically, trapezoidal rule is equivalent to approximating the area of the trapezoidal under the straight line connecting f(a) and f(b) as shown in Fig.6. Integral estimate can be represented as; I = width x height or (b a) x Average height where; Average height = average of the function values at end points = [f(a) + f(b)]/2
Fig.6
10
Numerical Methods for Chemical Engineers 6.2.2 Error of Trapezoidal Rule An estimate for truncation error of a single application of the trapezoidal rule is;
I = (b ! a )
f (a ) + f (b) 2
11
Numerical Methods for Chemical Engineers Example 1: Use trapezoidal rule to numerically integrate the function below; f(x) = 0.2 + 25x 200x2 + 675 x3 900x4 + 400x5 from a = 0 to b = 0.8 The exact value of the integral, analytically determined is 1.640533
Solution: Function values; f(0) = 0.2 and f(0.8) = 0.232 Substituted into trapezoidal rule formula:
Numerical Methods for Chemical Engineers Et = 1.640533 0.1728 = 1.467733 t = 1.467733/1.640533 x 100% = 89.5% A large error (Fig.7) because neglects significant portion above the straight line.
Fig.7
13
Numerical Methods for Chemical Engineers In actual situations, we have no knowledge of the true value, therefore an approximate error estimate is required. To obtain approximate error, the functions 2nd derivative over the interval can be computed by differentiating the original function twice; For example: f(x) = 0.2 + 25x 200x2 + 675 x3 900x4 + 400x5 f(x) = 25 400x + 2025x2 3600x3 + 2000x4 f(x) = -400 + 4050x 10800x2 + 8000x3 Average/Mean value of 2nd derivative:
f "( x) = !
0.8
= - 60 Substituted into:
Numerical Methods for Chemical Engineers 6.2.3 The Multiple Application Trapezoidal Rule To improve the accuracy of Trapezoidal Rule - by divide the integration interval from a to b into a number of segments. Results equation is called Multiple Application or composite integration formulas.
15
Numerical Methods for Chemical Engineers Fig.8: General format for Multiple Application Integrals
x1
x2
xn
xn"1
f ( x)dx
16
---(2)
------ (3)
------- (5)
17
f""
where;
! f " (# )
i i =1
----- (6)
--------- (7)
18
Numerical Methods for Chemical Engineers Example 2: Use the two-segment trapezoidal rule to estimate the integral of: f(x) = 0.2 + 25x 200x2 + 675 x3 900x4 + 400x5 From a = 0 and b = 0.8. Then employ equation (8) to estimate the approximation error. The true value for the integral is 1.640533 Solution: n = 2, thus, h = (b-a)/n = (0.8-0)/2 = 0.4 Function values; f(0) = 0.2 f(0.4) = 2.456 f(0.8) = 0.232 Thus; from equation (4)
n & # f ( xo ) + 2( f ( xi ) + f ( xn ) ! $ i =1 ! I = (b ' a ) $ 2n $ ! $ ! % "
Numerical Methods for Chemical Engineers To calculate true error; Et = 1.640533 1.0688 = 0.57173 where = 34.9%
To calculate approximate error for multiple application trapezoidal rule: from equation (8);
(b ! a ) 3 _ Ea = ! f" 2 12n
(0.8) 3 Ea = ! (!60) = 0.64 2 12(2 )
Where (60) is the average 2nd derivative determined previously in Example. Fig.9: significant reduce in error by increasing segment
20
Numerical Methods for Chemical Engineers 6.3 Simpson Rules Another way to obtain a more accurate estimate of an integral, by using high-order polynomials to connect the data points. If there is an extra point midway between f(a) and f(b), the three points can be connected with a parabola, as shown in Fig. 10(a).
Fig.10a: The formula that result from the intervals under these polynomials are called Simpsons Rules.
21
Numerical Methods for Chemical Engineers 6.3.1 The Simpsons 1/3 Rule Simpsons 1/3 rule, results when a 2nd order interpolating polynomial is substituted into equation;
If a = xo and b = x2, and f2(x) = 2nd order Lagrange polynomial; the integral above becomes;
x2 ' ( x ( x )( x ( x ) $ ( x ( x0 )( x ( x2 ) ( x ( x0 )( x ( x1 ) 1 2 I =! % f ( x0 ) + f ( x1 ) + f ( x2 )" dx x1 ( x1 ( x0 )( x1 ( x2 ) ( x2 ( x0 )( x2 ( x1 ) & ( x0 ( x1 )( x0 ( x2 ) #
h I ! [ f ( x0 ) + 4 f ( x1 ) + f ( x2 )] 3
where; h = (b-a)/2 Same as the 2nd Newton-Cotes Closed integration formula. 1/3 label because h is divided by 3
22
Numerical Methods for Chemical Engineers Simpsons 1/3 Rule can also be expressed as;
6.3.2 Truncation Error for Simpsons 1/3 Rule For a single-segment application;
Et = "
1 5 ( 4) h f (! ) 90
23
Numerical Methods for Chemical Engineers Example 3: Single application of Simpsons 1/3 Rule. Use equation below to integrate from a = 0 to b = 0.8. Also calculate the true error and approximation error. The true value for the integral is 1.640533 f(x) = 0.2 + 25x 200x2 + 675 x3 900x4 + 400x5 Solution: Function values; f(0) = 0.2 f(0.4) = 2.456 f(0.8) = 0.232 Therefore from Simpsons 1/3 rule equation;
& f ( x0 ) + 4 f ( x1 ) + f ( x2 ) # I ( (b ' a ) $ ! 6 % " & 0.2 + 4(2.456) + 0.232 # I = (0.8) $ ! = 1.367467 6 % "
where; Et = 1.640533 1.367467 = 0.2730667 and; t = 0.2730667/1.640533 x 100% = 16.8% (5 time more accurate than trapezoidal rule; t = 89.5%)
24
25
Numerical Methods for Chemical Engineers 6.3.3 The Multiple Application Simpsons 1/3 Rule Simpsons rule can be improved by dividing the integration interval into a number of segments of equal width, h = (b-a)/n.
26
x2
x4
xn
xn"2
f ( x)dx
27
Numerical Methods for Chemical Engineers Combining terms and change, h = (b-a)/n
n '1 n'2 & # f ( x0 ) + 4 ) f ( xi ) + 2 ) f ( x j ) + f ( xn ) ! $ i =1, 3, 5... j = 2 , 4 , 6... ! I ( (b ' a) $ 3n ! width $ $ ! % " Average. Height
The equation above is called as the Multiple Application Simpsons 1/3 Rule.
6.3.4 Error Estimate of Multiple Application Simpson 1/3 Rule. Same fashion as for Trapezoidal Rule;
(b ! a ) 5 !4 ) Ea = ! f( 180n 4
where, f 4 = the average 4th derivative for the interval.
28
Numerical Methods for Chemical Engineers Example 4 : Multiple Application Simpsons 1/3 Rule By using the multiple application Simpsons rule, with n = 4 estimate the integral of; f(x) = 0.2 + 25x 200x2 + 675 x3 900x4 + 400x5 From a = 0 and b = 0.8. Exact integral is 1.640533 Solution: n = 4; thus h = (b-a)/n = 0.8/4 = 0.2
Calculate for functions value; f(0) = 0.2 f(0.2) = 1.288 f(0.4) = 2.456 f(0.6) = 3.464
f(0.8) = 0.232
From the Multiple application Simpsons 1/3 Rule; n '1 n'2 & # f ( x0 ) + 4 ) f ( xi ) + 2 ) f ( x j ) + f ( xn ) ! $ i =1, 3, 5... j = 2 , 4 , 6... ! I ( (b ' a ) $ 3n $ ! width $ ! % "
Average. Height
Numerical Methods for Chemical Engineers Thus; Et = 1.640533 1.623467 = 0.017067 t = 0.017067 / 1.640533 x 100% = 1.04%
Approximation error;
30
Numerical Methods for Chemical Engineers 6.3.5 The Simpsons 3/8 Rule Permit evaluation of odd numbers of segments, and even number of points Derivative of Trapezoidal and Simpsons 1/3 rule, 3rd order Lagrange Polynomial can be fit to four points and integrated.
To yield;
Numerical Methods for Chemical Engineers Simpsons 3/8 Rule expressed in trapezoidal forms;
3 5 ( 4) Et = " h f (! ) 80
Because, h = (b-a)/3, thus;
Numerical Methods for Chemical Engineers Example 5: The Simpsons 3/8 Rule a. Use Simpsons 3/8 Rule to integrate; f(x) = 0.2 + 25x 200x2 + 675 x3 900x4 + 400x5 from a = 0 to b = 0.8. b. Use it in conjunction with Simpsons 1/3 Rule to integrate the same function for 5 segments.
Solution: a. A single application of Simpsons 3/8 Rule requires 4 points (3 intervals) Thus; f(0) = 0.2 f(0.2667) = 1.432724 f(0.5333) = 3.487177 f(0.8) = 0.232 For Simpsons 3/8 Rule;
' $ f ( x0 ) + 3 f ( x1 ) + 3 f ( x2 ) + f ( x3 ) " I ! (b ( a ) % " 8 Width % Average. Height & # ' 0.2 + 3(1.432724) + 3(3.487177) + 0.232 $ ! 0.8% " 8 & # ! 1.519170 33
Numerical Methods for Chemical Engineers Et = 1.640533 1.519170 = 0.1213630 t = 0.1213630/1.640533 x 100% = 7.4% For Approximation error;
34
Numerical Methods for Chemical Engineers b. The data needed for a 5-segment application (h = 0.16) is; f(0) = 0.2 f(0.32) = 1.743393 f(0.64) = 3.181929 f(0.16) = 1.296919 f(0.48) = 3.186015 f(0.80) = 0.232
Integral for the first two segments is obtained using Simpsons 1/3 Rule;
35
Numerical Methods for Chemical Engineers For the last three segments, Simpsons 3/8 Rule can be used to obtain;
' $ f ( x0 ) + 3 f ( x1 ) + 3 f ( x2 ) + f ( x3 ) " I ! (b ( a ) % " 8 Width % Average. Height & # '1.743393 + 3(3.186015) + 3(3.181929) + 0.232 $ ! 0.48% " 8 & # ! 1.264754
Total integral; I = 0.3803237 + 1.264753 = 1.645077 where; Et = 1.640533 1.645077 = -0.00454383 t = -0.28%
36
Numerical Methods for Chemical Engineers 6.4 Integration with Unequal Segments From previous section, all formulas for numerical integration have been based on equally spaced data points [h = (b-a)/n]. In many situation, this assumption does not happen and we must deal with unequal sized segments. One method is to apply the trapezoidal rule to each segment and sum the results;
37
Numerical Methods for Chemical Engineers Example 6: Trapezoidal Rule with unequal segments The information in Table below was generated using the same polynomial employed in Example 1. Use Trapezoidal Rule for Unequal Segments to determine the integral for this data. True value for polynomial is 1.640533. f(x) = 0.2 + 25x 200x2 + 675 x3 900x4 + 400x5 x 0.0 0.12 0.22 0.32 0.36 0.40 f(x) 0.2 1.309729 1.305241 1.743393 2.074903 2.456000 x 0.44 0.54 0.64 0.70 0.80 f(x) 2.842985 3.507297 3.181929 2.363000 0.232000
38
Numerical Methods for Chemical Engineers Solution: From Trapezoidal Rule for Unequal Segments;
where; t= 2.8%
39
Numerical Methods for Chemical Engineers Example 7: Inclusion of Simpsons Rules in the Evaluation of Uneven Data Recompute the integral for the data but use Simpsons rules for those segments where they are appropriate. f(x) = 0.2 + 25x 200x2 + 675 x3 900x4 + 400x5 x 0.0 0.12 0.22 0.32 0.36 0.40 f(x) 0.2 1.309729 1.305241 1.743393 2.074903 2.456000 x 0.44 0.54 0.64 0.70 0.80 f(x) 2.842985 3.507297 3.181929 2.363000 0.232000
40
Numerical Methods for Chemical Engineers Solution: The first segment is evaluated with trapezoidal rule: 1. x = 0 to 0.12 (use trapezoidal)
I = 0.2726863
4. x = 0.44 to 0.64 (use Simpsons 1/3)
I = 0.6684701
5. 6. x = 0.64 to 0.80 (use trapezoidal) Total integral = 1.603641
41
Numerical Methods for Chemical Engineers 6.5 NUMERICAL DIFFERENTIATION In previous chapter we discussed, finite-divideddifference, and also we developed forward, backward and centered difference approximations of 1st and higher derivatives. Now we will develop more accurate formula by retaining more terms, by applying Taylor Series. 6.5.1 High Accuracy differentiation Formulas Taylor series expansion;
f ( xi +1 ) ! f ( xi ) f ' ( xi ) = + O ( h) h
42
Numerical Methods for Chemical Engineers In this chapter we retain 2nd derivative term by substituting the following approximation of 2nd derivative;
Thus;
'
f ( xi + 2 ) ! 2 f ( xi +1 ) + f ( xi ) f ( xi ) = + O ( h) 2 h
''
f ( xi +1 ) ! f ( xi ) f ( xi + 2 ) ! 2 f ( xi +1 ) + f ( xi ) f ( xi ) = ! h + O(h 2 ) h 2h 2
Simplify the equation above;
! f ( xi + 2 ) + 4 f ( xi +1 ) ! 3 f ( xi ) f ( xi ) = + O(h 2 ) 2h
'
Inclusion of 2nd derivative term has improved the accuracy of 0(h2) Similar improved versions for : backward and centered formulas as shown in Fig. 23.1, 23.2, and 23.3
43
44
45
46
Numerical Methods for Chemical Engineers Example 7: High Accuracy Differentiation Formulas Estimate the derivative of the following function using high accuracy formulas:
47
Numerical Methods for Chemical Engineers Using high accuracy formulas, data needed:
xi ! 2 = 0
f ( xi ! 2 ) = 1.2
f ' (0.5) =
" t = 0%
Numerical Methods for Chemical Engineers 6.5.2 Derivatives of Unequally Spaced Data For the finite-divided difference approximations, the data had to be evenly spaced. One way to handle non-equispaced data is to fit a second-order Lagrange interpolating polynomial.
f ' ( x) = f ( xi !1 )
2 x ! xi ! xi +1 + ( xi !1 ! xi )( xi !1 ! xi +1 )
2 x ! xi !1 ! xi +1 f ( xi ) + ( xi ! xi !1 )( xi ! xi +1 ) 2 x ! xi !1 ! xi f ( xi +1 ) ( xi +1 ! xi !1 )( xi +1 ! xi )
Three main advantages: 1. It can be used to estimate the derivative within any range by three points. 2. The points do not have to be equally spaced. 3. The accuracy is the same as centered difference.
49
Numerical Methods for Chemical Engineers Example: Differentiating Unequally Spaced Data
50
51