64 669
Assignments Done
99,2%
Successfully Done
In September 2018

# Answer to Question #45329 in MatLAB | Mathematica | MathCAD | Maple for Akshay Joshi

Question #45329
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 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
close all; clear all; clc;date_min = datenum([1960 1 1]);             % start datedate_max = floor(now);                     &nbsp;% current dateN = 40;P = zeros(1,N-1);for n=2:N   date_r = randi([date_min date_max], 1, n);   &nbsp; % random day       date_r_d = datevec(date_r);            &nbsp;       d = date_r_d(:,3);       m = date_r_d(:,2);      &nbsp; c = 0;       for i = 1:n            for j = 1:n                if m(i) == m(j) &amp;&amp; d(i) == d(j) &amp;&amp; i ~= j                  &nbsp; c = c + 1;                end            end      &nbsp; end      &nbsp; P(n-1) = c/n;endP

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!