% Script File: ShowCompQNC
% Illustrates composite Newton-Cotes rules on three different
% integrands.

% Show QNC(m,n) errors for integral of sin from 0 to pi/2.
close all
figure
for m = [ 3 5 7]
   % m-point rule used.
   err = [];
   for n = [1 2 4 8 16 32 64]
      % n = number of subintervals.
      err = [err  abs(compQNC('cos',0,pi/2,m,n) -1)+eps];
   end
   semilogy([1 2 4 8 16 32 64],err)
   axis([0 70 10^(-17) 10^0])
   text(33,err(6),sprintf('m = %1.0f',m))
   hold on
end
title('Example 1.   QNC(m,n) error for integral of cos from 0 to pi/2')
xlabel('n = number of subintervals.')
ylabel('Error in QNC(m,n)')

% Show QNC(m,n) errors for integral of sqrt from 0 to 1.
figure
for m = [ 3 5 7]
   % m-point rule used.
   err = [];
   for n = [1 2 4 8 16 32 64]
      % n = number of subintervals.
      err = [err abs(compQNC('humps',0,3,m,n) - (23.9680798400577))+eps];
   end
   semilogy([1 2 4 8 16 32 64],err)
   axis([0 70 10^(-9) 10^(0)])
   text(33,err(6),sprintf('m = %1.0f',m))
   hold on
end
title('Example 2.   QNC(m,n) error for integral of humps from 0 to 1')
xlabel('n = number of subintervals.')
ylabel('Error in QNC(m,n)')


