%% Determine Whether Markov Chain Is Ergodic
% Consider this three-state transition matrix.
% P = \left[ {\begin{array}{*{20}{c}}
% 0&1&0\\
% 0&0&1\\
% 1&0&0
% \end{array}} \right].
% Create the Markov chain that is characterized by the transition matrix P.

P = [0 1 0; 0 0 1; 1 0 0];
mc = dtmc(P);

%
% Determine whether the Markov chain is ergodic.

isergodic(mc)

% 0 indicates that the Markov chain is not ergodic.
%
% Visually confirm that the Markov chain is not ergodic by plotting its eigenvalues on the complex plane.

figure;
eigplot(mc);

% All three eigenvalues have modulus one. This result indicates that the period of the Markov chain is three. Periodic Markov chains are not ergodic.
% Copyright 2012 The MathWorks, Inc.