function [evector, evalue]=PowerIterationF(A,x,maxit,tol)
% Normalized power iteration for the dominant eigenvalue
% A is the n by n input square matrix
% x is the starting eigenvector (n by 1)
% maxit is the max number of iteration
% tol is the error tolerance
%K. Ming Leung, 01/11/03, Version 2: 09/02/04
[n,n] = size(A); rt = rand(1,n);
error = 1; it = 0; 
disp('       it                  m                   x');
while (it < maxit & error > tol)
    y = A*x;
    evalue = (rt*y)/(rt*x);
    x = y/evalue;
    out = [ it+1 evalue x']; disp(out);
    error = norm(A*x-evalue*x);
    it = it+1;
end
evector = x;
    
