# Fred Adler, 1/21/94

# A couple of routine to compute the left hand and right hand estimates of
# an integral using Riemann sums.  Each has arguments (f,n,a,b), respectively
# the function to be integrated, the number of steps, the lower limit and
# the upper limit.  riemannl uses the value of the function at the left
# end of the interval, and riemannr uses the value of the function at the 
# right end of the interval.  The routines routine the value of the Riemann
# sum.  Trapezoid rule can be recovered as the average of riemannl and 
# riemannr.

riemannl := proc(f,n,a,b)
  local val,value,i,xup,step;
  step := (b-a)/n ;
  xup := a ;
  val := 0.0 ;
  for i from 0 to n-1 do
    val := val + step*f(xup) ;
    xup := xup + step ;
  od;
  value := evalf(val);
  RETURN(value);
end:
 
riemannr := proc(f,n,a,b)
  local val,value,i,xup,step;
  step := (b-a)/n ;
  xup := a ;
  val := 0.0 ;
  for i from 1 to n do
    xup := xup + step ;
    val := val + step*f(xup) ;
  od;
  value := evalf(val);
  RETURN(value);
end:

