MATH 164, Spring 2001 Due Date: Name(s): Project 8.7: Approximate Integration Objective To illustrate the Trapezoidal Rule and Simpson's Rule. Narrative If you have not already done so, read Section 8.7 in the text. In this project we illustrate and compare Riemann sums, the Trapezoidal Rule, and Simpson's Rule by looking at how they approximate 2 x=1 dx x = ln 2. In this project we introduce the command type: type(i,odd) is true if i is odd and false if i is even, and type(i,even) is true if i is even and false if i is odd. Task 1. Type the command lines in the left-hand column below into Maple in the order in which they are listed. The effect of each command is described in the right-hand column for your reference. This section of code provides Maple some initial information. > # Project 8.7: Approximate Integration > restart; Clear Maple's memory. > f := x -> 1/x; Let f(x) = 1/x. > NInts := 8; Let the number of intervals NInts = 8. > a := 1.0; b := 2.0; dx := (b-a)/NInts; Let a = 1, b = 2, and dx = (b-a)/NInts. > Actual := int(f(x),x=a..b); What is b x=a f(x) dx? a) Continue by typing the command lines in the left-hand column below into Maple in the order in which they are listed. These commands approximate our integral by Riemann sums. > # Riemann Sums > Riemann := 0.0; Initialize Riemann to 0. > for i from 1 to NInts do Riemann := Riemann + dx*f(a+i*dx) od; Compute the Riemann sum. > plot(f(x),x=a..b); Draw the graph of f. > abs(Actual-Riemann); The Riemann sum error. b) Continue by typing the command lines in the left-hand column below into Maple in the order in which they are listed. These commands approximate our integral by the Trapezoidal Rule. > # The Trapezoidal Rule > wt := i -> if i=0 then 1 Define the weighting function wt. elif i=NInts then 1 else 2 fi; > for i from 0 to NInts do wt(i) od; Check the weighting function. > Trap := 0.0; Initialize Trap to 0. > for i from 0 to NInts do Trap := Trap + (dx/2)*wt(i)*f(a+i*dx) od; Apply the Trapezoidal Rule. > plot(f(x),x=a..b); Draw the graph of f. > abs(Actual-Trap); The Trapezoidal Rule error. c) Continue by typing the command lines in the left-hand column below into Maple in the order in which they are listed. These commands approximate our integral by Simpson's Rule. > # Simpson's Rule > wt := i -> if i=0 then 1 Define the weighting function wt. elif i=NInts then 1 elif type(i,odd) then 4 elif type(i,even) then 2 fi; > for i from 0 to NInts do wt(i) od; Check the weighting function. > Simp := 0.0; Initialize Simp to 0. > for i from 0 to NInts do Simp := Simp + (dx/3)*wt(i)*f(a+i*dx) od; Apply Simpson's Rule. > plot(f(x),x=a..b); Draw the graph of f. > abs(Actual-Simp); Simpson's Rule error. At this time, make a hard-copy of your typed input and Maple's responses. Then, ... 2. On each of the graphs you created in parts (a), (b), and (c) above, sketch and shade in the region whose area approximates 2 x=1 dx x by Riemann sums, the Trapezoidal Rule, and Simpson's Rule, respectively, when n = 8. 3. When n = 8, which method -- Riemann sums, the Trapezoidal Rule, or Simpson's Rule -- provides the best estimate of 2 x=1 dx x = ln 2? Which provides the worst? Comments In practice, many definite integrals cannot be evaluated in closed form, and techniques such as the Trapezoidal Rule and Simpson's Rule must be applied to find numerical approximations. Maple actually has built in commands that make finding such approximations quite easy. We did not use them in this project, however, since our goal was to illustrate how such methods work, not just how to use certain commands.