Use at least 10000 simulations to answer the following question. A rat is trappe
ID: 3556598 • Letter: U
Question
Use at least 10000 simulations to answer the following question.
A rat is trapped in a maze. Initially he has to choose one of two directions. If he goes to the right, then he will wander around in the maze for three minutes and will then return to his initial position. If he goes to the left, then with probability (1/3) he will depart the maze after two minutes of traveling, and with probability (2/3) he will return to his initial position after five minutes of traveling. Assuming that the rat is at all times equally likely to go to the left or the right, find
a) the expected number of minutes that he will be trapped in the maze.
b) the standard deviation of the amount of time the rat spends in the maze.
Explanation / Answer
Simulation approach (BASIC)
5 DIM t(10000) preliminary
10 j = 0 statements
15 RANDOMIZE
20 FOR I = 1 TO 10000
25 t(I) = 0
30 y = INT(RND * 2) + 1 randomly chooses 1 or 2
35 IF y = 2 THEN GOTO 50 2 = left, 1 = right
40 t(I) = 3 + t(I) chose 1 = right. Add 3 to counter
45 GOTO 30 and return to beginning of maze
50 b = INT(RND * 3) + 1 chose 2 = left. Now randomly chooses 1,2, or 3
55 IF b = 1 GOTO 70 1 = exit; 2 or 3 = wander
60 t(I) = 5 + t(I) chose 2 or 3. Add 5 to counter
65 GOTO 30 and return to beginning of maze
70 t(I) = t(I) + 2 chose 1. Add 2 to counter & exit
75 j = j + t(I) advance trial counter
80 NEXT I start new trial
85 PRINT j / 10000 expected number of minutes,
based on 10,000 trials
%macro montecar(iter);
%do ii = 1 %to &iter;
data one;
k = 0;
t = 0;
do until (k gt 0);
w=ranuni(0);
x=ranuni(0);
y= int(x*2)+1; /*pick left or right*/
if y = 1 then do; /*if left*/
b = int(w*3)+1; /*wander or exit*/
if b = 1 then do; /*exit*/
t = t+2;
k = 1;
end;
else t = t+5; /*wander*/
end;
else t = t+3; /*if right*/
end;
output;
proc append base=output;
%end;
%mend montecar;
%montecar(5000);
data test; set output;
proc means; var t;
Analysis Variable : t
N Mean Std Dev Minimum Maximum
-----------------------------------------------------------------
5 14.0000000 13.4721936 2 37
-----------------------------------------------------------------
N Mean Std Dev Minimum Maximum
-------------------------------------------------------------------
100 23.2100000 20.8942963 2 89
-------------------------------------------------------------------
N Mean Std Dev Minimum Maximum
--------------------------------------------------------------------
1000 21.2550000 20.2002977 2 122
--------------------------------------------------------------------
N Mean Std Dev Minimum Maximum
--------------------------------------------------------------------
5000 20.9658000 20.8374823 2 191
--------------------------------------------------------------------
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.