disp(' ');
disp(' power_iteration.m  ver 1.1  September 4, 2012 ');
disp('  ');
disp(' by Tom Irvine ');
disp(' ')
disp(' This script finds the largest eigenvalue for the generalized ');
disp(' eigenvalue problem. ');
disp(' ');
disp(' Reference:  Bathe, page 617 ');
disp(' ');
%
clear X;
clear Y;
clear M;
clear Minv;
clear K;
clear n;
%
disp(' ');
M=input(' Enter the mass matrix name:  ');
disp(' ');
K=input(' Enter the stiffness matrix name:  ');
%
disp(' ');
num=input(' Enter the maximum number of iterations: ');
%
n=max(size(M));
%
X=zeros(n,1);
Y=zeros(n,1);
%
for i=1:n
    Y(i)=rand;
end
Y=Y-0.5;
%
Minv=pinv(M);
%
for i=1:num;
    Xhat=Minv*Y;
    Yhat=K*Xhat;
    rho=Xhat'*Yhat/(Xhat'*Y);
    Y=Yhat/sqrt(Xhat'*Y);
end
%
disp(' ');
out1=sprintf(' The maximum eigenvalue = %8.4g ',rho);
disp(out1);
out1=sprintf('              frequency = %8.4g Hz',sqrt(rho)/(2*pi));
disp(out1);
disp(' ');
idis=input(' Display eigenvector?  1=yes 2=no ');
%
if(idis==1)
    Y
end