%test pcg with different ichol preconditioners
clear
A = delsq(numgrid('S',400));
b = ones(size(A,1),1);
maxit=10000; tol=1e-6;
tic
[x0,fl0,rr0,it0,rv0] = pcg(A,b,tol,maxit);
toc

tic
L = ichol(A,struct('michol','on')); % modified incomplete Cholesky preconditioner.
[x2,fl2,rr2,it2,rv2] = pcg(A,b,tol,maxit,L,L');
toc

tic
L3 = ichol(A, struct('type','ict','droptol',1e-1));
[x3,fl3,rr3,it3,rv3] = pcg(A,b,tol,maxit,L3,L3');
toc

tic
L4 = ichol(A, struct('type','ict','droptol',1e-2));
[x4,fl4,rr4,it4,rv4] = pcg(A,b,tol,maxit,L4,L4');
toc

tic
L5 = ichol(A, struct('type','ict','droptol',1e-3));
[x5,fl5,rr5,it5,rv5] = pcg(A,b,tol,maxit,L5,L5');
toc

figure;
semilogy(0:it0,rv0/norm(b),'r-');
hold on;
semilogy(0:it2,rv2/norm(b),'r.');
semilogy(0:it3,rv3/norm(b),'b-.','linewidth',2);
semilogy(0:it4,rv4/norm(b),'b--','linewidth',2);
semilogy(0:it5,rv5/norm(b),'b:','linewidth',2);

legend('No Preconditioner','IC(0)','ICT(1e-1)','ICT(1e-2)', ...
'ICT(1e-3)','Location','Best');
xlabel('iteration number');
ylabel('relative residual norm');
hold off;