function [ x, r ] = pow ( A, xold )
%
% function [ x, r ] = pow ( A, xold )
%
%  Discussion:
%
%    POW carries out one step of the power method.
%
%  Modified:
%
%    09 April 2000
%
%  Author:
%
%    John Burkardt
%
%  Parameters:
%
%    Input, real A(N,N), the matrix.
%
%    Input, real XOLD(N), an estimate for the eigenvector.
%
%    Output, real X(N), the value of A*xold, normalized to have unit L2 norm.
%
%    Output, real R, the Rayleigh estimate of the eigenvalue.
%
x = A * xold;
r = ( x' * A * x ) / ( x' * x );
x = x / norm ( x );
%
%  X and -X are both eigenvectors.  To make it easier to detect
%  convergence, pick the one whose maximum is positive.
%
x_max = max ( x );
if ( x_max < 0 )
  x = - x;
end

