Plotting Birthday Problem in MATLAB: Analytical Form vs Code Implementation

  • MATLAB
  • Thread starter Bassalisk
  • Start date
  • Tags
    Matlab
In summary, MATLAB is giving me an infinity result for the birthday problem. However, I believe that you can solve it recursively.
  • #1
Bassalisk
947
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

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

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
  • #2
looks like you are not dividing by 365 to the nth power
 
  • #3
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
 
  • #4
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)
 
  • #5
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!
 

1. How do I calculate factorial in MATLAB?

To calculate factorial in MATLAB, you can use the built-in factorial function. For example, to calculate the factorial of 5, you would use the command factorial(5), which would return a value of 120.

2. Can I calculate factorial of a decimal or negative number in MATLAB?

No, the factorial function in MATLAB only works for positive integers. If you need to calculate the factorial of a decimal or negative number, you can use the gamma function instead. For example, gamma(5.5) would return a value of 52.3428.

3. How do I plot a factorial function in MATLAB?

To plot a factorial function in MATLAB, you can use the plot function and specify the range of values you want to plot. For example, x = 1:10; plot(x, factorial(x)) would plot the factorial function from 1 to 10.

4. Can I use a loop to calculate factorial in MATLAB?

Yes, you can use a loop to calculate factorial in MATLAB. For example, you can use a for loop to calculate the factorial of a given number. Alternatively, you can use a recursive function to calculate factorial in MATLAB.

5. Is there a limit to the size of the number that can be calculated using factorial in MATLAB?

Yes, there is a limit to the size of the number that can be calculated using factorial in MATLAB. The maximum value that can be calculated is realmax, which is approximately 1.7977e+308. Attempting to calculate the factorial of a number larger than this will result in an overflow error.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
2K
  • Precalculus Mathematics Homework Help
Replies
3
Views
942
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
3K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
3K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
7K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
1
Views
1K
  • Calculus and Beyond Homework Help
Replies
4
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
6K
Back
Top