%% Plot Markov Chain Eigenvalues
% Create 10-state Markov chains from two random transition matrices, with one transition matrix being more sparse than the other.

rng(1); % For reproducibility
numstates = 10;
mc1 = mcmix(numstates,'Zeros',20);
mc2 = mcmix(numstates,'Zeros',80); % mc2.P is more sparse than mc1.P

%
% Plot the eigenvalues of the transition matrices on the separate complex planes.

figure;
eigplot(mc1);

figure;
eigplot(mc2);

% The pink disc in the plots show the spectral gap (the difference between the two largest eigenvalue moduli). The spectral gap determines the mixing time of the Markov chain. Large gaps indicate faster mixing, whereas thin gaps indicate slower mixing.  Because the spectral gap of mc1 is thicker than the spectral gap of mc2, mc1 mixes faster than mc2.
% Copyright 2012 The MathWorks, Inc.