tol=0.0001
total=0;
% maximum number of terms we would evwer want to do
imax=100000;
for i=1:imax
    term=1/i^2;
    estimatedError=abs(term)*i;
    if estimatedError <= tol
        fprintf('Stopped summing after %i terms.\n',i-1)
        break
    end
    total=total+term;
end
sum=total
sumErr=total-pi^2/6
