Chapter 1 Numerical Integration In this chapter we examine a few basic numerical techniques to approximate a definite integral. You may recall some of this from Calculus I where we discussed the left, right and midpoint rules to motivate the definition of the Riemann integral. 1.1 left, right and midpoint rules We aim to calculate the signed-area bounded by y = f(x) for a x b. In this section we discuss three methods to approximate the signed-area. To begin we should settle some standard notation which we will continue to use for several upcoming sections. Definition 1.1.1. partition of [a, b]. Suppose a < b then [a,b] R. Define Δx = b a n for n N and let x j = a+jδx for j =,1,...,n. In particular, x o = a and x n = b. The closed interval [a,b] is a union of n-subintervals of length Δx. Note that the closed interval [a,b] = [x o,x 1 ] [x 1,x 2 ] [x n 1,x n ]. The followingruleisan intuitivelyobvious wayto calculatethesigned-area. Definition 1.1.2. left endpoint rule (L n ). Suppose that [a,b] dom(f) then we define n 1 L n = f(x j )Δx = [f(x )+f(x 1 )+ +f(x n 1 )]Δx. j= Example 1.1.3. Let f(x) = x 2 and estimate the signed-area bounded by f on [1,3] by the left-endpoint rule. To keep things simple I ll just illustrate the calculation with n = 4. Note Δx = 3 1 4 =.5 thus x o = 1,x 1 = 1.5,x 2 = 2,x 3 = 2.5 and x 4 = 3. L 4 = [f(1)+f(1.5)+f(2)+f(2.5)]δx = [1+2.25+4+6.25](.5) = 6.75 It s clear from the picture below that L 4 underestimates the true area under the curve. 39
31 CHAPTER 1. NUMERICAL INTEGRATION Definition 1.1.4. right endpoint rule (R n ). Suppose that [a,b] dom(f) then we define n R n = f(x j )Δx = [f(x 1 )+f(x 2 )+ +f(x n )]Δx. Example 1.1.5. Let f(x) = x 2 and estimate the signed-area bounded by f on [1,3] by the right end-point rule. To keep things simple I ll just illustrate the calculation with n = 4. Note Δx = 3 1 4 =.5 thus x o = 1,x 1 = 1.5,x 2 = 2,x 3 = 2.5 and x 4 = 3. R 4 = [f(1.5)+f(2)+f(2.5)+f(3)]δx = [2.25+4+6.25+9](.5) = 1.75 It s clear from the picture below that R 4 overestimates the true area under the curve. Definition 1.1.6. midpoint rule (M n ). Suppose that [a,b] dom(f) and denote the midpoints by x k = 1 2 (x k +x k 1 ) and define n M n = f( x j )Δx = [f( x 1 )+f( x 2 )+ +f( x n )]Δx. Example 1.1.7. Let f(x) = x 2 and estimate the signed-area bounded by f on [1,3] by the midpoint rule. To keep things simple I ll just illustrate the calculation with n = 4. Note Δx = 3 1 4 =.5 thus x 1 = 1.25, x 2 = 1.75, x 3 = 2.25 and x 4 = 2.75. M 4 = [f(1.25)+f(1.75)+f(2.25)+f(2.75)]δx = [1.5625+3.625+5.625+7.5625](.5) = 8.625 Clearly L 4 < M 4 < R 4 and if you study the errors you can see L 4 < M 4 < A < R 4.
1.1. LEFT, RIGHT AND MIDPOINT RULES 311 Notice that the size of the errors will shrink if we increase n. In particular, it is intuitively obvious that as n we will obtain the precise area bounded by the curve. Moreover, we expect that the distinction between L n,r n and M n should vanish as n. Careful proof of this seemingly obvious claim is beyond the scope of this course. In any event, we did prove the FTC part II in calculus I and as such we can calculate the area exactly with ease for this function: Example 1.1.8. 3 1 x 2 dx = 1 3 x3 3 1 = 1 3 (27 1) = 26 3 Notice that the error in M 4 is simply E = 8.6667 8.625 =.417 which is within.5% of the true area. I will not attempt to give an quantitative analysis of the error in L n,r n or M n at this time. However, I do hope you know terms such as increasing, decreasing, concave up/down and are able to discuss the relative errors in these methods for a specific function qualitatively, at least you should be able to rank the rules based on a geometric understanding of how the approximation schemes are constructed. Stewart discusses such issues in 8.7. Qualitatively, if the function is monotonic then we should expect that the area is bounded between L n and R n. Remark 1.1.9. You might ask why in the world we would calculate L n,r n or M n when we could just use the FTC part II? Isn t it easier to evaluate F(b) F(a) rather than adding all those terms? Well, yes, of course it s easier. However, it s hard to use the FTC when you can t find a formula for the antiderivative. For example, 1 e x2 or 1 1+x3 dx. Example 1.1.1. Calculate M 5 to approximate 1 e x2. Note δx = 2 and x j = 1,3,5,7,9 for j = 1,2,3,4,5. M 5 = 2(e 1 +e 9 +e 25 +e 49 +e 81 ).73657 In contrast, the numerical integrator in Wolfram Alpha returns: 1 e x2.8862269 If you study the graph y = e x2 the fact that M 5 is an underestimate is not surprising. Next, I ll calculate M 1, note x j = j.5 for j = 1,2,...,1 and δx = 1. 1 M 1 = e (j.5)2.8861352
312 CHAPTER 1. NUMERICAL INTEGRATION Now, we agree with Wolfram Alpha to the first 3 decimals. Calculate M 1, this makes δx =.1 and x j =.1j.5 for j = 1,2,...,1 1 M 1 = e (.1j.5)2.8862269. Obviously I used technology to compute this sum. I expect you will do the same in your homework. The methods used to compute integrals numerically by mathematical software are most likely built off the Simpson s rule which we consider at the end of this chapter. 1.2 trapezoid rule The idea of the trapezoid rule is simple enough, approximate a signed area by replacing the function with a trapezoidal approximation. Then the signed-area under the trapezoids are easy to calculate. We still use the same partition notation and our goal is to approximate once more b f(x)dx. Let s think about a subinterval a [x j 1,x j ]. We can replace f(x) with the secant line from (x j 1,f(x j 1 )) to (x j,f(x j )). This secant line has equation y = s j (x) = f(x j )+ f(x j) f(x j 1 ) (x x j ) Δx Therefore, we can approximate the integral on this subinterval as follows: xj xj ( f(x)dx f(x j )+ f(x ) j) f(x j 1 ) (x x j ) dx x j 1 Δx x j 1 = f(x j )(x j x j 1 ) f(x j) f(x j 1 ) (x j 1 x j ) 2 2Δx = f(x j )Δx f(x j) f(x j 1 ) ( Δx) 2 2Δx = 1 [ ] f(x j )+f(x j 1 ) Δx. 2 Consider that b x1 x2 xn 1 b f(x)dx = f(x)dx+ f(x)dx+ + f(x)dx+ f(x)dx a a x 1 x n 2 x n 1 ( ) ( ) 1 2 f(x 1 )+f(a)) Δx+ 1 2 f(x 2 )+f(x 1 ) Δx+ ( ) ( ) + 1 2 f(x n 1 )+f(x n 2 )) Δx+ 1 2 f(b)+f(x n 1 )) Δx ( ) f(a)+2f(x 1 )+2f(x 2 )+ +2f(x n 2 )+2f(x n 1 )+f(b) Δx = 1 2 Definition 1.2.1. Trapezoid rule (T n ). Suppose that [a,b] dom(f) then we define n 1 ( ) T n = 1 2 f(a)+f(b) + f(x j )Δx = 2[ 1 f(a)+2f(x1 )+2f(x 2 )+ +2f(x n 1 )+f(b) ] Δx.
1.3. SIMPSON S RULE 313 Example 1.2.2. Once more I return to 1 e x2. We ll examine T 1, T 1 = 1 2( 1+2e 1 +2e 4 + +2e 81 +e 1).8863186. Wolfram Alpha yields 1 e x2.8862269 so you can see we got the first 3 decimals, just like M 1. This is not surprising (see the error bounds for T n and M n they are very much the same order, page 535). Again, I should emphasize that if you must do these with technology. I ve used a mixture of Wolfram Alpha and plain old figuring to arrive at my numbers. You are free to use Mathematica, Matlab, etc... it matters not to me which CAS 1 you use. Just learn something. 1.3 Simpson s Rule The idea of Simpson s rule is simple enough: approximate the signed area by replacing the given function with a parabolic splice on each subinterval. We can easily integrate the signed area under parabolas so calculating the approximate total signed area should be fairly easy. In this case we must suppose that the number of approximating regions is even. After a couple pages of algebra one comes to the following formula: b a f(x)dx Δx [ ] f(a)+4f(x 1 )+2f(x 2 )+4f(x 3 )+ +4f(x n 3 )+2f(x n 2 )+4f(x n 1 )+f(b) 3 This is known as Simpson s Rule. Definition 1.3.1. Simpson s rule (S n ). Suppose that [a,b] dom(f) and n is even then we define S n = Δx 3 [ f(a)+4f(x 1 )+2f(x 2 )+4f(x 3 )+ +4f(x n 3 )+2f(x n 2 )+4f(x n 1 )+f(b) ]. Let us once more return to my favorite example. Example 1.3.2. Once more I return to 1 e x2 dx. We ll examine S 1, ( S 1 = 1 3 1+4e 1 +2e 4 +4e 9 +2e 16 +4e 25 +2e 36 +4e 49 +2e 64 +4e 81 +e 1) S 1.8362143 Recall T 1.8863186 and Wolfram Alpha yields 1 e x2.8862269 so you can see we only correctly calculated the first decimal. This is actually somewhat interesting since it is usually the case that Simpson s rule gives a more accurate result for a given number of approximating regions (see the error bounds for S n, page 539 in Stewart s 6-th Ed.). One may calculate that S 2.886196 so at least by n = 2 the rule of Simpson has arrived at the same accuracy as the trapezoid or midpoint rules of order 1. 1 Computer Algebra System
314 CHAPTER 1. NUMERICAL INTEGRATION Example 1.3.3. I feel bad for Simpson s rule so I m going to give it another chance at a new function. Let s calculate 1 1+x5 dx via all three methods and by the numerical integrator in Wolfram Alpha: 1 1+x5 dx 1.74669188848 by Wolfram Alpha. M 1 1.73933 T 1 1.76142 S 1 1.74671 You can see that Simpson s rule has 5 correct digits whereas the midpoint and trapezoid have only 3 correct digits. You can find a link to an online calculator at my website which both calculates and graphs these rules. Example 1.3.4. Below are a couple screen-shots of a Java Applet which calculates and graphs the left, right, midpoint, trapezoid and Simpson s rule. Note the website of the author is visible at the top of one of the pictures.
1.3. SIMPSON S RULE 315 Finally, Wolfram Alpha weighs in with an estimate of 2 1 sin(1/x)dx = Ci(1/2)+Ci(1)+2sin(1/2) sin(1).632568 where Ci(x) is the cosine integral function. This is one of the aspects of Wolfram Alpha I especially enjoy, it leads you to discover new mathematics while you are solving a standard problem. Welll, I hope you ve seen enough that you could numerically approximate a definite integral. The general and careful study of this problem is beyond this course.
316 CHAPTER 1. NUMERICAL INTEGRATION