% Generates Table 7.4

format short g

tol = 1e-11;
    
n = 200000; p = 2750159; 

AA = spdiags(primes(p)',0,n,n); e = ones(n,2);
for k = 2.^(0:floor(log2(n))), AA = AA + spdiags(e,[-k k],n,n); end
bb = sparse(n,1); bb(1) = 1;

table = []; kmax = 14;
for n = 20000*[1 10]
    table = [table; n];
    A = AA(1:n,1:n); b = bb(1:n);
    D=spdiags(diag(A),0,n,n);
    tic,
    [x,fail,r,k] = pcg(A,b,tol,kmax,D);
    t = toc;
    if not(fail),
        table = [table; t];
    end
    tic,
    m = 129; norm = 2;
    P = spdiags(diag(A),0,n,n); P(:,1:m) = A(:,1:m); M = inv(P);
    t = toc;
    table = [table; t];
    tic,
    [x,fail,r,k] = pri(A,b,tol,kmax,M,norm);
    t = toc;
    if not(fail),
        table = [table; t];
    end
end

table = reshape(table,4,2)'
    