function [x,nit,er,res]=richardson(A,b,toll,nmax,P,alpha)
  if nargin < 5
    P=eye(length(A));
  end
  x=zeros(size(b));
  nit=0;
  er='';
  r=b-A*x;
  res=norm(r);
  C=norm(b);
  tollC=C*toll;
  if nargin <6
    preA=P\A;
    lmax=max(abs(eig(preA)));
    lmin=min(abs(eig(preA)));
    alpha=2/(lmax+lmin);
  end       
  while nit < nmax & res > tollC
    nit=nit+1;
    z=P\r;
    x=x+alpha*z;
    r=r-alpha*A*z;
    res=norm(r);
  end
  if res > tollC | isnan(res)
    er='Test di arresto non soddisfato';
  end
