%% Determine Markov Chain Stationary Distribution
% Consider this theoretical, right-stochastic transition matrix of a stochastic process.
% P = \left[ {\begin{array}{*{20}{c}}
% 0&0&1/2&1/4&1/4&0&0\\
% 0&0&1/3&0&2/3&0&0\\
% 0&0&0&0&0&1/3&2/3\\
% 0&0&0&0&0&1/2&1/2\\
% 0&0&0&0&0&3/4&1/4\\
% 1/2&1/2&0&0&0&0&0\\
% 1/4&3/4&0&0&0&0&0
% \end{array}} \right].
% Create the Markov chain that is characterized by the transition matrix P.

P = [ 0   0  1/2 1/4 1/4  0   0 ;
      0   0  1/3  0  2/3  0   0 ;
      0   0   0   0   0  1/3 2/3;
      0   0   0   0   0  1/2 1/2;
      0   0   0   0   0  3/4 1/4;
     1/2 1/2  0   0   0   0   0 ;
     1/4 3/4  0   0   0   0   0 ];
mc = dtmc(P);

%
% Plot a directed graph of the Markov chain. Indicate the probability of transition by using edge colors.

figure;
graphplot(mc,'ColorEdges',true);

%
% Determine the stationary distribution of the Markov chain.

xFix = asymptotics(mc)

% Because xFix is a row vector, it is the unique stationary distribution of mc.
% Copyright 2012 The MathWorks, Inc.