% Monte Carlo simulation of simple queue % for comparison to Markov chain approach p = .05; q = .08; random_nums = rand(10000,1); nsims = 10000; state = ones(nsims,1); nperiods = 100; for n=1:nperiods for sim = 1:nsims random_num = rand(1); if random_num < p if state(sim)<3 state(sim) = state(sim) + 1; end end if random_num > 1-q if state(sim)>1 state(sim) = state(sim) - 1; end end end p1 = length(find(state==1)); p2 = length(find(state==2)); p3 = length(find(state==3)); disp([n p1 p2 p3]) end