% Test of FFT quadrature
function test1
mmax = 40;
for m=1:mmax
   N(m)=round(2^((m-1)/2));
   err1(m) = fint(@periodic1, 0, pi, N(m)) - 1;
   err2(m) = fint(@periodic2, 0, pi, N(m)) - 1;
   err2b(m) = midpoint1(@periodic2, 0, pi, N(m)) - 1;
   err3(m) = fint(@periodic3, 0, pi, N(m)) - 1;
end

figure(1)
loglog(N, abs(err1) + eps/10, 'b-+',...
       N, abs(err2) + eps/10, 'g-o',...
       N, abs(err2b) + eps/10, 'g--',...
       N, abs(err3) + eps/10, 'm-^',...
       N, N.^(-4),            'k--',...
       [N(1), N(mmax)], [eps/10, eps/10], 'r:' )
ylim([1e-17,1])
title('Convergence of FFT quadrature of periodic integrands',...
   'fontsize',18)
xlabel('Number of function evaluations','fontsize',16)
ylabel('absolute value fractional error + eps/10','fontsize',16)
legend( 'sin^4x',...
        '1/[2 + cos(2x)]',...
        '1/[2 + cos(2x)] (midpoint)',...
        '[x(π - x)]^2',...
        'err = 1/N^4',...
        'zero error (plotted as eps/10)' )
hold off

