function [x,residues] = CGk(A,b,x,tolerance,k) n=length(b); residues=zeros(n+1,1); P=zeros(n,n); r=b-A*x; residues(1,1)=r'*r; for i=1:n somme=zeros(n,1); for j=i-1:-1:i-k%projection sur k directions anterieures if(j>=1) pj=P(:,j); somme=somme+r'*A*pj/(pj'*A*pj)*pj; else break; end end p=r-somme; P(:,i)=p; %alpha=p'*b/(p'*A*p); alpha=p'*r/(p'*A*p); x=x+alpha*p; r=b-A*x; residues(i+1,1)=sqrt(r'*r); if(residues(i+1,1)