Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

What i have for the following has a different outcome. I am on the right track but how can I finish this? i need help!

What i have for the following has a different outcome. I am on the right track but how can I finish this? i need help! Also have screenshots of some of my errors if neded.

Activity 1: The Monty Hall Problem

1. The following is the MatLab code for generating a scatter plot showing the results of running the Monty Hall simulation 100000. Run the code and save the output.

% Code to simulate the Monty hall problem

% The array 'doors' represent the 3 doors

% Door States:

% 0 - uninitialized

% 1 - car

% 2 - goat

% 3 - revealed

% clear everything.

clc

clear all

close all

% Initialize

numOfSimulatedGames = 100000;

numGamesPlayed = 0; successfulSwitch = 0;

probabilityOfSuccess=zeros(1,numOfSimulatedGames);

for numGamesPlayed = 1:numOfSimulatedGames

doors = zeros(1,3);

% Stick a car behind a random 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

% Fill in the other 2 spots with goats.

for i = 1:3

if(doors(i)==0)

doors(i) = 2;

end

end

% Have contestant randomly pick a door.

rNum = 3*rand();

if( (rNum>0) && (rNum<1))

chosenDoor = 1;

elseif( (rNum>1) && (rNum<2))

chosenDoor = 2;

else

chosenDoor = 3;

end

% Reveal the first goat door that isnt a chosen door.

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

% At this point the theory says it's beneficial to switch your choice.

% so, if the door that (hasn't been picked or revealed) is the car, increment

% a variable and calculate the probabiltiy.

for i = 1:3

if(i~=chosenDoor)

if(doors(i)~=3)

% Not chosen or revealed, must be the door we'd switch too.

if(doors(i)==1)

% If we would have switched and won the car

successfulSwitch = successfulSwitch+1;

end

end

end

end

probabilityOfSuccess(numGamesPlayed) = successfulSwitch / numGamesPlayed;

end

xaxis = 1:numGamesPlayed;

figure

plot(xaxis,probabilityOfSuccess);

xlabel('Number of games played')

ylabel('Probability of a succesful switch')

2. Using the code above as a template or start from scratch, generate a version of the Monty Hall problem that would consist of 100 doors rather than only 3 doors. The program should still simulate the same concept. The player chooses one door from the one hundred doors. After the selection is made, 98 doors are opened leaving the player with only two doors again. The player must then switch doors.

Provide a scatter plot and a histogram of the results. Submit the code you have written to generate the graphs.

Does it matter if there are 3 doors or 100 doors? Explain your reasoning and use your outputs as evidence to support your claim(s).

Activity 2: The Birthday Problem

The birthday problem is stated as follows: if there is a group of n people in a room, what is the probability that two or more of them have the same birthday? It is possible to determine the answer to this question by simulation. Write a function that calculates the probability that two or more of n people will have the same birthday, where n is the calling argument.

Hint: to do this the function should create an array of size n and generate n birthdays in the range 1 to 365 randomly. It should then check to see if any of the n birthdays are identical. The function should perform this experiment at least 5000 times and calculate the fraction of those times in which two or more people had the same birthday.

MatLab Portion

Use the function you created above and check to see if it works. Let n = 30 and run the program.

Generate a scatter plot to show what the probability value is being approached.

Provide the code you wrote to support the graph.

*******The following code or any variation of the code that uses the mathamatical function is not allowed. *******

P = 1-365!/(365-n)!/365^n

****************************

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Databases And Information Systems 1 International Baltic Conference Dbandis 2020 Tallinn Estonia June 19 2020 Proceedings

Authors: Tarmo Robal ,Hele-Mai Haav ,Jaan Penjam ,Raimundas Matulevicius

1st Edition

303057671X, 978-3030576714

More Books

Students also viewed these Databases questions

Question

Explain the importance of Human Resource Management

Answered: 1 week ago

Question

What is the growth rate of GDP per capita?

Answered: 1 week ago