function [i,x]=gradient(N)
I=speye(N,N);
diag = 2*I;
subd=-sparse(2:N,1:N-1,1,N,N);
A=diag+subd+subd';
b=ones(N,1);
x=zeros(N,1);
for i=1:100000
  r=b-A*x; 
  step=dot(r,r)/dot(r,A*r);
  x=x+step*r;
  if (norm(r)<1.e-6)
    break
  end
end

