function[x]=cg_123(A,b,x0)
max_iter=5000;
epsilon=1e-8;
x=x0;
i=0;
r=b-A*x;
d=r;
delta_new=r'*r;
delta0=delta_new;
while(i<max_iter)&&(delta_new/delta0>epsilon^2)
q=A*d;
alpha=delta_new/(d'*q);
x=x+alpha*d;
r=b-A*x;
delta_old=delta_new;
delta_new=r'*r;
beta=delta_new/delta_old;
d=r+beta*d;
i=i+1;
end