function area = riemann2( f, a, b, n )
%RIEMANN2 Integrate f from a to b as a Riemann sum of n rectangles.
% (Uses left rectangles, but that doesn't really matter.)


% Set up x and f(x) values, without assuming that f vectorizes.

x = linspace( a, b, n+1 );

y = [];
for i = 1 : n
    y(i) = f( x(i) );
end


% Calculate the area under the curve.

deltaX = ( b - a ) / n;
area = sum( deltaX * y );

end