Plotting Birthday Problem in MATLAB: Analytical Form vs Code Implementation

  • Context: MATLAB 
  • Thread starter Thread starter Bassalisk
  • Start date Start date
  • Tags Tags
    Matlab
Click For Summary

Discussion Overview

The discussion revolves around plotting the birthday problem in MATLAB, specifically comparing the analytical form of the probability of not having the same birthday among a group of people with its code implementation. Participants explore issues related to coding, numerical limits, and potential solutions.

Discussion Character

  • Technical explanation
  • Mathematical reasoning
  • Debate/contested

Main Points Raised

  • One participant presents the analytical form of the birthday problem's probability and expresses difficulty in implementing it in MATLAB.
  • Another participant suggests that the issue may stem from not dividing by 365 raised to the nth power.
  • Further comments indicate that the calculations might be resulting in infinity due to MATLAB's limitations on integer and floating-point numbers.
  • A participant proposes a recursive approach to calculate the probabilities, starting from n=0 and building up to higher values.

Areas of Agreement / Disagreement

Participants do not reach a consensus on the specific coding issue, as multiple viewpoints on the cause of the problem and potential solutions are presented.

Contextual Notes

Participants note limitations related to MATLAB's maximum values for integers and floating-point numbers, which may affect the calculations being performed.

Bassalisk
Messages
946
Reaction score
2
So I am trying to plot the birthday problem.

Number of people vs chance not to have the same birthday.

I know the analytical form

P(n)={\Large\frac{365\cdot 364\cdot 363...(365-n+1)}{365^{n}}}

problem is, MATLAB is giving me this, when I try to put that into code.

[PLAIN]http://pokit.org/get/e8cbb0974a4b30d349d554c27ab0f537.jpg

And that's only trying to realize the top part of the fraction.

I am trying to get this result.

[URL]http://upload.wikimedia.org/wikipedia/commons/f/ff/Birthdaymatch.png[/URL]

Source wikipedia.Thank you.
 
Last edited by a moderator:
Physics news on Phys.org
looks like you are not dividing by 365 to the nth power
 
Dr Transport said:
looks like you are not dividing by 365 to the nth power

Still he is giving me infinity. I think he calculates factorial first, then to the nth, then divides that and still gets infinity
 
Unfortunately, MATLAB has maxima on both integers and floating point numbers:
http://www.mathworks.com/help/techdoc/ref/intmax.html
http://www.mathworks.com/help/techdoc/ref/realmax.html

I believe that both are exceeded by the calculations that you're trying to make in the numerator and denominator.

However, I believe that you can do this recursively (i.e. start with n=0, and use this result to generate n=1, use that result to generate n=2, etc.)
http://en.wikipedia.org/wiki/Recursion_(computer_science)
 
MATLABdude said:
Unfortunately, MATLAB has maxima on both integers and floating point numbers:
http://www.mathworks.com/help/techdoc/ref/intmax.html
http://www.mathworks.com/help/techdoc/ref/realmax.html

I believe that both are exceeded by the calculations that you're trying to make in the numerator and denominator.

However, I believe that you can do this recursively (i.e. start with n=0, and use this result to generate n=1, use that result to generate n=2, etc.)
http://en.wikipedia.org/wiki/Recursion_(computer_science)

My hero <3 Thank you!
 

Similar threads

  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 4 ·
Replies
4
Views
7K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 1 ·
Replies
1
Views
4K
  • · Replies 3 ·
Replies
3
Views
2K
Replies
2
Views
2K
Replies
5
Views
8K
  • · Replies 2 ·
Replies
2
Views
7K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 1 ·
Replies
1
Views
2K