function [x,se]  = invhatv(A,x0,N)
n=max(size(x0));
if x0 == zeros(n,1), 
        x0(1)=1; 
end;
if det(A) == 0, 
       SA=A+2.01*eye(n,n);
       szing=1;
else SA=A;
     szing=0;
end;
x=x0/norm(x0);
  for j=1:N, xs=inv(SA)*x;
      if SA == SA',
          se=(x'*xs)/(x'*x);
      else  
         [m,k]=max(abs(x));
            se=xs(k)/x(k);
      end;
      x=xs/norm(xs);
  end;
se=1/se;
if szing == 1, se=se-2.01; end;
