Advertisement
makispaiktis

Tutorial - Birthday Paradox

Aug 11th, 2021 (edited)
378
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 0.56 KB | None | 0 0
  1. clc
  2. clear all
  3.  
  4. % MAIN FUNCTION
  5. % Given N = 100 for example, I will find the probabilities: If there are n people
  6. % in the same room, what's the p someone shares the birthday
  7. N = 100;
  8. possibilities = birthdayParadox(N);
  9. display('In 23 people, the possibility someone shares his birthday: ');
  10. disp(possibilities(23));
  11.  
  12. % AUXILIARY FUNCTION
  13. function possibilities = birthdayParadox(N)
  14.     possibilities = zeros(N, 1);
  15.     p = 365/365;
  16.     for n = 1:N
  17.         possibilities(n) = 1-p;
  18.         p = p * (365 - n) / 365;
  19.     end
  20.     plot(possibilities);
  21. end
  22.  
  23.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement