function [lambda, x, conv] = mypower(A, x, tol, maxiter)
% MYPOWER find the largest in absolute value eigenvalue of matrix A
%         and the corresponding eigenvector
   x = x/norm(x);
   xn = A*x;
   lambdaold = x'*xn;
   x = xn/norm(xn);
   conv = [];
   iter = 1;
   rel = 2*tol;
   while (rel > tol) && (iter < maxiter)
       xn = A*x;
       lambda = x'*xn;
       rel = abs(lambda - lambdaold);
       lambdaold = lambda;
       conv = [conv rel];
       iter = iter + 1;
       x = xn/norm(xn);
   end
end
