(a) Use Matlab to conduct a computer experiment to verify the solution that the probability of winning by switching is 2/3. Report your design and computer code of the experiment and average results from 10, 000 trials of the experiment.

4 views (last 30 days)
(a) Usclose all;
clc;
ntrials = 10000;
%losing results
doors = ['empty','empty','car'];
wins = 0;
losses = 0;
newwins= 0;
newlosses=0;
%person keeps the same door they chose at the beginning
for i = 0:ntrials
doors = rand;
choice = ['Choose Door', 'A','B','C'];
if doors(choice-1) == input('You Won')
fprintf('Winner!');
wins = wins+1;
else
fprintf('Loser!')
losses = losses+1;
end
end
%person changes door once shown door chosen is empty
for j = 0:ntrails
doors = rand;
choice = ['Choose Door', 'A','B','C'];
choice2 = rand(0,2);
end
while door(choice2)==input('car')
choice2=choice;
%losing door revealed
fprintf('Eliminate Door B')
if choice2 == 0 && choice == 1
choice = 2;
elseif choice2 == 0 && choice == 2
choice = 1;
elseif choice2 == 1 && choice == 0
choice =2;
elseif choice2 == 1 && choice == 2
choice = 0;
elseif choice2 == 2 && choice == 0
choice = 1;
elseif choice2 == 2 && choice == 1
choice = 0;
end
end
if doors(choice-1) == input('You Won!')
fprintf('Winner!');
newwins = newwins+1;
else
fprintf('Loser!')
newlosses = newlosses+1;
end
e Matlab to conduct a computer experiment to verify the solution that the probability of winning by switching is 2/3. Report your design and computer code of the experiment and average results from 10, 000 trials of the experiment.

Answers (0)

Categories

Find more on MATLAB Report Generator in Help Center and File Exchange

Tags

Products

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!