function ShowPCG()
% Illustrates pcg with various incomplete cholesky preconditioners
close all

% Generate an example...
A = delsq(numgrid('C',100));
[n,n] = size(A);
b = randn(n,1);

% Maximum number of iterations...
itMax = 100;
% Stop if || Ax - b||/||b| <= tol
tol = .00000000001;

% No preconditioner...
G = speye(n);
[x,flag,relres,itLast,resVec] = pcg(A,b,tol,itMax,G,G');
h(1) = semilogy((1:length(resVec))',resVec,'k');

hold on
% Incomplete Cholesky with no fill in...
G = cholinc(A,'0')';
[x,flag,relres,itLast,resVec] = pcg(A,b,tol,itMax,G,G');
h(2) = semilogy((1:length(resVec))',resVec,'r');

% Incompolete Cholesky with drop tolerance = .001
G = cholinc(A,.001)';
[x,flag,relres,itLast,resVec] = pcg(A,b,tol,itMax,G,G');
h(3) = semilogy((1:length(resVec))',resVec,'b');

title(sprintf('PCG with Various Preconditioners n = %1d',n),'fontsize',14)
legend(h,'G = I','G = cholinc(A,''0'')','G = cholinc(A,.001)','location','best')
hold off
xlabel('Iterations','fontsize',14)
ylabel('|| A*xk - b || / || b ||','fontsize',14)
shg