An Original Description of the Problem
Model a scenario where a computer is shared by two users who connect
and disconnect independently. Assume that at any given minute, each
connected user has a 0.5 probability of disconnecting, while each
disconnected user has a 0.2 probability of reconnecting with a new task.
Represent this system as a Markov chain with three states: 0 (no users
connected), 1 (one user connected), and 2 (both users connected).
Capture the transition probabilities between these states in a matrix.
Simulate this Markov chain for 10,000 transitions, analyze the frequency
of each state, and visualize the results using appropriate graphs to
determine the percentage of time the system spends in each state.
Simulated Data
First 50 states: 3 1 1 2 3 2 1 2 1 1 2 2 1 1 1 2 2 2 2 3 1 2 1 3 3 3
3 3 2 2 3 1 2 1 1 1 2 2 2 2 2 2 2 2 2 2 2 2 2 1
Findings Discussion
After simulating the Markov chain for 10,000 transitions, we found
that the system was in state 0 approximately 50.75% of the time, in
state 1 about 41.18% of the time, and in state 2 around 8.07% of the
time. These results indicate that the system spends the most time with
no users connected, likely due to the higher probability (0.64) of
remaining in state 0. State 1 also appears frequently, reflecting a
moderate balance between users connecting and disconnecting, while state
2 is the least frequent, aligning with its lower transition
probabilities. The bar graph and scatterplot visualizations confirm
these findings, illustrating the dynamic behavior and relative stability
of each state in the system.
Code
library(ggplot2) library(dplyr)
transition_matrix <- matrix(c(0.64, 0.32, 0.04, 0.40, 0.50, 0.10,
0.25, 0.50, 0.25), nrow = 3, byrow = TRUE)
num_transitions <- 10000
set.seed(123) states <- numeric(num_transitions) states[1] <-
sample(1:3, 1)
for (i in 2:num_transitions) { states[i] <- sample(1:3, 1, prob =
transition_matrix[states[i-1], ]) }
cat(“First 50 states:”, states[1:50], “”)
state_freq <- table(states)
barplot(state_freq, main = “Frequency of States in the Markov Chain”,
xlab = “State”, ylab = “Frequency”, col = “skyblue”)
plot(states, type = “p”, main = “Scatterplot of Simulated Markov
Chain States”, xlab = “Transition Index”, ylab = “State”, col = “blue”,
pch = 16)
state_percentages <- prop.table(state_freq) * 100
cat(“Percentage of times in each state:”)
print(state_percentages)