(* This code redefines MatrixPower so that any matrix to the 0 is the identity. This turns out to be convenient in the demos below. *)
Unprotect[MatrixPower];
MatrixPower[m_?SquareMatrixQ,0]:=IdentityMatrix[Length[m]];
Protect[MatrixPower];

(* Defines a "demo" command that makes an interactive view to follow the execution of a Markov chain. *)
demo[A_,v_,maxn_:20] := Manipulate[ 
{
((1-m)A + m/Dimensions[A][[1]]) // MatrixForm,v //MatrixForm,
BarChart[MatrixPower[A(1-m) + m/Dimensions[A][[1]],n] .v,PlotRange->{Automatic,{0,1}}]},
{m,0,1,0.05},{n,0,maxn,1}]

(* An example with complex eigenvalues *)
A = {{0,0,1},{1,0,0},{0,1,0}};
demo[A,{1,0,0}]

(* Example from class *)
A = {{0.7,0.5},{0.3,0.5}};
demo[A,{1,0}]

(* Example from the PageRank lab *)
A = {{0,1,0,0,0},{1,0,0,0,0},{0,0,0,1,0.5},{0,0,1,0,0.5},{0,0,0,0,0}};
demo[A,{1,0,0,0,0},100]
demo[A,{0,0,1,0,0}]
demo[A,{0,0,0,0,1}]

(* Example from homework: exercise 5.4.4 *)
A = {{0.6,0.3,0.4},{0.1,0.4,0.3},{0.3,0.3,0.3}};
demo[A,{1,0,0}]
demo[A,{0,1,0}]
demo[A,{1/3,1/3,1/3}]