% gauss4test05.m
% Script to test gauss4pts05.m, 
% the 4 point gauss-Legendre quadrature
% by using it compute the integral from 0 to 1
% of x^k, for k = 0, 1, ...
% K. Ming Leung

clear all; format long g;
a = 0; b = 1;
nMax = 16;
AbsError = ones(1,nMax);
for n=1:nMax
    k = n-1;
    integral = gauss4pts05('gauss4test05Fcn',a,b,k);
    exactAnswer = 1/n;
    AbsError(n) = abs(integral - exactAnswer);
end
plot(0:nMax-1,AbsError,'*');
xlabel('Order of Monomial');
ylabel('Absolute Error');
[ (0:nMax-1)' AbsError' ]

% RESULTS:
%
% Errors are practically equal to 0 for k = 0, 1, ..., 7
% This is expected since the Guass-Legendre quadrature is
% exact for polynomials of degree less than or equal to (2*N-1).
% For N=4 point formula, 2*4-1 = 7.
% After k = 7, the error grows with increasing k.
