% ------------------------------
% poww.m
% power iteration
% ------------------------------
clear all;close all;format long;
A  = rand(10,10); b=rand(10,1);
lamx=max(eig(A));
bb = b;
for i = 1: 10000
    b = A*b;
    b = b/norm(b);
    lam = A*b./b;
    [b lam]
    input 'continue'
    if(max(abs(bb-b))<10^-6) 
        disp(['converged after ',num2str(i),' iterations']);
        break
    end
    bb = b;
end
disp(['largest eigenvalue is ',num2str(lam(1))])
disp(['         eig(A) gives ',num2str(lamx)])

    