function [x,iter]=grad(A,b,toll,nmax)
[n,n]=size(A)
iter=0; r=b; r0=norm(r); err=r0; x=zeros(n,1); 
while err>toll & iter<nmax
iter=iter+1;
alpha=(r'*r)/(r'*A*r);
x=x+alpha*r;
r=b-A*x;
err=norm(r)/r0;
end;
