%pi_estimate uses quadtx to estimate the value of pi through the integral
%2/(1+x^2)

f=inline('2/(1+x^2)');
fcountes
subplot(311);ezplot(f,-1.5,1.5);
Qexact=pi;
disp('  tol                 Q            fcount    error        error/tol');
for k=1:12  
        
    tol=10^(-k);
    tolvector(k)=10^(-k);
    [Q,fcount]=quadtx(f,-1,1,tol);
    error(k)=Q-Qexact;
    ratio=error(k)/tol;
    fcountvector(k)=fcount;
    fprintf('%8.0e %21.14f %7d %13.3e %9.3f\n',tol,Q,fcount,error(k),ratio);
end
end

subplot(312);semilogx(tolvector,fcountvector,'*');
ylabel('fcount');xlabel('tol');
hold on; ezplot(
subplot(313);loglog(tolvector,error,'o');
ylabel('Error (Q-Pi)');xlabel('tol');