echo off
disp(sprintf('**** Graphical presentation of Power method - single starting vector*'));
echo on
%A=[0.5 0.1; 0.1 0.3] 	% initial matrix with maximal eigenvalue < 1
A=[0.7 1; 0.1 -1.2] 	% initial matrix with maximal eigenvalue > 1
xi=[0.1,0.1]' % initial vector
echo off;
figure(1);
axis equal;
plot(xi(1,1),xi(2,1),'-'); %plot starting vector
hold on;   
plot(0,0,'r+');	%plot origin (0,0) point
for i=1:10
	xi=A*xi;	% generate next vector
	axis equal;
	plot(xi(1,1),xi(2,1),'r*'); %plot vector
end
echo on;
v=norm(xi);
xn=xi/v		% approximate normalized eigenvector 
axis equal;
plot(xn(1,1),xn(2,1),'g*')
x=A*xi;	% generate one additional vector
v=x(1,1)/xi(1,1)	% approximate maximal eigenvalue 
[V,D]=eig(A)	%MatLab eigenvectors and eigenvalues.


echo off
disp(sprintf('**** Graphical presentation of Power method - all vectors ***'));
%A=[0.5 0.1; 0.1 0.3] 	% initial matrix with maximal eigenvalue < 1
A=[0.7 1; 0.1 -1.2] 	% initial matrix with maximal eigenvalue > 1
figure(2);
axis equal;
hold on;   
plot(0,0,'r+');	%plot origin (0,0) point
t=[-1:.01:1];
%Calculate vectors from the unit circle
U=[cos(t*pi); sin(t*pi)];
Xi=A*U;
plot(U(1,:),U(2,:),'r.');
plot(Xi(1,:),Xi(2,:),'b.');
for i=1:5
	Xi=A*Xi;	% generate next vector
	axis equal;
	plot(Xi(1,:),Xi(2,:),'b.'); %plot vector
end
[V,D]=eig(A)	%MatLab eigenvectors and eigenvalues.
