Power Method in MATLAB
I would like to implement the Power Method for determining the dominant eigenvalue and eigenvector of a matrix in MATLAB. Here's what I wrote so far: %function to implement power method to compute dominant %eigenvalue/eigenevctor function [m,y_final]=power_method(A,x); m=0; n=length(x); y_final=zeros(n,1); y_final=x; tol=1e-3; while(1) mold=m; y_final=A*y_final; m=max(y_final); y_final=y_final/m; if (m-mold)<tol break; end end end With the above code, here is a numerical example: A=[1 1 -2;-1 2 1; 0 1 -1] A = 1 1 -2 -1 2 1 0 1 -1 >> x=[1 1 1]; >> x=x'; >> [m,y_final]=power_method(A,x); >> A*x