Question #45298

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
n=2,3,4…. 40
1

Expert's answer

2014-09-02T01:49:08-0400

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 n=2,3,4n = 2,3,4\ldots 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);
end


Result



http://www.AssignmentExpert.com/

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!
LATEST TUTORIALS
APPROVED BY CLIENTS