]> ApproximateInt.html

Using Maple to compute integral approximations

The first thing to say, of course, is that you will be expected to know how to compute LHS, RHS, TRAP, and MPS sums.  Don't worry too much about memorizing how to compute the sums using simpson's method.  So if you use the helps that follow, also be aware of how to do it by hand.

In what follows, I explain things in this sort of font.  Bold red things are the commands typed into Maple, and the blue stuff is the things that Maple prints out.

First, we need to load some add-on packages (the same ones we used back when we were doing Newton's method)

 > with(Student[Calculus1]);   We will use the "ApproximateInt" function to approximate integrals.  For the first example, we'll approximate the function x^2 ("x squared") on the interval [0,4].  To do this, go to a prompt (a line that begins with ">", and type:

 > ApproximateInt(x^2,x=0..4); (notice we end each line with a semicolon).  Well, that's great.  By default, ApproximateInt calculuates the midpoint sum with 10 subintervals MPS(10), and returns the answer.  It would be nice if Maple would plot out the function and help us understand better what was going on.  We do this by sticking a "output=plot" at the end.

 > ApproximateInt(x^2,x=0..4,output=plot); Much better!  The "Approximate Value" above the graph is the actual area under the curve, while the "Area" under the graph is the area of the rectangles that we calculute (i.e., in this case, MPS(10)=21.28).

There are, of course, more options we can change (I sure hope so, otherwise this homework is going to be horrendous to do! :)  To change the method of approximation, (to, say, the left sum LHS(10), just type "method=left"):

 > ApproximateInt(x^2,x=0..4,output=plot,method=left); For the method, we can use left, right, midpoint, trapezoid, simpson, upper, lower, random, and a few others we won't list here.  For instance, to calculate using the trapezoid sum, we type

 > ApproximateInt(x^2,x=0..4,output=plot,method=trapezoid); Isn't that beautiful?  And you can see the area we came up is much closer to the area under the curve.  Of course, like we discussed in class, using simpson's rule will give the exact value because the function is a parabola

 > ApproximateInt(x^2,x=0..4,output=plot,method=simpson); So now, what if we want to change the number of subintervals?  Piece of cake :).  Just put a "partition=blah" in there (except, replace the blah with the number of partitions you want).  So to calculuate RHS(50), just type

 > ApproximateInt(x^2,x=0..4,output=plot,method=right,partition=50); Yep, it sure looks like a lot of intervals!  And you can see that the area is much closer to the value of the integral as well.

There are many more options, which you can see by typing "?ApproximateInt;".  We'll finish up with one more example, though.

Remember that exponential function we put down in class, e^(-x^2)?  Let's approximate it in several ways.  To type the exponential function, we say exp(-x^2)

 > ApproximateInt(exp(-x^2),x=-2..2,method=midpoint,output=plot,partition=10); Using trapezoid, we get a little closer area

 > ApproximateInt(exp(-x^2),x=-2..2,output=plot,method=trapezoid,partition=10); Using Simpson's method, we will get even better, but still not exact.

 > ApproximateInt(exp(-x^2),x=-2..2,output=plot,method=simpson,partition=10); It was pretty close, though!  If we increase the number of subintervals, we'll get closer, though.

 > ApproximateInt(exp(-x^2),x=-2..2,output=plot,method=simpson,partition=50); If you have any questions, come talk and we'll figure it out.  Have a wonderful day!