% generates Figure 3.2

close all
clear all
f=inline('z^(-4)','z');
Z=inline('1/2-i*t/2','t');
dZ = inline('-i/2','t');
F_Summation = inline('real(f(Z(t))*cot(pi*Z(t))*dZ(t)/2/i)','t','f','Z','dZ');

h1 = 1./(1:0.05:6);
s1 = zeros(size(h1));
k1 = zeros(size(h1));

for j=1:length(h1);
    [s1(j),k1(j)]=TrapezoidalSum(F_Summation,h1(j),1e-16,1,'yes',f,Z,dZ);
end

h2 = 1./(1:0.05:9);
s2 = zeros(size(h2));
k2 = zeros(size(h2));

for j=1:length(h2);
    [s2(j),k2(j)]=TrapezoidalSum(F_Summation,h2(j),1e-16,2,'yes',f,Z,dZ);
end

figure(1);
err1 = abs(s1-pi^4/90);
semilogy(1./h1,err1,'b-.','LineWidth',2);
set(gca,'FontSize',18,'FontWeight','normal','FontName','Times');
hold on;

err2 = abs(s2-pi^4/90);
semilogy(1./h2,err2,'g-','LineWidth',2)
axis([1 9 10^-15 10^1]);
xlabel('{\ith}^{-1}','FontWeight','normal','FontSize',24);
ylabel('Error','FontWeight','normal','FontSize',24);

figure(2)
semilogy(k1,err1,'b-.','LineWidth',2);
set(gca,'FontSize',18,'FontWeight','normal','FontName','Times');
hold on
semilogy(k2,err2,'g-','LineWidth',2)
axis([1 130 10^-15 10^1]);
xlabel('Number of terms','FontWeight','normal','FontSize',24);
ylabel('Error','FontWeight','normal','FontSize',24);

