Riemann Sums:
A Symbolic and Graphical Approach

This Maple worksheet allows investigation of the definite integral of y = f(x) on [a,b] as a limit of Riemann Sums from a symbolic and graphical point of view. The Riemann sums for the right and left hand endpoints are computed and the convergence to the common limit is illustrated using an animation.

The approach taken in this worksheet is to define the Riemann sums as functions of the increment in x and plot the Riemann sums as a function of the increment. As the increment approaches 0, the Riemann sums approach a common limit.

Change the function, f(x), interval [a,b] by re-defining. Enter each command, select the graphics box and use the animation tools in the toolbar. The number of frames in the animation may be changed by changing the value of numframes.

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

Warning, the name changecoords has been redefined

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

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

> a:=0;b:=2;

a := 0

b := 2

> LS :=leftsum(f, x=a..b, n);

LS := 2*Sum(f,i = 0 .. n-1)/n

> n:=(b-a)/deltax;

n := 2*1/deltax

> LHE:=expand(value(LS));

LHE := 2*f

Define the left hand endpoint function.

> lefthand:=t->-218/15+39*t-35/3*t^2+1/5*t^4;

lefthand := proc (t) options operator, arrow; -218/...

> leftplot:=plot(lefthand(deltax),deltax=-1..1,color=blue,thickness=3):

> unassign('n');

> RS := rightsum(f, x=a..b, n);

RS := 2*Sum(f,i = 1 .. n)/n

> n:=(b-a)/deltax;

n := 2*1/deltax

> RHE:=expand(value(RS));

RHE := 2*f

Define the right hand sum function.

> righthand:=t->-218/15-39*t-35/3*t^2+1/5*t^4;

righthand := proc (t) options operator, arrow; -218...

> rightplot:=plot(righthand(deltax),deltax=-1..1,color=red,thickness=3):

> display(leftplot,rightplot);

[Maple Plot]

Set up the animation. For a left approach use h:=k->-((1-a)-(1-a)*k/numframes);

> numframes:=50;

numframes := 50

> h:=k->(1-a)-(1-a)*k/numframes;

h := proc (k) options operator, arrow; 1-a-(1-a)*k/...

> plot_animate:=[seq(plot([righthand(deltax),
                        [[h(k),righthand(h(k))]],lefthand(deltax),
                        [[h(k),lefthand(h(k))]]],deltax=-1..1,
                        y=-70..20,color=[red,red,blue,blue],
                        style=[line,point,line,point],
                        symbol=circle,symbolsize=20,thickness=3),
                        k=0..numframes-1)]:

> display(plot_animate,insequence=true);

[Maple Plot]

We now construct a more general Riemann sum where the points at which the function is evaluated are chosen in a consistent manner.

> unassign('n');

> rs:=(deltax,s)->expand(value(sum(f(a+(m-s)*deltax)*deltax,m=1..n)));

rs := proc (deltax, s) options operator, arrow; exp...

> n:=(b-a)/deltax;

n := 2*1/deltax

> rs(deltax,1/2);

-218/15-7/40*deltax^4+35/6*deltax^2

> mp:=t->-218/15+35/6*t^2-7/40*t^4;

mp := proc (t) options operator, arrow; -218/15+35/...

> mpplot:=plot(mp(deltax),deltax=-1..1,color=green,thickness=3):

Define the trapezoid approximation.

> trap:=t->1/2*(lefthand(t)+righthand(t));

trap := proc (t) options operator, arrow; 1/2*lefth...

> trapplot:=plot(trap(deltax),deltax=-1..1,color=yellow,thickness=3):

Plot right hand, left hand, midpoint, and trapezoid approximations concurrently, then animate the motion of a point on each of the graphs. For a left-hand approach, use h:=k->-((1-a)-(1-a)*k/numframes) ;

> display(leftplot,rightplot,mpplot,trapplot);

[Maple Plot]

> plot_animate2:=[seq(plot([righthand(deltax),
                          [[h(k),righthand(h(k))]],lefthand(deltax),
                          [[h(k),lefthand(h(k))]],mp(deltax),
                          [[h(k),mp(h(k))]],trap(deltax),
                          [[h(k),trap(h(k))]]],deltax=-1..1,
                          y=-70..20,
                          color=[red,red,blue,blue,green,green,yellow,yellow],
                          style=[line,point,line,point,line,point,line,point],
                          symbol=circle,symbolsize=20,thickness=3),
                          k=0..numframes-1)]:

> display(plot_animate2,insequence=true);

[Maple Plot]

Another approximation is Simpson's Rule.

> simp:=t->1/3*(2*mp(t)+trap(t));

simp := proc (t) options operator, arrow; 2/3*mp(t)...

> simp_plot:=plot(simp(deltax),deltax=-1..1,color=black,thickness=3):

> display(mpplot,trapplot,rightplot,leftplot,simp_plot);

[Maple Plot]

This Maple 6 worksheet was based on the ideas discussed in
"Symbolic and Graphical Investigations of Riemann Sums with a Computer Algebra System",
PRIMUS , VI, No.4 (December 1996), 366-380 by Dr. Lawrence H. Riddle from Agnes Scott College.

The Maple 6 worksheet was developed by
Lila F. Roberts
Department of Mathematics and Computer Science
Georgia College & State University
Milledgeville, GA  31061
lila.roberts@gcsu.edu