L24-riemannSum.mws

Calculus I

Lesson 24: Riemann Sums

Approximating an Area with Rectangles

Consider the area under the curve f(x) = x^3-5*x^2+x+10 on the interval [-1, 4].

> restart;

> f:=x->x^3-5*x^2+x+10;

f := proc (x) options operator, arrow; x^3-5*x^2+x+...

> plot(f(x), x=-1..4);

[Maple Plot]

How might we find the net area under this graph? If it were drawn on graph paper, we could get an approximation to the net area by counting the number of rectangles (and parts of rectangles) under the graph that are above the axis, and subtracting the number that are below the axis . The calculus approach begins with a variant of this simple idea: we approximate the required area by rectangles. More explicitly, we divide the interval [-1, 4] into some number of equal sub-intervals, and then draw a rectangle over each sub-interval whose height is the height of the graph at the right-hand endpoint of the sub-interval. We can draw the rectangles by taking advantage of Maple's rightbox command, which is in the student package.

> with(student);

[D, Diff, Doubleint, Int, Limit, Lineint, Product, ...
[D, Diff, Doubleint, Int, Limit, Lineint, Product, ...

> rightbox(f(x), x=-1..4, 6);

[Maple Plot]

In this example, we used 6 sub-intervals. (That's what the last argument in the rightbox command is for.) We can add up the areas of the 6 rectangles easily enough (note that each rectangle has base 6/5):

> evalf( 1*f(-1) + 1*f(0) + 1*f(1) + 1*f(2) + 1*f(3) + 1*f(4) );

13.

and we can save typing by using the sum command:

> evalf( sum(1*f(-2 + k), k=1..6) );

13.

but it is not likely that this computation by itself will give a very good approximation to the area under the graph. To get a better approximation, we could try using more rectangles. Here are the picture and the sum with 12 rectangles (each of which will then have base length 12/5):

> rightbox(f, x=-1..4, 12);

[Maple Plot]

> sum((1/2)*f(0 + k*(1/2)), k=1..12);

107/2

It seems reasonable that if we take enough rectangles, we can make their total area as close as we want to the true area under the graph. (It will be easier to compare the numerical answers if we use evalf on the sums.)

> rightbox(f(x), x=-1..4, 25);

[Maple Plot]

> evalf(sum((6/25)*f(-2 + k*(6/25)), k=1..25));

8.044800000

> rightbox(f(x), x=-1..4, 50);

[Maple Plot]

> evalf(sum((6/50)*f(-2 + k*(6/50)), k=1..50));

7.051200000

> rightbox(f(x), x=-1..4, 100);

[Maple Plot]

> evalf(sum((6/100)*f(-2 + k*(6/100)), k=1..100));

6.532800000

Here's an animation showing the convergence of a Riemann sum to the area under the curve

> animateRiemann := proc (f, a, b)
local i, Lb;
for i from 2 to 33 do
Lb[i]:=student[rightbox](f, x=a..b, 3*i):
end do:
plots[display]([seq(Lb[i], i=2..33)],insequence=true);
end proc:

> animateRiemann(f, -1, 4);

[Maple Plot]