Birthday probability solution

版本 1.0.0.0 (1.5 KB) 作者: samil
Solution to the problem of finding the probability of at least two people having the same birthday
4.7K 次下载
更新时间 2012/1/31

查看许可证

Solution to birthday probability problem: If there are n people in a classroom, what is the probability that at least two of them have the same birthday?
General solution:
P = 1-365!/(365-n)!/365^n
If you try to solve this with large n (e.g. 30, for which the solution is 29%) with the factorial function like so:
P = 1-factorial(365)/factorial(365-30)/365^30
Matlab will output NaN because Matlab tries to compute very large values here.
The approach in this script is to start from n=1 and at each step use the previous step's result to avoid dealing with large numbers.

引用格式

samil (2024). Birthday probability solution (https://www.mathworks.com/matlabcentral/fileexchange/34860-birthday-probability-solution), MATLAB Central File Exchange. 检索来源 .

MATLAB 版本兼容性
创建方式 R2007a
兼容任何版本
平台兼容性
Windows macOS Linux
类别
Help CenterMATLAB Answers 中查找有关 Birthdays 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!
版本 已发布 发行说明
1.0.0.0