% part_c % % Estimates the expected return times to state i for n=5,i =1,2,3,4,5 function return_times = part_c(number_of_iterations) % Input Variables % number_of_iterations Number of times to run to find return time % Initialize estimate = 0; return_times = zeros(5,1); % Run for i = 1,2,3,4,5 for i = 1:5 for loop = 1:number_of_iterations x = i; % start at state i u = rand(1); % Generate a uniform random variable x = part_a(x,u,5); % take a step in the Markov chain estimate = estimate + 1; while (x ~= i) u = rand(1); % Generate a uniform random variable x = part_a(x,u,5); % take a step in the Markov chain estimate = estimate + 1; end end return_times(i) = estimate / number_of_iterations; end