Application Center - Maplesoft

App Preview:

Defining double integrals - Riemann Sums

You can switch back to the summary page by clicking here.

Learn about Maple
Download Application



Defining double integrals - Riemann Sums

Worksheet by Mike May, S. J.-

Section 15.1

Riemann sums in two variable

> restart; with(plottools): with(plots): with(student):

Warning, the name changecoords has been redefined

This worksheet uses commands from a number of packages. The line above loads those packages and has to be run before the examples will work. Following our pattern in this course we approach a topic in multivariable calculs by reviewing the topic in single variable calculus.

Reviewing Riemann sums for functions of one variable

Recall that for a function f(x) of one variable, the integral from x=a to x=b was defined as the limit as n approaches infinity of the sum obtained by cutting the region from a to b into n subintervals, then approximating the function on each subinterval by a constant function. In loose terms we approximated the region by rectangles and took the limit as we used more and more rectangles.

Example 1:

We would like to use Riemann sums to approximate int(x^3-x,x = -1 .. 3) .

The visual approach:

We would obviously like to plot the curve and the approximating rectangles. We start with 7 subintervals.

> lowx := -1: highx :=2: xdivs :=7:
f := x -> x^3-x:
delx := (highx-lowx)/xdivs:
plotter :={plot(f(x),x=lowx..highx, color=blue)}:
for i from 1 to xdivs do
plotter := plotter union {rectangle([lowx+(i-1)*delx, 0],
[lowx+i*delx, f(lowx+i*delx)],color=red)}:
plots[display](plotter, axes=boxed);

[Maple Plot]

If we increase the number of subintervals we get a very good approximation.

The numeric approach:

The picture above uses a right hand rule for evaluating the sum. We can have Maple compute this sum for us. It serves our interests to first formally compute the sum, then to evaluate it, and finally to convert to a decimal value.

> lowx := -1: highx :=2: xdivs :=7:
f := x -> x^3-x:
sum1 := rightsum(f(x), x=lowx..highx,xdivs);
sum2 := value(sum1);
sum3 := evalf(sum2);

sum1 := 3/7*Sum((-1+3/7*j)^3+1-3/7*j,j = 1 .. 7)

sum2 := 180/49

sum3 := 3.673469388

If we want a better approximation, we can look at the value we obtain this way with a large number of subintervals.

> `sum500` = evalf(value(rightsum(f(x), x=lowx..highx,500)));

sum500 = 2.268027000

We can also set up the sum for an arbitrary number of subintervals and then take the limit as the number of subintervals approaches infinity.

> sum2arbn := value(rightsum(f(x), x=lowx..highx,n));
sum3inf := limit(sum2arbn,n=infinity);

sum2arbn := 3*(3*(n+1)^2/n-3*(n+1)/n-9*(n+1)^3/(n^2...

sum3inf := 9/4


We compare this with the result obtained through symbolic integration and see that they are the same.

> Int(f(x),x) = int(f(x),x);
Int(f(x), x=-1..2) = int(f(x), x=-1..2);
Int(f(x), x=-1..2) = evalf(int(f(x), x=-1..2));

Int(x^3-x,x) = 1/4*x^4-1/2*x^2

Int(x^3-x,x = -1 .. 2) = 9/4

Int(x^3-x,x = -1 .. 2) = 2.250000000


1) The Riemann sum definition of integral is most useful when we are either trying to decide which interval is appropriate in a problem or when we are trying to evaluate an integral that we cannot do symbolically. Approximate Int(sin(x^4)/x^2, x=0..1) by using Riemann sums with 100 subintervals. (Even Maple cannot antidifferentiate this function automatically.)


Generalizing to functions of 2 variables:

To make computations and the Maple programming easier, we will restrict to the case where the region of integration is a rectangle. When we try to take subintervals we now want to break up both the x interval and the y interval. That means we will be adding little boxes with rectangular bases and the height determined by evaluating the function at some point in the subregions. We would like to be able to visualize how the boxes approximate the region and also be able to find the value of the approximation.

Example 2:

We will look at example 3 from the text and look at the approximations to the volume under the surface obtained by graphing g(x,y) = 2-x^2-y^2 with x and y between -1 and 1. Simbolically we are looking to evaluate int(int(2-x^2-y^2,y = -1 .. 1),x = -1 .. 1) .

The Visual Approach:

We will start with 7 subintervals in x and 5 intervals in y. We want to see a plot of the surface, a plot of the approximating Riemann sum, and a plot of the two together.

> lowx := -1: highx :=1:
lowy := -1: highy :=1:
xdivs :=7: ydivs :=5:
g := (x,y) -> 2 - x^2 - y^2:
delx := (highx-lowx)/xdivs: dely := (highy-lowy)/ydivs:
plot3d(g(x,y),x=lowx..highx, y=lowy..highy,
color=blue, style=patch, axes=boxed);
surf :=plot3d(g(x,y),x=lowx..highx, y=lowy..highy,
color=blue, style=patch):
plotter :={}:
for i from 1 to xdivs do
for j from 1 to ydivs do
plotter := plotter union
{cuboid([lowx+(i-1)*delx, lowy+(j-1)*dely, 0],
[lowx+i*delx, lowy+j*dely, g(lowx+i*delx, lowy+j*dely)],
display3d(plotter, axes=boxed, style=patch);
display3d(plotter union {surf}, axes=boxed, style=patch);

[Maple Plot]

[Maple Plot]

[Maple Plot]

Once again we get a better approximation by increasing the number of subintervals. It should be noted however that if we do 100 subintervals for x and for y, then we have to compute 10,000 boxes.

The Numaric Approach:

Once again we will mimic what we did with a function of one variable. We start by evaluating with a small number of subintervals.

> lowx := -1: highx :=1:
lowy := -1: highy :=1:
xdivs :=7: ydivs :=5:
g := (x,y) -> 2 - x^2 - y^2:
delx := (highx-lowx)/xdivs: dely := (highy-lowy)/ydivs:
sum1 := rightsum(rightsum(g(x, y), x=lowx..highx,xdivs),
y = lowy..highy,ydivs);
sum2 := value(sum1);
sum3 := evalf(sum2);

sum1 := 2/5*Sum(2/7*Sum(2-(-1+2/7*i1)^2-(-1+2/5*i2)...

sum2 := 6336/1225

sum3 := 5.172244898

(Note that version 5 picks wierd names for the indices of a double summation. The names look like numbers.)

Next we look at the value we obtain this way with a large number of subintervals. We also take the limit as the number of subintervals approaches infinity.

> `approx100` := evalf(value(rightsum(value(rightsum(g(x,y),
x=lowx..highx,100)), y = lowy..highy,100)));
sum2arbmn := value(student[leftsum](value(student[leftsum]
(g(x,y), x=lowx..highx,n)), y = lowy..highy,m));
sum3a := limit(limit(sum2arbmn,n=infinity),m=infinity);
`limitinfinity` = evalf(sum3a);

approx100 := 5.332800000

sum2arbmn := 2*(8/3*m-4/3*m/(n^2)-4/3*1/m)/m

sum3a := 16/3

limitinfinity = 5.333333333

Finally we compare with the result of symbolic integration and see that they are the same.

> Int(Int(g(x,y),y=-1..1),x=-1..1) = int(int(g(x,y),y=-1..1),x=-1..1);
Int(Int(g(x,y),y=-1..1),x=-1..1) = evalf(int(int(g(x,y),y=-1..1),x=-1..1));

Int(Int(2-x^2-y^2,y = -1 .. 1),x = -1 .. 1) = 16/3

Int(Int(2-x^2-y^2,y = -1 .. 1),x = -1 .. 1) = 5.333...


2) Let R be the region with x in [1, 2] and y in [1, 3] . Estimate the integral of x^2+y^2 over R by evaluating a Riemann sum with 10 subintervals in each of x and y. (This is problem 7 in section 15.1.)



3) Let R be the region with x in [-Pi, 0] and y in [0, Pi/2] . Estimate the integral of sin(x*y) over R by evaluating a Riemann sum with 10 subintervals in each of x and y. (This is problem 8 in section 15.1.)