This is a problem I\'m trying to tackle and I don\'t know where to start. Any id
ID: 3765258 • Letter: T
Question
This is a problem I'm trying to tackle and I don't know where to start. Any ideas or some code or script that would work would be greatly appreciated. Especially with explanations because this will be on my final exam! I have to figure it out and memorize it for the final and I am lost. Thanks!
Consider the following variation of the final round of the classic TV game show Let’s Make A Deal. There are three doors, and behind one of them there is a car, while behind the other two are goats. You are asked to choose one of the doors, and, without loss of generality, you choose Door 1. Now, the host Monty Hall opens either Door 2 or Door 3, behind which is a goat. He never opens up the door with the car behind it. Monty now gives you the choice: do you want to stick with Door 1, or switch to the other door. What should you do? Or does it matter?
As seen in class and the youtube video, switching is the better algorithm, and you will verify it, from a numerical standpoint, in this assignment. You are to create two .m files. One is a function that simulates many plays of the Monty Hall game for a single strategy (stay or switch) and returns the probability of success. The other .m file is a script that calls the function once for each strategy and displays the results.
1. In the Matlab Current Folder view:
1. Create a new folder called monty_hall.
2. Add the folder to your path.
3. Make monty_hall your current folder.
2. Create a Matlab function (in a file called simulate_monty_hall_strategy.m) that has the following definition line:
function winProbability = simulate_monty_hall_strategy(strategy, numPlays)
% strategy: A string that may be either 'stay' or 'switch'
% numPlays: # of times to play the Monty Hall game using strategy
% winProbability: # of times the car is won divided by numPlays
Note that your function must use the definition shown above or it will not be graded.
3. simulate_monty_hall_strategy performs the Monty Hall game numPlays times using the given strategy. It follows the standard Monty Hall rules, so the probability that the car is behind any given door is 1/3. Use a loop to perform the simulation, keeping track of the number of wins. winProbability, the output, is the ratio of the number of wins to the number of plays.
4. Create a Matlab script called test_strategies.m that:
1. Runs simulate_monty_hall_strategy using the 'stay' strategy 100,000 times.
2. Displays the strategy name, number of plays, win percentage and loss percentages
3. Runs simulate_monty_hall_strategy using the 'switch' strategy 100,000 times.
4. Displays the strategy name, number of plays, win percentage and loss percentages.
Explanation / Answer
% simulate_monty_hall_startegy
clear all
%Initialize number of Simulated Games
nSGames = 100000;
%Initialize number of Games played with value 0
nGplayed = 0;
%Initialize Successful Switch with value 0
success = 0;
pOfSuccess=zeros(1,nSGames);
for nGplayed = 1:nSGames
doors = zeros(1,3);
% car behind any door
rNum = 3*rand();
if( (rNum>0) && (rNum<1))
doors(1) = 1;
elseif( (rNum>1) && (rNum<2))
doors(2) = 1;
else
doors(3) = 1;
end
for i = 1:3
if(doors(i)==0)
doors(i) = 2;
end
end
% Here gamer randomely pick any door
rNum = 3*rand();
if( (rNum>0) && (rNum<1))
chosenDoor = 1;
elseif( (rNum>1) && (rNum<2))
chosenDoor = 2;
else
chosenDoor = 3;
end
picked = 0;
for i = 1:3
if(i~=chosenDoor)
if(doors(i)~=1)
if(picked==0)
%door isn't a car, isn't the one the contestant picked, and we havent revealed yet..
doors(i)=3;
picked =1;
end
end
end
end
%switch gamer choice.
for i = 1:3
if(i~=chosenDoor)
if(doors(i)~=3)
%not choosen
if(doors(i)==1)
%If gamer switched door won the car
success = success+1;
end
end
end
end
pOfSuccess(nGplayed) = success / nGplayed;
end
xaxis = 1:nGplayed;
figure
plot(xaxis,pOfSuccess);
xlabel('Number of games played')
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.