%% copy this file iteratesep29.m to your directory and
%% enter the matlab command  ---  iteratesep29  at the matlab prompt
clear all
close all
format long
M=[.95 .9; .05 .1]
disp('eigenvectors and eigenvalues are:')
[Q,D]=eig(M)
disp('enter return to continue - or use dbstep')
keyboard
x_p=rand(2,1);
x_p=x_p/sum(x_p);
x_c=zeros(2,1);
disp('start iteration for new x_p=Mx_c with initial random vector x_c')
x_p
iterk=0;
plot(x_p(1),x_p(2),'bo-')
Xp=x_p;
while norm(x_c-x_p)>1e-14,
  x_c=x_p;
  x_p=M*x_c;
  iterk=iterk+1;
  disp(' ')
  disp(['previous x_c, new x_p vectors and x_c-x_p after iteration ',num2str(iterk),' are '])
  Xp=[Xp x_p];
  plot(Xp(1,:),Xp(2,:),'bo-')
  hold on
  plot(Xp(1,end),Xp(2,end),'rx-')
  hold off
  [x_c x_p x_c-x_p]
end
disp('normalized solution is')
x_p=x_p/sum(x_p);
x_p
