Chapter 11.1 Exercise 7

Find the matrices \(P^2\), \(P^3\), \(P^4\), and \(P^n\) for the Markov chain determined by the transition matrix \(P = \begin{pmatrix} 1 & 0 \\ 0 & 1 \end{pmatrix}\). Do the same for the transition matrix \(P = \begin{pmatrix} 0 & 1 \\ 1 & 0 \end{pmatrix}\). Interpret what happens in each of these processes.

library(expm)
p1 <- c(1 ,0, 0, 1)
P1 <- matrix(p1, nrow=2)
P1
##      [,1] [,2]
## [1,]    1    0
## [2,]    0    1
P1%^%2
##      [,1] [,2]
## [1,]    1    0
## [2,]    0    1
P1%^%3
##      [,1] [,2]
## [1,]    1    0
## [2,]    0    1
P1%^%4
##      [,1] [,2]
## [1,]    1    0
## [2,]    0    1

If \(P = \begin{pmatrix} 1 & 0 \\ 0 & 1 \end{pmatrix}\), then \(P^n = P = \begin{pmatrix} 1 & 0 \\ 0 & 1 \end{pmatrix}\).

Since it is the identity matrix it will always be the identity matrix as many times as you multiply it by itself. This would be true of any size identity matrix.

p2 <- c(0, 1, 1, 0)
P2 <- matrix(p2, nrow=2)
P2
##      [,1] [,2]
## [1,]    0    1
## [2,]    1    0
P2%^%2
##      [,1] [,2]
## [1,]    1    0
## [2,]    0    1
P2%^%3
##      [,1] [,2]
## [1,]    0    1
## [2,]    1    0
P2%^%4
##      [,1] [,2]
## [1,]    1    0
## [2,]    0    1

If \(P = \begin{pmatrix} 0 & 1 \\ 1 & 0 \end{pmatrix}\), then if \(n\) is even \(P^n = \begin{pmatrix} 1 & 0 \\ 0 & 1 \end{pmatrix}\) and if \(n\) is odd \(P^n = P = \begin{pmatrix} 0 & 1 \\ 1 & 0 \end{pmatrix}\). Since \(P\) times itself equals the identity matrix each time you multiply it by itself again it will flip-flop back and forth between \(P\) and the identity matrix.

This would be true of any square matrix with ones on the secondary diagonal and zeros everywhere else…

p3 <- c(0, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 0)
P3 <- matrix(p3, nrow=4)
P3
##      [,1] [,2] [,3] [,4]
## [1,]    0    0    0    1
## [2,]    0    0    1    0
## [3,]    0    1    0    0
## [4,]    1    0    0    0
P3%^%2
##      [,1] [,2] [,3] [,4]
## [1,]    1    0    0    0
## [2,]    0    1    0    0
## [3,]    0    0    1    0
## [4,]    0    0    0    1
P3%^%3
##      [,1] [,2] [,3] [,4]
## [1,]    0    0    0    1
## [2,]    0    0    1    0
## [3,]    0    1    0    0
## [4,]    1    0    0    0
P3%^%4
##      [,1] [,2] [,3] [,4]
## [1,]    1    0    0    0
## [2,]    0    1    0    0
## [3,]    0    0    1    0
## [4,]    0    0    0    1

If the entries on the secondary diagonal are all the same but not ones then it would keep raising the power of the entriees and swapping them between the main diagonal and the secondary diagonal…

p4 <- c(0, 0, 0, 3, 0, 0, 3, 0, 0, 3, 0, 0, 3, 0, 0, 0)
P4 <- matrix(p4, nrow=4)
P4
##      [,1] [,2] [,3] [,4]
## [1,]    0    0    0    3
## [2,]    0    0    3    0
## [3,]    0    3    0    0
## [4,]    3    0    0    0
P4%^%2
##      [,1] [,2] [,3] [,4]
## [1,]    9    0    0    0
## [2,]    0    9    0    0
## [3,]    0    0    9    0
## [4,]    0    0    0    9
P4%^%3
##      [,1] [,2] [,3] [,4]
## [1,]    0    0    0   27
## [2,]    0    0   27    0
## [3,]    0   27    0    0
## [4,]   27    0    0    0
P4%^%4
##      [,1] [,2] [,3] [,4]
## [1,]   81    0    0    0
## [2,]    0   81    0    0
## [3,]    0    0   81    0
## [4,]    0    0    0   81

If the entries on the secondary diagonal are not all the same, then it gets a bit more complicated, but the resulting values from raising the matrix to increasing powers will still flip-flop between diagonals and remain zero everywhere else…

p5 <- c(0, 0, 0, 5, 0, 0, 4, 0, 0, 3, 0, 0, 2, 0, 0, 0)
P5 <- matrix(p5, nrow=4)
P5
##      [,1] [,2] [,3] [,4]
## [1,]    0    0    0    2
## [2,]    0    0    3    0
## [3,]    0    4    0    0
## [4,]    5    0    0    0
P5%^%2
##      [,1] [,2] [,3] [,4]
## [1,]   10    0    0    0
## [2,]    0   12    0    0
## [3,]    0    0   12    0
## [4,]    0    0    0   10
P5%^%3
##      [,1] [,2] [,3] [,4]
## [1,]    0    0    0   20
## [2,]    0    0   36    0
## [3,]    0   48    0    0
## [4,]   50    0    0    0
P5%^%4
##      [,1] [,2] [,3] [,4]
## [1,]  100    0    0    0
## [2,]    0  144    0    0
## [3,]    0    0  144    0
## [4,]    0    0    0  100

So, if you want to swap diagonals of any square matrix you can just multiply it by a matrix of the same dimensions with ones on the secondary diagonal…

p6 <- c(1, 5, 9, 13, 2, 6, 10, 14, 3, 7, 11, 15, 4, 8, 12, 16)
P6 <- matrix(p6, nrow=4)
P6
##      [,1] [,2] [,3] [,4]
## [1,]    1    2    3    4
## [2,]    5    6    7    8
## [3,]    9   10   11   12
## [4,]   13   14   15   16
P3 %*% P6
##      [,1] [,2] [,3] [,4]
## [1,]   13   14   15   16
## [2,]    9   10   11   12
## [3,]    5    6    7    8
## [4,]    1    2    3    4

Actually it looks like what it does is reverse the order of the rows! Interesting!