function result = midpoint2(integrand, a, b, M, N)
% Like midpoint1, but uses M*N steps, and allows
% the user to choose a balance of speed against
% conservation of memory.
dx = (b - a)/M;
limits = a + (0:M)*dx;
result = 0;
for n = 1:M
   result = result + midpoint1(integrand, limits(n), limits(n+1), N);
end
