function lambda = powermethod(A, xinitial, niters) % POWERMETHOD : Power method to estimate norm of dominant eigenvalue % % lambda = powermethod(A, xinitial, niters); % % This routine takes matrix A and vector xinitial, and repeatedly % multiplies the matrix by the vector and normalizes the result % to have length 1. % If the dominant eigenvalue of A is simple, the vector converges % to the dominant eigenvector and the norm converges to the norm % of the dominant eigenvalue, which is returned. % % This routine does exactly niters iterations. % (A more realistic power method routine would include a test % to see when the iteration converged.) % % This is a sequential Matlab template -- CS240A homework 1 is % to implement this in parallel. % % John R. Gilbert 13 Jan 2006 n = length(xinitial); x = xinitial; for i = 1:niters x = x / norm(x); x = A * x; end; lambda = norm(x);