A=[5 1 3 0; 1 4.2 2 -1; 3 2 7 1; 0 -1 1 3];
b=[5;4;14;3];
% R=chol(A);
% y=R'\b;
% x=R\y;

x0=rand(4,1);
kmax=100;
tol=1.e-8;
[x,kk,err]=grad(A,b,x0,kmax,tol);

[x1,kk1,err1]=conjgra(A,b,x0,kmax,tol);

[x2,flag,relres,iter,resvec]=pcg(A,b,tol,kmax,[],[],x0);

figure(1)
semilogy(err,'r');
hold on
semilogy(err1,'b');
semilogy(resvec/norm(b),'g')
xlabel('k')
ylabel('err')
legend('gradient method','CG method','matlab pcg')

