S=0 ss=0 cc=0 =0 whilei<3. j=0 while j<3: s+=t]]*c[0] ss+=T[i][j]*c[i]lj] cc+=c[i][j] j+-1 +=1 ss/=cc s/=cc if abs(ss-s)/s<0.03: return 1 return 0 =0.5 while not ans(r):progressive increasing and get the first number r+=0.01 =0 while i<3:output matrix T print Tfi] i计=1 printr# Procedure code 2: >>n=2500000:t0=2000000: P=0.4,0.2,0.4,0.12,0.46,0.42,0.15,0.30,0.551 C=cumsum(P,2); state=ones(1,n); r=unifrnd(0,1,1,n) i0=input('original state:) original state:I >i=i0: for t=l:n j=state(t): while r(t)>C(i,j) j-j+l; end state(t)=j; i ends=0 ss=0 cc=0 i=0 whilei<3: j=0 while j<3: s+=t[i][j]*c[i][j] ss+=T[i][j]*c[i][j] cc+=c[i][j] j+=1 i+=1 ss/=cc s/=cc if abs(ss-s)/s<0.03: return 1 return 0 r=0.5 while not ans(r): # progressive increasing and get the first number r+=0.01 i=0 while i<3:# output matrix T print T[i] i+=1 print r # Procedure code 2: >> n=2500000;t0=2000000; P=[0.4,0.2,0.4;0.12,0.46,0.42;0.15,0.30,0.55]; C=cumsum(P,2); state=ones(1,n); r=unifrnd(0,1,[1,n]); i0=input('original state:'); original state:1 >>i=i0; for t=1:n j=state(t); while r(t)>C(i,j) j=j+1; end state(t)=j; i=j; end