a = 0; b = 1;
f = @(x) sin( 7/2 * x ) + exp( x ) - 1;
I_ex = exp( 1 ) - 2 + 2 / 7 * ( 1 - cos( 7 / 2 ) )
%  I_ex =
%    1.2716

[ Igl_n0 ] = gauss_legendre_simple_quadrature( f, a, b, 0 )
%  Igl_n0 =
%    1.6327
[ Igl_n1 ] = gauss_legendre_simple_quadrature( f, a, b, 1 )
%  Igl_n1 =
%    1.2409
[ Igl_n2 ] = gauss_legendre_simple_quadrature( f, a, b, 2 )	
%  Igl_n2 =
%    1.2724

% Note that to run lines 20 and 24, you should add the functions to the
% Matlab path, or run the lines from the folder where the functions are
% written. 
Is = simpson_composite_quadrature( f, a, b, 1 )
%  Is =
%    1.3164

It_c = trapezoidal_composite_quadrature( f, a, b, 10 )
%  It_c =
%    1.2673

f = @(x,d) x.^d;   a = 0;   b = 1;
Table = [ ];  % for visualization of the results
for d = [ 0 : 6 ]    
    I_ex = 1 / ( d + 1 );
    % Gauss-Legendre n=0,1,2
    Igl0 = gauss_legendre_simple_quadrature( @(x)f(x,d), a, b, 0 );    
    Igl1 = gauss_legendre_simple_quadrature( @(x)f(x,d), a, b, 1 );    
    Igl2 = gauss_legendre_simple_quadrature( @(x)f(x,d), a, b, 2 );    
    % Midpoint 
    Imp = ( b - a ) * f( ( a + b ) / 2, d );    
    % Trapezoidal
    It = ( b - a ) / 2 * ( f( a, d ) + f( b, d ) );    
    % Simpson
    Is = ( b - a ) / 6 * ( f( a, d ) + 4 * f( ( a + b ) / 2, d ) + f( b, d ) );    
    Table = [ Table; 
              [ d, abs( I_ex - Igl0 ), abs( I_ex - Igl1 ), abs( I_ex - Igl2 ), ...
                  abs( I_ex - Imp ), abs( I_ex - It ), abs( I_ex - Is ) ] ];
end
disp('d,     GL n0,     GL n1,     GL n2,      MidP,      Trap,      Simp')
disp(num2str(Table))

% d,      GL n0,      GL n1,      GL n2,       MidP,       Trap,       Simp
% 0           0           0           0           0           0           0
% 1           0           0           0           0           0           0
% 2    0.083333           0  5.5511e-17    0.083333     0.16667           0
% 3       0.125  2.7756e-17           0       0.125        0.25           0
% 4      0.1375   0.0055556           0      0.1375         0.3   0.0083333
% 5     0.13542    0.013889  2.7756e-17     0.13542     0.33333    0.020833
% 6     0.12723    0.022487  0.00035714     0.12723     0.35714    0.034226

