Mat_A = [0.8 0.1 0; 0.2 0.6 0.1; 0 0.3 0.9]; x = Markov(Mat_A); disp(x); function x = Markov(Mat_A) Current = rand(3, 1); Current = Current / sum(Current); Check = false; for i = 1:100 Next = Mat_A * Current; Next = Next / sum(Next); if all(round(Current, 4) == round(Next, 4)) Check = true; break; end Current = Next; end if Check x = Current; disp('Solution is:'); else disp('Failed.'); end end