% Generates Table 7.1

nn = 2000*[1, 10, 100, 1000];
pp = [17389, 224737, 2750159, 32452843];

table = [];
for j=1:length(nn)
   n=nn(j); p=pp(j);
   tic; 
   A = spdiags(primes(p)',0,n,n); e = ones(n,2);
   for k = 2.^(0:floor(log2(n))), A = A + spdiags(e,[-k k],n,n); end
   t = toc;
   s = whos('A'); 
   table = [table; n t s.bytes/1024^2];
end

table