% 1st ord conv demo. taken from Math56 2014 lec1. Barnett 10/12/21

clear
format long g                      % makes show lots of (ie 16) digits
ns = 10.^[2:8];
for j=1:numel(ns), n=ns(j);
  s=0;
  for i=1:n, s = s+1/i^2; end
  disp([n, s])
  ss(j) = s;
end

y = pi^2/6;                        % exact, zeta(2)
figure;loglog(ns,abs(ss/y-1),'r+-');
hold on; loglog(ns,abs(ss/ss(end)-1),'b+-');
xlabel('$N$','interpreter','latex'); ylabel('est rel err $\varepsilon$','interpreter','latex');
axis([ns(1) ns(end-1) 4e-8 .006])
text(1e4,2e-4,'negative slope \approx 1 = order','rotation',-45);
text(4e3,3e-3,'Convergence plot $\varepsilon(N)$','interpreter','latex');
set(gcf,'paperposition',[0 0 3.3 3.5]);
print -dpng pisqsix.png

