Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

5.24 The birthday problem is stated as follows: if there is a group of n people

ID: 3535138 • Letter: 5

Question

5.24

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.

Explanation / Answer

TRy this

Here is a Monte Carlo solution. Increase the number of samples to improve the accuracy.

nump=30;
samples=10000;
birthd=ceil(365*rand(nump,samples));
count=0;
for j=1:samples
if numel(birthd(:,j))-numel(unique(birthd(:,j))) >0
count=count+1;
end
end
probab=1-count/samples

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote