After Reading This Chapter, You Should Be Able To s3

Total Page:16

File Type:pdf, Size:1020Kb

After Reading This Chapter, You Should Be Able To s3

Chapter 07.02 Trapezoidal Rule of Integration

After reading this chapter, you should be able to:

1. derive the trapezoidal rule of integration, 2. use the trapezoidal rule of integration to solve problems, 3. derive the multiple-segment trapezoidal rule of integration, 4. use the multiple-segment trapezoidal rule of integration to solve problems, and 5. derive the formula for the true error in the multiple-segment trapezoidal rule of integration.

What is integration? Integration is the process of measuring the area under a function plotted on a graph. Why would we want to integrate a function? Among the most common examples are finding the velocity of a body from an acceleration function, and displacement of a body from a velocity function. Throughout many engineering fields, there are (what sometimes seems like) countless applications for integral calculus. You can read about some of these applications in Chapters 07.00A-07.00G. Sometimes, the evaluation of expressions involving these integrals can become daunting, if not indeterminate. For this reason, a wide variety of numerical methods has been developed to simplify the integral. Here, we will discuss the trapezoidal rule of approximating integrals of the form b I   f xdx a where f (x) is called the integrand, a  lower limit of integration b  upper limit of integration

What is the trapezoidal rule? The trapezoidal rule is based on the Newton-Cotes formula that if one approximates the integrand by an n th order polynomial, then the integral of the function is approximated by

07.02.1 07.02.2 Chapter 07.02 the integral of that n th order polynomial. Integrating polynomials is simple and is based on the calculus formula.

Figure 1 Integration of a function

b n1 n1 n  b  a   x dx   , n  1 (1) a  n 1  So if we want to approximate the integral b I   f (x)dx (2) a to find the value of the above integral, one assumes

f (x)  f n (x) (3) where n1 n f n (x)  a0  a1 x  ...  an1 x  an x . (4) th where f n (x) is a n order polynomial. The trapezoidal rule assumes n  1, that is, approximating the integral by a linear polynomial (straight line), b b f (x)dx  f (x)dx   1 a a

Derivation of the Trapezoidal Rule Method 1: Derived from Calculus b b f (x)dx  f (x)dx   1 a a b  (a  a x)dx  0 1 a  b 2  a 2     a0 (b  a)  a1   (5)  2  Trapezoidal Rule 07.02.3

But what is a0 and a1 ? Now if one chooses, (a, f (a)) and (b, f (b)) as the two points to approximate f (x) by a straight line from a to b ,

f (a)  f1 (a)  a0  a1a (6)

f (b)  f1 (b)  a0  a1b (7)

Solving the above two equations for a1 and a0 , f (b)  f (a) a  1 b  a f (a)b  f (b)a a  (8a) 0 b  a Hence from Equation (5), b f (a)b  f (b)a f (b)  f (a) b 2  a 2  f (x)dx  (b  a)  (8b) a b  a b  a 2  f (a)  f (b)  (b  a) (9)  2 

Method 2: Also Derived from Calculus f1 (x) can also be approximated by using Newton’s divided difference polynomial as f (b)  f (a) f (x)  f (a)  (x  a) (10) 1 b  a Hence b b f (x)dx  f (x)dx   1 a a b  f (b)  f (a)     f (a)  (x  a)dx a  b  a  b  f (b)  f (a)  x 2    f (a)x    ax b  a  2     a 2 2  f (b)  f (a)  b a 2   f (a)b  f (a)a     ab   a   b  a  2 2   f (b)  f (a)  b 2 a 2   f (a)b  f (a)a     ab    b  a  2 2 

 f (b)  f (a)  1 2  f (a)b  f (a)a    b  a  b  a  2 1  f (a)b  f (a)a   f (b)  f (a)b  a 2 07.02.4 Chapter 07.02

1 1 1 1  f (a)b  f (a)a  f (b)b  f (b)a  f (a)b  f (a)a 2 2 2 2 1 1 1 1  f (a)b  f (a)a  f (b)b  f (b)a 2 2 2 2  f (a)  f (b)  (b  a) (11)  2  This gives the same result as Equation (10) because they are just different forms of writing the same polynomial.

Method 3: Derived from Geometry The trapezoidal rule can also be derived from geometry. Look at Figure 2. The area under the curve f1 (x) is the area of a trapezoid. The integral b  f (x)dx  Area of trapezoid a 1  (Sum of length of parallel sides)(Perpendicular distance between parallel sides) 2 1   f (b)  f (a)(b  a) 2  f (a)  f (b)  (b  a) (12)  2 

Figure 2 Geometric representation of trapezoidal rule.

Method 4: Derived from Method of Coefficients The trapezoidal rule can also be derived by the method of coefficients. The formula b b  a b  a  f (x)dx  f (a)  f (b) (13) a 2 2 2

 ci f (xi ) i1 where b  a c  1 2 b  a c  2 2

x1  a

x2  b Trapezoidal Rule 07.02.5

Figure 3 Area by method of coefficients.

The interpretation is that f (x) is evaluated at points a and b , and each function evaluation b  a is given a weight of . Geometrically, Equation (12) is looked at as the area of a 2 trapezoid, while Equation (13) is viewed as the sum of the area of two rectangles, as shown in Figure 3. How can one derive the trapezoidal rule by the method of coefficients?

Assume b f (x)dx  c f (a)  c f (b)  1 2 (14) a b b Let the right hand side be an exact expression for integrals of 1dx and  xdx , that is, the a a formula will then also be exact for linear combinations of f (x)  1 and f (x)  x , that is, for f (x)  a0 (1)  a1 (x) . b 1dx  b  a  c  c  1 2 (15) a b b 2  a 2 xdx   c a  c b  1 2 (16) a 2 Solving the above two equations gives b  a c  1 2 b  a c  (17) 2 2

Hence b b  a b  a  f (x)dx  f (a)  f (b) (18) a 2 2 07.02.6 Chapter 07.02

Method 5: Another approach on the Method of Coefficients The trapezoidal rule can also be derived by the method of coefficients by another approach b b  a b  a  f (x)dx  f (a)  f (b) a 2 2 Assume b f (x)dx  c f (a)  c f (b)  1 2 (19) a Let the right hand side be exact for integrals of the form b a  a x dx   0 1  a So b b  x 2  a  a x dx  a x  a    0 1   0 1  a  2  a  b 2  a 2     a0 b  a a1   (20)  2  But we want b a  a x dx  c f (a)  c f (b)   0 1  1 2 (21) a to give the same result as Equation (20) for f (x)  a0  a1 x . b a  a x dx  c a  a a  c a  a b   0 1  1  0 1  2  0 1  a

 a0 c1  c2  a1 c1a  c2b (22) Hence from Equations (20) and (22),  b 2  a 2    a0 b  a a1    a0 c1  c2  a1 c1a  c2b  2 

Since a0 and a1 are arbitrary for a general straight line

c1  c2  b  a b 2  a 2 c a  c b  (23) 1 2 2 Again, solving the above two equations (23) gives b  a c  1 2 b  a c  (24) 2 2 Therefore b f (x)dx  c f (a)  c f (b)  1 2 a Trapezoidal Rule 07.02.7

b  a b  a  f (a)  f (b) (25) 2 2

Example 1 In an attempt to understand the mechanism of the depolarization process in a fuel cell, an electro-kinetic model for mixed oxygen-methanol current on platinum was developed in the laboratory at FAMU. A very simplified model of the reaction developed suggests a functional relation in an integral form. To find the time required for 50% of the oxygen to be consumed, the time, Ts is given by 7 0.61106 6.73x  4.302510  T    dx  1.22106  11   2.31610 x 

a) Use single segment Trapezoidal rule to find the time required for 50% of the oxygen to be consumed.

b) Find the true error, Et , for part (a).

c) Find the absolute relative true error, t , for part (a).

Solution  f a f b a) I  b  a , where  2  a  1.22106 b  0.6110 6 6.73x  4.302510 7  f (x)   11   2.31610 x  6 7 6 6.731.22 10  4.302510  11 f 1.22 10    11 6   3.058110  2.316 10 1.22 10  

6 7 6 6.730.6110  4.302510  11 f 0.6110    11 6   3.2104 10  2.316 10 0.6110   11 11 6 6  3.0582 10   3.2104 10  I  0.6110 1.22 10    2   1.9119105 s b) The exact value of the above integral is, 7 0.61106 6.73x  4.302510  T    dx  1.22106  11   2.316 10 x   1.9014105 s so the true error is 07.02.8 Chapter 07.02

Et  True Value  Approximate Value  1.9014 105 1.9119 105  1056.2 c) The absolute relative true error, t , would then be True Error   100 t True Value 1056.2  100 1.9014105  0.55549 %

Multiple-Segment Trapezoidal Rule In Example 1, the true error using a single segment trapezoidal rule was large. We can divide the interval [1.22x106 ,0.61x106 ] into [1.22x106 ,9.15x107 ] and [9.15x107 ,0.61x106 ] intervals and apply the trapezoidal rule over each segment. 7 0.61106 6.73x  4.302510  T    dx  1.22106  11   2.31610 x  0.61x106 9.15x107 0.61x106  f (x)dx   f (x)dx   f (x)dx 1.22x106 1.22x106 9.15x107

6 7 7 6  7 6  f (1.22x10 )  f (9.15x10 ) 6 7  f (9.15x10 )  f (0.61x10 )  (9.15x10 1.22x10 )   (0.61x10  9.15x10 )    2   2  f (1.22x106 )  3.0581x1011 s f (9.15x107 )  3.1089x1011 s f (0.61x106 )  3.2104x1011 s Hence 11 11  7 6  3.0581x10  3.1089x10   6 (9.15x10 1.22x10 )   ... 0.61x10  2  f (x)dx      11 11  1.22x106 6 7  3.1089x10  3.2104x10  ...(0.61x10  9.15x10 )     2   1.9042x105 s

The true error, Et is 5 5 Et 1.901410 s 1.9042x10 s  280 s The true error now is reduced from 1056.2 s to  280s. Extending this procedure to dividing [a,b] into n equal segments and applying the trapezoidal rule over each segment, the sum of the results obtained for each segment is the approximate value of the integral. Trapezoidal Rule 07.02.9

Divide (b  a) into n equal segments as shown in Figure 4. Then the width of each segment is b  a h  (26) n The integral I can be broken into h integrals as b I   f (x)dx a ah a2h a(n1)h b   f (x)dx   f (x)dx  ...   f (x)dx   f (x)dx (27) a ah a(n2)h a(n1)h

Figure 4 Multiple ( n  4 ) segment trapezoidal rule

Applying trapezoidal rule Equation (27) on each segment gives b  f (a)  f (a  h)  f (x)dx  (a  h)  a  a  2   f (a  h)  f (a  2h)  (a  2h)  (a  h)  2   f (a  (n  2)h)  f (a  (n 1)h)  ……………  a  (n 1)h a  (n  2)h  2   f (a  (n 1)h)  f (b)  b  a  (n 1)h  2   f (a)  f (a  h)  f (a  h)  f (a  2h)  h  h  ......  2   2   f (a  (n  2)h)  f (a  (n 1)h)  f (a  (n 1)h)  f (b)  h  h  2   2   f (a)  2 f (a  h)  2 f (a  2h)  ...  2 f (a  (n 1)h)  f (b)  h   2  07.02.10 Chapter 07.02

h   n1     f (a)  2 f (a  ih)  f (b) 2   i1   b  a   n1     f (a)  2 f (a  ih)  f (b) (28) 2n   i1  

Example 2 In an attempt to understand the mechanism of the depolarization process in a fuel cell, an electro-kinetic model for mixed oxygen-methanol current on platinum was developed in the laboratory at FAMU. A very simplified model of the reaction developed suggests a functional relation in an integral form. To find the time required for 50% of the oxygen to be consumed, the time, Tsis given by

7 0.61106 6.73x  4.302510  T    dx  1.22106  11   2.316 10 x 

a) Use two- segment Trapezoidal rule to find the time required for 50% of the oxygen to be consumed.

b) Find the true error, Et , for part (a).

c) Find the absolute relative true error, t , for part (a). Solution b  a   n1   a) I   f (a)  2 f (a  ih)  f (b) 2n   i1   n  2 a  1.22106 b  0.6110 6 6.73x  4.302510 7  f (x)   11   2.316 10 x  b  a h  n 0.61106 1.22106  2  0.30500106 6 f x0   f 1.2210  6 7 6 6.731.22 10  4.302510  11 f 1.22 10    11 6   3.058110  2.316 10 1.22 10   6 6 f x1   f 1.2210  0.3050010   f 0.91500106  Trapezoidal Rule 07.02.11

6 7 6.730.91510  4.302510  11 f 0.91500   11 6   3.1089 10  2.316 10 0.91510   6 f x2   f xn   f 0.6110  6 7 6 6.730.6110  4.302510  11 f 0.6110    11 6   3.2104 10  2.316 10 0.6110   6 6 21 0.6110 1.2210  6   6  I   f 1.22 10  2 f a  ih  f 0.6110  22   i1    0.61106  f 1.22106  2 f 0.915106  f 0.61106  4  0.61106   3.05811011  2 3.10891011  3.21041011  4  1.9042105 s b) The exact value of the above integral is, 7 0.61106 6.73x  4.302510  T    dx  1.22106  11   2.316 10 x   1.90140105 s so the true error is

Et  True Value  Approximate Value  1.90140 105 1.9042 105  282.12

c) The absolute relative true error, t , would then be True Error   100 t True Value  282.12  100 1.9014105  0.14838 %

Table 1 Values obtained using multiple-segment Trapezoidal rule for 7 0.61106 6.73x  4.302510  T    dx  1.22106  11   2.316 10 x  07.02.12 Chapter 07.02

n Value Et t % a % 1 191190 1056.2 0.55549 --- 2 190420 282.12 0.14838 0.40711 3 190260 127.31 0.066956 0.081424 4 190210 72.017 0.037877 0.029079 5 190180 46.216 0.024307 0.013570 6 190170 32.142 0.016905 0.0074020 7 190160 23.636 0.012431 0.0044740 8 190150 18.107 0.0095231 0.0029079

Example 3 Use the multiple-segment trapezoidal rule to find the area under the curve 300x f (x)  1 e x from x  0 to x  10 .

Solution Using two segments, we get 10  0 h   5 2 300(0) f (0)   0 1 e0 300(5) f (5)   10.039 1 e5 300(10) f (10)   0.136 1 e10 b  a   n1   I   f (a)  2 f (a  ih)  f (b) 2n   i1   10  0   21     f (0)  2 f (0  5)  f (10) 2(2)   i1   10   f (0)  2 f (5)  f (10) 4 10  0  2(10.039)  0.136  50.537 4 So what is the true value of this integral? 10 300x dx  246.59  x 0 1 e Making the absolute relative true error Trapezoidal Rule 07.02.13

246.59  50.535   100 t 246.59  79.506% Why is the true value so far away from the approximate values? Just take a look at Figure 5. As you can see, the area under the “trapezoids” (yeah, they really look like triangles now) covers a small portion of the area under the curve. As we add more segments, the approximated value quickly approaches the true value.

Figure 5 2-segment trapezoidal rule approximation.

10 300x dx Table 2 Values obtained using multiple-segment trapezoidal rule for  x . 0 1 e n Approximate E  Value t t 1 0.681 245.91 99.724% 2 50.535 196.05 79.505% 4 170.61 75.978 30.812% 8 227.04 19.546 7.927% 16 241.70 4.887 1.982% 32 245.37 1.222 0.495% 64 246.28 0.305 0.124%

Example 4 Use multiple-segment trapezoidal rule to find 2 1 I   dx 0 x 07.02.14 Chapter 07.02

Solution We cannot use the trapezoidal rule for this integral, as the value of the integrand at x  0 is infinite. However, it is known that a discontinuity in a curve will not change the area under it. We can assume any value for the function at x  0. The algorithm to define the function so that we can use the multiple-segment trapezoidal rule is given below.

Function f (x) If x  0 Then f  0 If x  0 Then f  x^ (0.5) End Function

Basically, we are just assigning the function a value of zero at x  0. Everywhere else, the function is continuous. This means the true value of our integral will be just that—true. Let’s see what happens using the multiple-segment trapezoidal rule. Using two segments, we get 2  0 h   1 2 f (0)  0 1 f (1)   1 1 1 f (2)   0.70711 2 b  a   n1   I   f (a)  2 f (a  ih)  f (b) 2n   i1   2  0   21     f (0)  2 f (0 1)  f (2) 2(2)   i1   2   f (0)  2 f (1)  f (2) 4 2  0  2(1)  0.70711 4  1.3536 So what is the true value of this integral? 2 1  dx  2.8284 0 x Thus making the absolute relative true error 2.8284 1.3536   100 t 2.8284  52.145% 2 1 Table 3 Values obtained using multiple-segment trapezoidal rule for  dx . 0 x Trapezoidal Rule 07.02.15

n Approximate E  Value t t 2 1.354 1.474 52.14% 4 1.792 1.036 36.64% 8 2.097 0.731 25.85% 16 2.312 0.516 18.26% 32 2.463 0.365 12.91% 64 2.570 0.258 9.128% 128 2.646 0.182 6.454% 256 2.699 0.129 4.564% 512 2.737 0.091 3.227% 1024 2.764 0.064 2.282% 2048 2.783 0.045 1.613% 4096 2.796 0.032 1.141%

Error in Multiple-segment Trapezoidal Rule The true error for a single segment Trapezoidal rule is given by (b  a)3 E   f "( ), a    b t 12 Where  is some point in a,b. What is the error then in the multiple-segment trapezoidal rule? It will be simply the sum of the errors from each segment, where the error in each segment is that of the single segment trapezoidal rule. The error in each segment is (a  h)  a3 E   f "( ), a    a  h 1 12 1 1 h3   f "( ) 12 1 (a  2h)  (a  h)3 E   f "( ), a  h    a  2h 2 12 2 2 h3   f "( ) 12 2 . . . (a  ih)  (a  (i 1)h)3 E   f "( ), a  (i 1)h    a  ih i 12 i i h3   f "( ) 12 i . . 07.02.16 Chapter 07.02

. a  (n 1)h a  (n  2)h3 E   f "( ), a  (n  2)h    a  (n 1)h n1 12 n1 n1 h3   f "( ) 12 n1 b  a  (n 1)h3 E   f "( ), a  (n 1)h    b n 12 n n h3   f "( ) 12 n Hence the total error in the multiple-segment trapezoidal rule is n Et   Ei i1 h3 n    f "( i ) 12 i1 (b  a)3 n   3  f "( i ) 12n i1 n f "( ) (b  a)3  i   i1 12n2 n n  f "( i ) The term i1 is an approximate average value of the second derivative n f "(x), a  x  b . Hence n f "( ) (b  a)3  i E   i1 t 12n2 n In Table 4, the approximate value of the integral 30  140000    2000ln   9.8t dt 8  140000  2100t   is given as a function of the number of segments. You can visualize that as the number of segments are doubled, the true error gets approximately quartered.

Table 4 Values obtained using multiple-segment trapezoidal rule for 30  140000   x   2000ln   9.8t dt . 8  140000  2100t   Trapezoidal Rule 07.02.17

n Approximate E  %  % Value t t a 2 11266 -205 1.853 5.343 4 11113 -52 0.4701 0.3594 8 11074 -13 0.1175 0.03560 16 11065 -4 0.03616 0.00401

For example, for the 2-segment trapezoidal rule, the true error is -205, and a quarter of that error is -51.25. That is close to the true error of -48 for the 4-segment trapezoidal rule.

Can you answer the question why is the true error not exactly -51.25? How does this information help us in numerical integration? You will find out that this forms the basis of Romberg integration based on the trapezoidal rule, where we use the argument that true error gets approximately quartered when the number of segments is doubled. Romberg integration based on the trapezoidal rule is computationally more efficient than using the trapezoidal rule by itself in developing an automatic integration scheme.

INTEGRATION Topic Trapezoidal Rule Summary These are textbook notes of trapezoidal rule of integration Major Chemical Engineering Authors Autar Kaw, Michael Keteltas Date 2018 年 6 月 3 日 Web Site http://numericalmethods.eng.usf.edu

Recommended publications