Download Math 221: Simulations/Law of Large Numbers

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts

Hardware random number generator wikipedia , lookup

Molecular dynamics wikipedia , lookup

Randomness wikipedia , lookup

Fisher–Yates shuffle wikipedia , lookup

Military simulation wikipedia , lookup

Computer simulation wikipedia , lookup

Birthday problem wikipedia , lookup

Transcript
Math 221: Simulations/Law of Large Numbers
The Birthday Problem
Let A be the event that at least two people from a class of 50 share the same birthday. We can use
simulations to find the probability of A. The exact probability is:
P (A) = 1 − P (Ā) = 1 −
316
365 364 363
365 P50
= .97037
·
·
···
=1−
365 365 365
365
36550
A simulation of a procedure is a process that behaves the same way as the procedure, so that similar
results are produced.
In this case, each probability of a birthday is assumed to be equally likely (which is a fair assumption).
We can use a random number generator to randomly choose numbers between 1 and 365, where 1
indicates January 1st and 365 indicates December 31st. The Statistics toolbox for the program Matlab
can easily randomly select the numbers. The simulation would proceed as follows:
1. Randomly select 50 numbers from 1 to 365 (pick 50 birthdays).
2. Determine if at least two of the 50 numbers match (at least two people have the same birthday).
3. Repeat the last two steps thousands of times, keeping track of how many times at least two of the
50 numbers matched, along with the number of trials.
The programming code for the simulation along with a plot are below.
n = 50;
tot = 0;
tot_vec = [];
for i=1:10000
i
G=sort(unidrnd(365,n,1));
H=[G;0] - [0;G];
yes = sum(H==0);
if yes > 0,
tot = tot + 1;
end
tot_vec = [ tot_vec; tot/i ];
end
plot(tot_vec);
page 2
Simulation of Probability that at least 2 people in 50 share the same birthday
1
Relative Frequency
.99
.98
.97
.96
.95
.94
0
500
1000
2000
1500
2500
Number of Trials
3000
3500
4000