% area_under_sine_grid.m
%
%  Estimate the area between the x axis and the curve y=sin(x) for 0<=x<=2 pi.
%
%  Use a Left Riemann sum.
%
n = input ( '  Enter the number of intervals to use: ' );

area = 0.0;
width = 2 * pi / n;

for i = 1 : n
  x = 2 * pi * ( i - 1 ) / n;
  y = sin ( x );
  area_strip = width * y;
  area = area + area_strip;
end

fprintf ( '  Estimated area under y=sin(x) is %g\n', area );
fprintf ( '  Exact area is %g\n', 0.0 );

