# This procedure evaluates an integral numerically, using an approximation
# based on a grid of 'n' rectangles, with heights given by the function value
# at the midpoint of their base. The parameters are an expression defining
# the function to integrate, the unknown variable in this expression, the
# range over which to integrate, and the number of rectangles to use. The
# computations are done using floating point arithmetic.
#
# If the expression defining the function contains a call of a procedure,
# it will probably be necessary to put in in single-quotes (') to prevent
# immediate evaluation.
#
# Example: intrect (x^2, x, 0..1, 100) should return about 1/3.
intrect := proc(f,x,rng,n)
local low, high, sum, i, h;
if not type(rng,range) then
ERROR(`Third operand must be a range`);
fi;
low := evalf(op(1,rng));
high := evalf(op(2,rng));
if high