Numerical Methods for Eng [ENGR 391] [Lyes KADEM 2007] CHAPTER VI Numerical Integration Topics - Riemann sums Trapezoidal rule Simpson’s rule Richardson’s extrapolation Gauss quadrature rule Mathematically, integration is just finding the area under a curve from one point to another. It is b represented by f ( x)dx , where the symbol is an integral sign, the numbers a and b are the a lower and upper limits of integration, respectively, the function f is the integrand of the integral, and x is the variable of integration. Figure 1 represents a graphical demonstration of the concept. Why are we interested in integration: because most equations in physics are differential equations that must be integrated to find the solution(s). Furthermore, some physical quantities can be obtained by integration (example: displacement from velocity). The problem is that sometimes integrating analytically some functions can easily become laborious. For this reason, a wide variety of numerical methods have been developed to find the integral. Figure.6.1- Integration. I. Riemann Sums Let f be defined on the closed interval [a, b], and let ∆ be an arbitrary partition of [a, b] such as: a = x0 < x1 < x2 < … < xn-1 <xn = b, where ∆xi is the length of the ith subinterval. If ci is any point in the ith subinterval, then the sum n f (c )x , x i 1 i i Numerical Integration i 1 ci xi 81 Numerical Methods for Eng [ENGR 391] [Lyes KADEM 2007] ∆xi x1 x2 ... xi-1 xi … xn-1 xn is called a Riemann Sum of the function f for the partition ∆ on the interval [a , b]. For a given partition ∆, the length of the longest subinterval is called the norm of the partition. It is denoted by ||∆|| (the norm of ∆). The following limit is used to define the definite integral: n lim 0 f (c )x i 1 i i I This limit exists if and only if for any positive number ε, there exists a positive number δ such that for every partition ∆ of [a, b] with ||∆|| < δ, it follows that n I f (ci )xi i 1 for any choice of the numbers ci in the ith subinterval of ∆. If the limit of a Riemann Sum of f exists, then the function f is said to be integrable over [a, b] and that the Riemann Sums of f on [a, b] approach the number I. n lim 0 f (c )x i 1 i i I, b Where I f ( x)dx a Example Find the area of the region between the parabola y = x2 and the x-axis on the interval [0, 4.5]. Use Riemann’s Sum with four partitions. 2. TRAPEZOIDAL RULE Trapezoidal rule is based on the Newton-Cotes formula that if we approximate the integrand by an nth order polynomial, then the integral of the function is approximated by the integral of that n th order polynomial. b n1 a n1 n , n 0 x dx a n 1 b Numerical Integration 82 Numerical Methods for Eng [ENGR 391] [Lyes KADEM 2007] So if we want to approximate the integral b I f ( x)dx a to find the value of the above integral, we write our function under polynomial form: f ( x) f n ( x) where f n ( x) a 0 a1 x ... a n 1 x n 1 a n x n where f n (x) is an n th order polynomial. Trapezoidal rule assumes n 1, that is, the area under the linear polynomial (straight line), b b a a f ( x)dx f ( x)dx 1 2.1. DERIVATION OF THE TRAPEZOIDAL RULE We have: b b a a f ( x)dx f ( x)dx 1 b (a0 a1 x)dx a b2 a2 . a0 (b a) a1 2 But what is a0 and a1? Now if we choose, (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 f (b) f1 (b) a0 a1b Solving the above two equations for f (b) f (a ) ba f (a)b f (b)a a0 ba a and b , a1 b Hence we get, a f ( x)dx f (a)b f (b)a f (b) f (a) b 2 a 2 (b a) ba ba 2 b f ( x) a Numerical Integration f (a) f (b) dx (b a) 2 83 Numerical Methods for Eng [ENGR 391] [Lyes KADEM 2007] Example The vertical distance covered by a rocket from t 8 to t 30 seconds is given by 30 140000 x 2000 ln 9.8t dt 140000 2100t 8 a) Use single segment Trapezoidal rule to find the distance covered. b) Find the true error, Et for part (a). c) Find the absolute relative true error for part (a). 3.1. Multiple-segment Trapezoidal Rule: One way to increase the accuracy of the trapezoidal rule is to increase the number of segments between a and b. So in this procedure, we will divide [ a, b] into n equal segments and apply the Trapezoidal rule over each segment, the sum of the results obtained for each segment is the approximate value of the integral. Divide (b a ) into segment is n equal segments as shown in the figure below. Then the width of each h ba n The integral can be broken into h integrals as b I f ( x)dx a ah a ( n 1) h a2h f ( x)dx a ah f ( x)dx ... f ( x)dx a ( n2) h b f ( x)dx a ( n 1) h Figure.6.2- Multiple-segment Trapezoidal rule. Numerical Integration 84 Numerical Methods for Eng [ENGR 391] [Lyes KADEM 2007] Applying Trapezoidal rule on each segment gives: f (a) f (a h) 2 b f ( x)dx (a h) a a f ( a h) f ( a 2 h) (a 2h) (a h) 2 ……………… b a f ( x)dx ba n1 f ( a ) 2 f (a ih ) f (b) 2n i 1 Example The vertical distance covered by a rocket from t 8 to t 30 seconds is given by 30 140000 x 2000 ln 9.8t dt 140000 2100t 8 a) Use two-segment Trapezoidal rule to find the distance covered. b) Find the true error, Et for part (a). c) Find the absolute relative true error for part (a). 3.1.1. Why increasing the number of segments To illustrate the importance of increasing the number of segments in the Trapezoidal rule, let us consider the following integral: 10 300 x dx 1 ex 0 I Numerical Integration 85 Numerical Methods for Eng [ENGR 391] [Lyes KADEM 2007] The following table represents the variation in the absolute and relative error with the number of segments used. Note that with a small number of segments, the error is very high. Approximate Value Et t 1 0.681 245.91 99.724% 2 50.535 196.05 79.505% 4 170.61 75.978 30.812% n 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% 3.1.2. Error in Multiple-segment Trapezoidal Rule The true error for a single segment Trapezoidal rule is given by Et (b a) 3 f " ( ), a b 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 E1 3 ( a h) a 12 f " ( 1 ) a 1 a h h3 f " ( 1 ) 12 (a 2h) (a h)3 f "( ) E2 2 12 h3 f " ( 2 ) 12 a h 2 a 2h . . En 3 b a (n 1)h 12 f " ( n ) a (n 1)h n b h3 f " ( n ) 12 Hence the total error in multiple-segment Trapezoidal rule is n Et Ei i 1 Numerical Integration 86 Numerical Methods for Eng [ENGR 391] [Lyes KADEM 2007] h3 n f " ( i ) 12 i 1 (b a) 3 n f " ( i ) 12n 3 i 1 n f " ( (b a) 3 12n 2 i 1 i ) n n f " ( i 1 The term i n ) is an approximate average value of the second derivative f " ( x), a x b . Hence n (b a) 3 Et 12n 2 f " ( i 1 i ) n 4. SIMPSON’S 1/3RD RULE Trapezoidal rule was based on approximating the integrand by a first order polynomial, and then integrating the polynomial in the interval of integration. Simpson’s 1/3rd rule is an extension of Trapezoidal rule where the integrand is approximated by a second order polynomial. We have, b b a a I f ( x)dx f 2 ( x)dx where f 2 ( x) is a second order polynomial. f 2 ( x) a0 a1 x a 2 x 2 a b a b , f , and (b, f (b)) as the three points of the function to 2 2 evaluate a 0 , a1 and a 2 . Choose (a, f (a )), f (a ) f 2 (a ) a 0 a1 a a 2 a 2 ab ab ab ab f f2 a 0 a1 a2 2 2 2 2 f (b) f 2 (b) a 0 a1b a 2 b 2 2 Solving the above three equations for unknowns, a 0 , a1 and a 2 gives Numerical Integration 87 Numerical Methods for Eng [ENGR 391] [Lyes KADEM 2007] ab 2 a 2 f (b) abf (b) 4abf abf (a) b f (a ) 2 a0 2 a 2ab b 2 ab ab af (a ) 4af 3af (b) 3bf (a) 4bf bf (b) 2 2 a1 a 2 2ab b 2 ab 2 f (a) 2 f f (b) 2 a2 2 2 a 2ab b Then b I f 2 ( x)dx a b a0 a1 x a2 x 2 dx a b x2 x3 a 0 x a1 a2 2 3 a b2 a2 b3 a3 a0 (b a) a1 a2 2 3 Substituting values of b f 2 ( x)dx a a 0 , a1 and a 2 gives ba ab f (a) 4 f f (b) 6 2 Since for Simpson’s 1/3rd Rule, the interval h a, b is broken into 2 segments, the segment width is ba 2 Hence the Simpson’s 1/3rd rule is given by b a b f ( b) 2 h f ( x)dx 3 f (a) 4 f a Since the above form has 1/3 in its formula, it is called Simpson’s 1/3rd Rule. Numerical Integration 88 Numerical Methods for Eng [ENGR 391] [Lyes KADEM 2007] Example t 8 to t 30 is given by 140000 x 2000 ln 9.8t dt 140000 2100t 8 The distance covered by a rocket from 30 a) Use Simpson’s 1/3rd Rule to find the approximate value of x . b) Find the true error, E t c) Find the absolute relative true error, t . 4.1. Multiple Segment Simpson’s 1/3rd Rule Just like in multiple-segment Trapezoidal Rule, we can subdivide the interval a, b into n segments and apply Simpson’s 1/3rd Rule over every two segments. Note that n needs to be even. Divide interval a, b into n equal segments, hence the segment width h b a . n b xn a x0 f ( x)dx f ( x)dx where x0 a xn b b x2 x4 xn 2 xn a x0 x2 xn 4 xn 2 f ( x)dx f ( x)dx f ( x)dx ...... f ( x)dx f ( x)dx Apply Simpson’s 1/3rd Rule over each interval, b f ( x)dx ( x a 2 f ( x0 ) 4 f ( x1 ) f ( x2 ) f ( x 2 ) 4 f ( x3 ) f ( x 4 ) x0 ) ( x4 x2 ) ... 6 6 f ( x n 4 ) 4 f ( x n 3 ) f ( x n 2 ) f ( xn 2 ) 4 f ( xn 1 ) f ( xn ) ( xn2 xn4 ) ( xn xn2 ) 6 6 Since x i x i 2 2h i 2, 4, ..., n then f ( x0 ) 4 f ( x1 ) f ( x2 ) f ( x 2 ) 4 f ( x3 ) f ( x 4 ) 2h ... 6 6 b f ( x)dx 2h a f ( x n 4 ) 4 f ( x n 3 ) f ( x n 2 ) f ( x n 2 ) 4 f ( x n 1 ) f ( xn ) 2h 2h 6 6 Numerical Integration 89 Numerical Methods for Eng [ENGR 391] [Lyes KADEM 2007] h f ( x0 ) 4 f ( x1 ) f ( x3 ) ... f ( xn1 ) 2 f ( x2 ) f ( x4 ) ... f ( xn2 ) f ( xn ) 3 n 1 n2 h f ( x 0 ) 4 f ( xi ) 2 f ( xi ) f ( x n ) 3 i 1 i 2 i odd i even b a n 1 n 2 ba f ( x )dx f ( x 0 ) 4 f ( xi ) 2 f ( xi ) f ( x n ) 3n i 1 i 2 i odd i even 4.2. Error in Multiple Segment Simpson’s 1/3rd Rule The true error in a single application of Simpson’s 1/3rd Rule is given by Et (b a) 5 ( 4) f ( ), a b 2880 In Multiple Segment Simpson’s 1/3rd Rule, the error is the sum of the errors in each application of Simpson’s 1/3rd Rule. The error in n segment Simpson’s 1/3rd Rule is given by ( x 2 x0 ) 5 ( 4) f ( 1 ), x0 1 x 2 2880 h 5 ( 4) f ( 1 ) 90 ( x x2 ) 5 ( 4) E2 4 f ( 2 ), x2 2 x4 2880 h 5 ( 4) f ( 2 ) 90 E1 : ( xn xn2 ) 5 4 En f n , x n 2 n x n 2880 2 2 2 5 h ( 4) f n 90 2 Hence, the total error in Multiple Segment Simpson’s 1/3rd Rule is n 2 Et Ei i 1 5 n 2 h f ( 4) ( i ) 90 i 1 Numerical Integration 90 Numerical Methods for Eng [ENGR 391] (b a ) 90n 5 5 n 2 f n 2 f f 5 ( 4) ( i ) i 1 n ( i ) ( 4) i 1 The term ( i ) i 1 n 2 (b a ) 90n 4 ( 4) [Lyes KADEM 2007] is an approximate average value of n Et f ( 4) ( x), a x b . Hence (b a ) 5 ( 4 ) f 90n 4 where n 2 f ( 4) f ( 4) i 1 ( i ) n 5. Richardson’s Extrapolation Formula for Trapezoidal Rule The true error in a multiple segment Trapezoidal Rule with n segments for an integral b f x dx a is given by n Et f i 3 b a i 1 12n 2 where for each i, i n is a point somewhere in the domain a i 1h, a ih, and n f the term i i 1 n can be viewed as an approximate average value of us to say that the true error, Et can be written under the form: Et Numerical Integration 91 1 n2 f x in a, b . This leads Numerical Methods for Eng [ENGR 391] Et Or [Lyes KADEM 2007] C n2 where C is an approximate constant of proportionality. Since, we have Et TV I n where TV = true value I n = approximate value using n-segments. Then, we can write, C TV I n n2 If the number of segments is doubled from n to 2n in the Trapezoidal rule, C 2n 2 TV I 2 n The above equations can be combined to get: TV I 2n I 2n I n 3 6. GAUSS QUADRATURE RULE 6.1. Derivation of two-point Gaussian Quadrature Rule The two-point Gauss Quadrature Rule is an extension of the Trapezoidal Rule approximation where the arguments of the function are not predetermined as a and b , but as unknowns x1 and x 2 . So in the two-point Gauss Quadrature Rule, the integral is approximated as b I f ( x)dx a c1 f ( x1 ) c2 f ( x2 ) Numerical Integration 92 Numerical Methods for Eng [ENGR 391] There are four unknowns [Lyes KADEM 2007] x1 , x 2 , c1 and c2 . These are found by assuming that the formula gives exact results for integrating a general third order polynomial, f ( x) a 0 a1 x a 2 x a3 x . 2 3 Hence b b f ( x)dx a0 a1 x a 2 x 2 a3 x 3 dx a a x2 a 0 x a1 a2 2 b2 a0 b a a1 b x3 x4 a3 3 4 a b3 a3 b4 a4 a2 a 2 a3 2 3 4 The formula gives b f ( x)dx c f ( x ) c 1 1 2 f ( x2 ) c1 a0 a1 x1 a2 x1 a3 x1 c2 a0 a1 x2 a2 x2 a3 x2 2 3 2 a Equating the above equations gives b2 a 2 b3 a 3 b4 a 4 a 2 a3 a0 b a a1 2 3 4 c x a c x c1 a0 a1 x1 a 2 x1 a3 x1 c2 a0 a1 x2 a 2 x2 a3 x2 2 a0 c1 c2 a1 c1 x1 3 2 Since in this equation, the constants 2 2 1 1 2 2 2 3 3 a 0 , a1 , a 2 , and a 3 are arbitrary, the coefficients of a 0 , a1 , b a c1 c2 b2 a2 c1 x1 c 2 x 2 2 b3 a3 2 2 c1 x1 c 2 x 2 3 4 b a4 3 3 c1 x1 c2 x2 4 and ba 2 Numerical Integration c2 x2 a3 c1 x1 c2 x2 a2 , and a 3 are equal. This gives us the four following equations: c1 3 93 3 Numerical Methods for Eng [ENGR 391] [Lyes KADEM 2007] ba 2 b a 1 b a x1 2 3 2 b a 1 b a x2 2 2 3 c2 Hence ba ba f ( x)dx c f x c f x 2 f 2 b 1 1 2 2 a 1 ba ba 2 2 3 ba 1 ba f 2 2 3 6.2. Higher point Gaussian Quadrature Formulas If we write the integral of the function f(x) under the following form: b f ( x)dx c 1 f ( x1 ) c2 f ( x2 ) c3 f ( x3 ) a This is called the three-point Gauss Quadrature Rule. The coefficients function arguments c1 , c2 and c3 , and the x1 , x 2 and x3 are calculated by assuming the formula gives exact expressions for integrating a fifth order polynomial a b 0 a1 x a2 x 2 a3 x 3 a4 x 4 a5 x 5 dx . General n-point rules would approximate the integral a b f ( x)dx c 1 f ( x1 ) c2 f ( x2 ) . . . . . . . cn f ( xn ) a 6.2.1. Arguments and weighing factors for n-point Gauss Quadrature Rules Usually coefficients and arguments for n-point Gauss Quadrature Rule are tabulated. But, they are given for integrals of the form 1 n 1 i 1 g ( x)dx ci g ( xi ) Numerical Integration 94 Numerical Methods for Eng [ENGR 391] Table 1: Weighting factors [Lyes KADEM 2007] c and function arguments x used in Gauss Quadrature formulas Points 2 3 4 5 6 Weighting Function Factors Arguments c1 1.000000000 x1 0.577350269 c2 1.000000000 x2 0.577350269 c1 0.555555556 x1 0.774596669 c2 0.888888889 x2 0.000000000 c3 0.555555556 x3 0.774596669 c1 0.347854845 x1 0.861136312 c2 0.652145155 x2 0.339981044 c3 0.652145155 x3 0.339981044 c4 0.347854845 x4 0.861136312 c1 0.236926885 x1 0.906179846 c2 0.478628670 x2 0.538469310 c3 0.568888889 x3 0.000000000 c4 0.478628670 x4 0.538469310 c5 0.236926885 x5 0.906179846 c1 0.171324492 x1 0.932469514 c2 0.360761573 x2 0.661209386 c3 0.467913935 x3 0.238619186 c4 0.467913935 x4 0.238619186 c5 0.360761573 x5 0.661209386 c6 0.171324492 x6 0.932469514 1 Note: if the table is given for g ( x)dx integrals, how can we solve 1 Any integral with limits of Numerical Integration b f ( x)dx ? a a, b can be converted into an integral with limits 1, 1 . 95 Let Numerical Methods for Eng [ENGR 391] [Lyes KADEM 2007] x mt c If x a , then t 1 If x b, then t 1 such that a m(1) c b m(1) c Solving these two simultaneous linear Equations (21) gives ba 2 ba c 2 m Hence ba ba t 2 2 ba dx dt 2 x Substituting our values of x and dx into the integral gives us b 1 f ( x )dx a baba ba x dx 2 2 2 f 1 Example Use three-point Gauss Quadrature Rule to approximate the distance covered by a rocket from to t 30 as given by 30 140000 x 2000 ln 9.8t dt 140000 2100t 8 Also, find the absolute relative true error. Numerical Integration 96 t 8