P5
Math 2984 - Fall 2017
Intro to Mathematical Problem Solving


Project Task #5: At a random party of N people, will at least two people share a birthday?


COMMENT: For simplicity, assume there are just 365 possible birthdays, and number them 1 through 365.

To simulate a party of N people, we create a vector B of length N, containing a uniform random selection of the integers from 1 to 365.

Given a vector B of length N, MATLAB has a function "unique" which removes any duplicates in B, returning a (possibly shorter) list:

        U = unique ( B )
      

If everyone at the party has a unique birthday, then U is the same length as B. If at least one pair of people have the same birthday, then U is shorter than B.

Write "function value = party ( n )" which simulates a party of N people, and returns true (1) if at least one birthday is shared, but returns false (0) otherwise.

Write "function prob = party_prob ( n )" which calls party(n) 10000 times, counts the number of times that at least one birthday is shared, and returns the probability of this happening (the number of times it happened, divided by 10000).


Write a script that calls party_prob(n) for the values n = 1 through 30, and prints out the values of n and prob.


You can use three separate files, or have all three procedures in a single file.


INSTRUCTIONS:

        call party_prob(n) for n from 1 to 30
        print each pair: n, prob

        function prob = party_prob ( n )
          call party(n) 10000 times.
          Count the number of times party(n) returns true, and divide by 10000
          to estimate prob

        function value = party ( n )
          create the vector b as random integers between 1 and 365;
          (review how to compute a vector of random integers!)
          create the vector u of unique entries in b
          if u is "shorter" than b, then return true
          otherwise return false
      


CHECK: The exact probability of at least one pair of partygoers with matching birthdays for N=23 is 0.507297...


SUBMIT: Your main script should be called "p5.m". If your party() and party_prob() functions are in separate files, please turn them in as well.