%MATLAB version of the script for example 7.7 on pages 326f of conte/deboor
% example 7.7  Composite Four-Point Gauss Legendre.
%
%  Reference:
%
%    Samuel Conte, Carl de Boor,
%    Elementary Numerical Analysis,
%    Third Edition,
%    SIAM, 2017,
%    ISBN: 978-1-611975-19-2.
%
F = @(x) sin(x).^2./x;
disp('Example 7.7: Composite Four-Point Gauss Legendre')
disp('   N         I(DP)            ERROR(DP)')

A = 1; B = 3;  NP = 4;
gausleg = LGNDRE(NP); 
for N=2:3
  H2 = (B-A)/(2*N); MP = A + H2.*(1:2:(2*N-1));
  value =  ...
  H2*sum(gausleg.weights*F(repmat(MP,NP,1)+repmat(gausleg.points(:)*H2,1,N)));
  error = 7.948251806691e-01-value;
  fprintf('  %2d   %15.7e  %15.3e\n', [N,value,error])
end
