Write a procedure approxInt that takes in a function f, a number of intervals
N, a left endpoint a, and a right endpoint b. Given these data, the procedure should split the
interval [a, b] into N subintervals and use the function f to estimate the area under the curve
using
(a) Left endpoints,
(b) Right endpoints,
(c) Midpoints, and
(d) Trapezoids.
Write another procedure called compareApproxInt that does the following:
(a) Takes as inputs the function f, the endpoints a and b, and the number of subintervals N.
(b) Calls the procedure approxInt in order to estimate the area under the curve of f(x) with
N subintervals, with the four different approximations methods.
(c) Returns four sentences:
Using , the approximate area under f is . This method has a margin of error of .
Test compareApproxInt with the functions
f1(x) = x
f2(x) = x^2 ,
f3(x) = x^3 - 4 · x^2 , and
f4(x) = e^x ,
each on the interval [-1, 1], with 10 subintervals.