In: Advanced Math
Consider the Monty Hall problem.Verify the results using by writing a computer program that estimates the probabilities of winning for different strategies by simulating it.
1. First, write a code that randomly sets the prize behind one of three doors and you also randomly select one of the doors. You win if the the door you selected has the prize (Here, we are simulating ’stick to the initial door’ strategy). Repeat this experiment 100 times and compute the average number of wins.
2. Next, try simulating the switching strategy. Find the door the host will open and change your initial door with the door not opened by the host. Also repeat this experiment 100 times and compute the average number of wins. If you did everything right, the first code should yield the probability of winning as ≈ 1/3 and the second code should yield ≈ 2/3. You can use any programming language you want (MATLAB, Python etc.)
%%Monty Hall problem
clear all
close all
%1st type with 100 numbers of simulations
val=0; %initial value
for i =1:100
%choosing random number between 1 and 3
%prize door
prize_door = randperm(3,1);
%my choice
my_door = randperm(3,1);
if prize_door==my_door
val=val+1;
end
end
%probability
prob=val/100;
fprintf('Average number of win for 1st problem =%f\n',prob)
%1st type with 100 numbers of simulations
val=0; %initial value
for i =1:100
%choosing random number between 1 and 3
%prize door
prize_door = randperm(3,1);
%my choice
my_door = randperm(3,1);
if prize_door~=my_door
val=val+1;
end
end
%probability
prob=val/100;
fprintf('Average number of win for 2nd problem =%f\n',prob)
%%%%%%%%%%%%%%%% END OF CODE %%%%%%%%%%%%%%%