####################################################
# Section 6.2 Introduction to Discrete Markov Chains
####################################################
P=matrix(c(.5,.5,0,0,0,0,.25,.5,.25,0,0,0,0,.25,.5,.25,0,0,
0,0,.25,.5,.25,0,0,0,0,.25,.5,.25,0,0,0,0,.5,.5),
nrow=6,ncol=6,byrow=TRUE)
P
s=array(0,c(50000,1))
s[1]=3
for (j in 2:50000)
s[j]=sample(1:6,size=1,prob=P[s[j-1],])
m=c(500,2000,8000,50000)
for (i in 1:4)
print(table(s[1:m[i]])/m[i])
w=matrix(c(.1,.2,.2,.2,.2,.1),nrow=1,ncol=6)
w%*%P
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.