function [l,y,n]=potinv2(A,x0,toll,nmax)
  [L,U,P]=lu(A);
  x=x0;
  y=x/norm(x);
  z=L\P*y;
  x=U\z;
  m_old=y'*x;
  y=x/norm(x);
  n=0;
  do
  z=L\P*y;
  x=U\z;
  m=y'*x;
  y=x/norm(x);
  err=abs(m-m_old)/abs(m_old);
  m_old=m;
  n=n+1;
  until (n>nmax | err < toll)
  l=1/m;
  
