Answer on Question #45298,
Programming, Mat LAB | Mathematica | MathCAD | Maple
Problem.
If there is a group of n people in a room, what is the probability that two or more of them having same birthday? It is possible to determine answer to this question by simulation. (Hint: You can generate random dates, n times and determine the fraction of people who born in a given day). Write a function that determines the answer to this question by simulation. The program you write can take n as the input and prints out the probability that two or more of n people will have the same birthday for 40
Solution.
Code (MATLAB)
function probability()
clc();
% Input
n = input('Enter the number of people:');
m = input('Enter the number simulation:');
% The number of case in which two or more have the same birthday
success = 0;
% Loop to compute success
for i = 1:1:m
group = randi(365,1,n);
if length(unique(group)) == n
success = success + 1;
end
end
% Output
fprintf('The probability equals %f\n', success/m);
endResult
http://www.AssignmentExpert.com/
Comments