function lambda = powermethod(A) % POWERMETHOD : Power method to estimate norm of dominant eigenvalue % % lambda = powermethod(A); % % This routine generates a random vector, then repeatedly % multiplies matrix A by the vector and normalizes the result % to have length 1. The norm converges to the magnitude of % the dominant eigenvalue, which is returned as lambda. % % This is a sequential Matlab template -- CS140 homework 3 is % to implement this in parallel. % % John R. Gilbert 13 Jan 2006 / modified 24 Jan 2008 [n,n] = size(A); % number of rows and columns in A x = rand(n,1); % creates a random n-vector for i = 1:1000 x = x / norm(x); % norm(x) is sqrt(x(1)^2 + x(2)^2 + ... + x(n)^2) x = A * x; % use your parallel matrix * vector routine here end; lambda = norm(x);