Write a code that implements the basic power method to find
Write a code that implements the basic power method to find the largest eigenvalue and its corresponding eigenvector of any matrix. Use your code to find the largest eigenvalue and its corresponding eigenvector of the matrix
Solution
function [x,lambda]=powermat1(A,x0,nit)
% calculates the largest eigenvalue and corresponding eigenvector of
% matrix A by the power method using x0 as the starting vector and
% carrying out nit interactions. %
x = x0;
for n = 1:nit
xnew = A*x;
lambda = norm(xnew,inf)/norm(x,inf);
fprintf(\'n = %4d lambda = %g x = %g %g %g \ \', n, lambda, x\');
x=xnew;
end x = x/norm(x);
%normalise x
fprintf(\'n = %4d normalised x = %g %g %g\ \', n, x\');
%end
