% Compare error in numeric integration using Riemann sums and the trapezoid
% rule for various step sizes.

%% Set up the basic parameters of the comparison: function to use, bounds
% of integration, etc.
f = @(x)x^3;
a = 0;
b = 1;

area = 0.25;       

minN = 2;
maxN = 52;
deltaN = 2;
n = minN : deltaN : maxN;


%% Plot a reference line at the exact value of the integral
clf;
plot( [minN maxN], [area area], 'r' );
hold on;


%% Plot a series of Riemann approximations
r = [];
for i = n
    r = [ r riemann2( f, a, b, i ) ];
end

plot( n, r, 'bo' );


%% Plot a series of trapezoid approximations
t = [];
for i = n
    t = [ t trapezoid2( f, a, b, i ) ];
end

plot( n, t, 'gx' );
