Von Mises Iteration
a.k.a. the power method. Takes a matrix and computes the dominant eigenvalue and eigenvector.
function [lambda, v] = power_method(A)
[n, ~] = size(A); % size of nxn matrix A
v_prev = rand(n, 1); % random starting vector
tol = Inf; % relative error
%{
Implement the algorithm in the while loop
%}
while tol > 1e-15
v = (A*v_prev)/norm(A*v_prev, Inf);
tol = norm(v-v_prev, Inf);
v_prev = v;
lambda = norm(A*v_prev, Inf);
end
end