% ShowStatVec
% Find the steady state population given transition probabilities
% and the initial population.

clc
% Transition probabilities: 
% P(i,j) is the probability of going to node i from node j
P= [.2 .6 .2; ...
    .7 .3 .3; ...
    .1 .1 .5];
 
v= 1000*ones(3,1);  % initial population distribution
tol= 1;             % tolerance: .1 percent of init population
kMax= 10;           % max no. of iterations allowed

[w,err,its] = StatVec(P,v,tol,kMax);

% Display the approx stationery vector
fprintf('\nAfter %d iterations\n', its)
fprintf('population distribution is %.0f, %.0f, %.0f.\n', ...
        w(1),w(2),w(3))