Wrong result in matrix for loop

I want to enter in R the following matrix (transition probability) but something I make wrong and the output is not right.
The matrix is in the picture :


my effort is the following :


n=100
A = matrix(c(0),n+1,n+1);A
A[1,2] = 1/4 
A[1,1] = 3/4
A[2,1] = 1/4 
A[2,2] = 1/2 
A[2,1] = 1/4
for (k in 2:n) {
  A[k,k+1] = 1/4
  A[k,k]   = 1/2 
  A[k,k-1] = 1/6 
  A[k,k-2] = 1/12
  A[n,n]   = 3/4 
  A[n,n-1] = 1/6 
  A[n,n-2] = 1/12}
A


pA = A
for (i in 10000){
  pA = pA %*% A }
pA

but the resulting columns (first 3 columns) must be: 0.2087, 0.1652, 0.1307

Any help?

Can you try the following code? Please let me know if it works. Thanks

n=100
A = matrix(c(0),n+1,n+1);A
A[1,2] = 1/4 
A[1,1] = 3/4
A[2,1] = 1/4 
A[2,2] = 1/2 
A[2,3] = 1/4
for (k in 3:n) {
  A[k,k+1] = 1/4
  A[k,k]   = 1/2 
  A[k,k-1] = 1/6 
  A[k,k-2] = 1/12
}
A[n+1,n+1]   = 3/4 
A[n+1,n] = 1/6 
A[n+1,n-1] = 1/12
A

yes it works.thanks mate.!!

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.