Page 415 Exercise 13

transition_matrix <- matrix(c(0.5,0.25,0.25,0.5,0,0.5,0.25,0.25,0.5), nrow=3, ncol=3, byrow=TRUE)

land_of_oz <- function(x, y) {
  library(expm)
  Prob_y <- transition_matrix %^% y
  result <- Prob_y %*% x
  
  return (result)
}
# first vector
u1 <- matrix(c(c(0,1,0)))

# result
land_of_oz(u1, 10)
## Warning: package 'expm' was built under R version 4.2.3
## Loading required package: Matrix
## Warning: package 'Matrix' was built under R version 4.2.3
## 
## Attaching package: 'expm'
## The following object is masked from 'package:Matrix':
## 
##     expm
##           [,1]
## [1,] 0.1999998
## [2,] 0.2000008
## [3,] 0.1999998
u2 <- matrix(c(c(1/3,1/3,1/3)))
land_of_oz(u2, 10)
##           [,1]
## [1,] 0.3333333
## [2,] 0.3333333
## [3,] 0.3333333