% Session p. 157

session_p148

tol = 1e-11; kmax = 28;
D=spdiags(diag(A),0,n,n);
[x,fail,r,k] = pcg(A,b,tol,kmax,D);
if not(fail), k, x1 = x(1), err = r/x1, end