clear clc P = [1 0.2 0.3; 0 0.7 0.1; 0 0.1 0.6] P_previous = P brojac = 0; while 1 P_next = P_previous * P x = sum(sumabs((P_previous-P_next))) if x<0.01 break; end P_previous = P_next brojac = brojac + 1; end P P_next brojac x