Contact
CoCalc Logo Icon
StoreFeaturesDocsShareSupport News AboutSign UpSign In
| Download

Presentation

Views: 84
#Recall Riemann sums from calculus. These are done to approximate the value of an integral of a function over a specific interval by evaluating it at subintervals and creating bars with set width and height equal to the function's value at some point. There are 3 main ways to do this: left-hand rule, right hand rule, and midpoint rule. Essentially, the names of these rules designates where the height of the bar will be calculated (from the left bound of the bar, from the right, or from the midpoint). #1. First, let's try a Riemann sum for the function f(x)= x**2 + 4*x - 3 over the interval [-1,3] using subintervals of width 1 and th left-hand rule. f(x)= x**2 + 4*x - 3 leftSum = f(-1) +f(0) +f(1) +f(2) show(leftSum) #Notice that we did not evaluate f(3) because this uses the left-hand rule. Also, we did not have to multiply each evaluation since the width was just 1.
2\displaystyle 2
#2. Now, let's use the same function and interval, but this time use the right-hand rule with subintervals of width 0.5. rightSum = 0.5*f(-0.5) +0.5*f(0) +0.5*f(0.5) +0.5*f(1) +0.5*f(1.5) +0.5*f(2) +0.5*f(2.5) +0.5*f(3) show(rightSum)
19.5000000000000\displaystyle 19.5000000000000
#3. You may be curious if something is wrong at this point. Those values were very different. Try plotting the graph of f(x) over the interval to see what is going on. Be sure to make the window big enough to display it all. Make a conjecture about what caused the difference. plot(f(x), -1, 3)
#The difference is a result of the quality of each evaluation method for this interval. When evaluating at the left-hand side, we end up overestimating the area under the x-axis as well as underestimating the area above the x-axis. Using the right-hand rule essentially does the exact opposite, although it gets a little bit closer since we used smaller subintervals. #4. Let's see if the midpoint-rule improves our approximation. Use subintervals of 1 again, to make it easy. midSum = f(-.5) +f(.5) +f(1.5) +f(2.5) show(midSum)
13.0000000000000\displaystyle 13.0000000000000
#Much closer! If you haven't already checked out of curiosity, the actual value of this integral is 13 + 1/3. #5. Finally, let's use smaller intervals on the midpoint to see if it gives us an even better approximation. This time, define a function g(x)= 0.5*f(x) to save yourself some time. And remember, we want the midpoints so we will be evaluating at -0.75, -0.25, etc. g(x)= 0.5*f(x) betterSum = g(-0.75) +g(-0.25) +g(0.25) +g(0.75) +g(1.25) +g(1.75) +g(2.25) +g(2.75) show(betterSum)
13.2500000000000\displaystyle 13.2500000000000
#Indeed, that is even closer. If you are interested, try using the polygon2d function to graphically see what these look like. Here's an example for the right-hand, subinterval 1 sum of this function. a = polygon2d([(-1,0), (-1,f(-1)), (0,f(-1)), (0,0)], color='green') b = polygon2d([(0,0), (0,f(0)), (1,f(0)), (1,0)], color='green') c = polygon2d([(1,0), (1,f(1)), (2,f(1)), (2,0)], color='green') d = polygon2d([(2,0), (2,f(2)), (3,f(2)), (3,0)], color='green') plot(f(x), -1, 3) +plot(a) +plot(b) +plot(c) +plot(d)