function [evector, evalue]=PowerRayQuotF(A,x,maxit,tol)

% Normalized power iteration for the dominant eigenvalue
% by computing the Rayleigh quotient
% 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/12/03

[n,n]=size(A);
error=1; it=0;
disp(' it eigenvalue eigenvector');
while (it < maxit & error > tol)
y=A*x;
evalue=x'*y/(x'*x); % eigenvalue using the Rayleigh quotient
[maxabsy,maxidx]=max(abs(y)); % find element with the largest magnitude
x=y/y(maxidx); % scale the vector
out=[ it+1 evalue x']; disp(out);
error=norm(A*x-evalue*x); % an expensive way to compute the error
it=it+1;
end
evector=x;