%
% Power method to find the dominant eigenvalue and eigenvector
%
function [lambda,v]=powerM(A,u,epsilon,maxnum)
% Initialize parameters;
lambda=0.0;
err=1.0;
count=1;
state=1;
while ((count<maxnum) && (state==1))
  z=A*u;
  [tmax k]=max(abs(z)); 
  z=z/tmax;
  dlambda=abs(lambda-tmax);
  dvector=norm(z-u,inf);
  err=max(dlambda,dvector);
  u=z;
  lambda=tmax;
  state=0;
  if (err > epsilon)
    state=1;
  end 
  count=count+1;
end
lambda=tmax;
v=u/norm(u,2);
