%power method for estimating dominant (i.e. largest in absolute value)
%eigenvalue and eigenvector of a square matrix A


A = [4,-4;12,-12];
n = 8;         %number of iterations
x = [1;0];      %initial guess of dominant eigenvector

for k=1:n
    x = A*x          %x = the current estimate of the dominant eigenvector
    [argvalue,argmax] = max(abs(x));
    m = x(argmax)    %m = the entry of x with largest absolute value
    x = x/m;
end

disp('estimate of dominant eigenvalue is...')
m

disp('estimate of corresponding eigenvector is...')
x