\(~\)
\(~\)
\[P = \begin{pmatrix}0.5 & 0.5\\ 0.25 & 0.75\end{pmatrix}, y = \begin{pmatrix}1 \\ 0\end{pmatrix}\]
\(~\)
# Load libraries
# This library is from the package "expm" so please install if needed
library(expm)
# Create matrices
<- matrix(c(0.5, 0.25, 0.5, 0.75), nrow = 2)
P P
## [,1] [,2]
## [1,] 0.50 0.50
## [2,] 0.25 0.75
<- matrix(c(1, 0))
y y
## [,1]
## [1,] 1
## [2,] 0
\(~\)
# Computing Py
<- P %*% y
Py Py
## [,1]
## [1,] 0.50
## [2,] 0.25
Visually this looks like the following:
\[\begin{pmatrix}\frac{1}{2} & \frac{1}{2}\\ \frac{1}{4} & \frac{3}{4}\end{pmatrix} * \begin{pmatrix}1\\ 0\end{pmatrix} = \begin{pmatrix}\frac{1}{2}\\ \frac{1}{4}\end{pmatrix} = \begin{pmatrix}0.5\\ 0.25\end{pmatrix}\]
\(~\)
# Computing P{^2}y
<- (P %^% 2) %*% y
P2y P2y
## [,1]
## [1,] 0.3750
## [2,] 0.3125
Visually this looks like the following:
\[\begin{pmatrix}\frac{1}{2} & \frac{1}{2}\\ \frac{1}{4} & \frac{3}{4}\end{pmatrix} * \begin{pmatrix}\frac{1}{2}\\ \frac{1}{4}\end{pmatrix} = \begin{pmatrix}\frac{3}{8}\\ \frac{5}{16}\end{pmatrix} = \begin{pmatrix}0.375\\ 0.3125\end{pmatrix}\]
\(~\)
# Computing P{^4}y
<- (P %^% 4) %*% y
P4y P4y
## [,1]
## [1,] 0.3359375
## [2,] 0.3320312
Visually this looks like the following:
\[\begin{pmatrix}\frac{1}{2} & \frac{1}{2}\\ \frac{1}{4} & \frac{3}{4}\end{pmatrix} * \begin{pmatrix}\frac{3}{8}\\ \frac{5}{16}\end{pmatrix} = \begin{pmatrix}\frac{11}{32}\\ \frac{21}{64}\end{pmatrix} = \begin{pmatrix}0.34375\\ 0.328\end{pmatrix}\]
and one more time: \[\begin{pmatrix}\frac{1}{2} & \frac{1}{2}\\ \frac{1}{4} & \frac{3}{4}\end{pmatrix} * \begin{pmatrix}\frac{11}{32}\\ \frac{21}{64}\end{pmatrix} = \begin{pmatrix}\frac{43}{128}\\ \frac{85}{256}\end{pmatrix} = \begin{pmatrix}0.3359\\ 0.3320\end{pmatrix}\]
\(~\)