Binomial distribution

Homework Statement

You throw a coin a 100 times, what's the probability of getting 50 tails?

The Attempt at a Solution

We have n=100 , p=1/2, q=1/2 and k=50 we substitute in the first equation we get:
P= 100!/ (50! * 50!) * (1/2)^100
The factorials are not simple to calculate so i used Stirling formula ( logarithmic approximation) and i found that Log P=0 so P=1 which i think is incorrect because 1 is the sum of all the probabilities...so where is my mistake?

Related Precalculus Mathematics Homework Help News on Phys.org
Homework Helper
Log p? I'm not sure what expression it is you calculated the log of. Try this:
Since
$$\binom{100}{50} = \dfrac{100!}{50! \cdot 50!}$$
its logarithm is
$$\log{100!} - \log{50! \cdot 50!} = \log{100!} - \left(\log 50! + \log 50!\right) = \log{100!} - 2\log{50!}$$

use the approximation to work that out, then go back and finish the calculation. (Or, you can use Wolfram Alpha to get the coefficient). It is possible that the intent of the problem is to use the normal approximation, but unless that is specifically requested ...

Orodruin
Staff Emeritus
Homework Helper
Gold Member
I suggest not using the Stirling formula. Computing those factorials relatively accurately should not be a big problem for a computer.

Edit: To clarify, the Stirling formula is not accurate enough for this problem. In order to get something more reasonable you need to include the next term of the approximation as well:
$$\ln(n!) \simeq n(\ln n - 1) + \frac 12 \ln(2\pi n)$$

Last edited:
Log p? I'm not sure what expression it is you calculated the log of. Try this:
Since
$$\binom{100}{50} = \dfrac{100!}{50! \cdot 50!}$$
its logarithm is
$$\log{100!} - \log{50! \cdot 50!} = \log{100!} - \left(\log 50! + \log 50!\right) = \log{100!} - 2\log{50!}$$

use the approximation to work that out, then go back and finish the calculation. (Or, you can use Wolfram Alpha to get the coefficient). It is possible that the intent of the problem is to use the normal approximation, but unless that is specifically requested ...
That's exactly what i did but in order to get that i had to introduce the Log in both sides of the equation, that's why i got Log P

I suggest not using the Stirling formula. Computing those factorials relatively accurately should not be a big problem for a computer.

Edit: To clarify, the Stirling formula is not accurate enough for this problem. In order to get something more reasonable you need to include the next term of the approximation as well:
$$\ln(n!) \simeq n(\ln n - 1) + \frac 12 \ln(2\pi n)$$
I used the next term too and i got a negative result !!! I got 1/2 Log2 - 1/2 Log 100π !!!!

Orodruin
Staff Emeritus
Homework Helper
Gold Member
Then I suggest you redo the algebra. The ##100\log(1/2)## term should cancel with the leading terms from the Stirling approximation and you should be left with the correction terms from ##\ln(100!)## and ##2\ln(50!)##. Do note that the result for ##\ln(P)## should be negative as long as the probability is smaller than 1. I tried this problem both by computing the factorials and by using the correction to the Stirling formula. Both gave similar results.

Then I suggest you redo the algebra. The ##100\log(1/2)## term should cancel with the leading terms from the Stirling approximation and you should be left with the correction terms from ##\ln(100!)## and ##2\ln(50!)##. Do note that the result for ##\ln(P)## should be negative as long as the probability is smaller than 1. I tried this problem both by computing the factorials and by using the correction to the Stirling formula. Both gave similar results.
oh yes yes that's ok i found P=0.08 ...that was Log P which is negative sorry ...Thank you

I suggest not using the Stirling formula. Computing those factorials relatively accurately should not be a big problem for a computer.

Edit: To clarify, the Stirling formula is not accurate enough for this problem. In order to get something more reasonable you need to include the next term of the approximation as well:
$$\ln(n!) \simeq n(\ln n - 1) + \frac 12 \ln(2\pi n)$$
Just a question, How can we know that we should get to next term of the approximation ( without calculating and finding a wrong result)?

Orodruin
Staff Emeritus
Homework Helper
Gold Member
A priori we do not. In order to know we must know how the next term in the series behaves (in this case as ln(n)) and compare to the contribution of the previous terms. The thing to note here is that as was the case in this problem, terms from different contributions might cancel out to leading order and then you really have to go to the next order in the expansion. Another example of this would be ##f(x) = e^x - e^{-x}## for small ##x##. In that situation we would have ##f(x) \simeq 0## close to ##x = 0## due to ##e^x \simeq 1##. However, as soon as you go to the first order correction, you would obtain ##e^x \simeq 1+x## and thus
$$f(x) \simeq (1+x) - (1-x) = 2x.$$

Manel
Ray Vickson
Homework Helper
Dearly Missed
Just a question, How can we know that we should get to next term of the approximation ( without calculating and finding a wrong result)?
I'm not sure what your "next term" would be, but there is a very simple correction to Stirling that gives an upper bound on ##n!##:
$$\text{St}(n) < n! < \text{St1}(n) \\ \text{where} \\ \text{St}(n) = \sqrt{2 \pi n} n^n e^{-n}, \; \text{St1}(n) = \sqrt{2 \pi n} n^n e^{-n + \frac{1}{12n}}$$
If we call St1(n) the corrected Stirling, it gives much better accuracy, even for small ##n##:
$$\begin{array}{cccc} n & n! & \text{Stirling} & \text{Corrected Stirling}\\ 1 & 1 & 0.922137 & 1.002274\\ 2 & 2 & 1.919004 & 2.000652 \\ 5 & 120 & 118.0192 & 120.0026 \\ 10 & 3628800 & 3598696 & 3628810 \\ 15 & 1.307674e+12 & 1.300431e+12 & 1.307675e+12 \\ 20 & 2.432902e+18 & 2.422787e+18 & 2.432903e+18 \\ 25 & 1.551121e+25 & 1.545959e+25 & 1.551121e+25 \\ 30 & 2.652529e+32 & 2.645171e+32 & 2.652529e+32 \end{array}$$
Note that
$$\log(\text{St1}(n)) = \frac{1}{2} \log(2 \pi) +\frac{1}{2} \log(n) + n \log(n) - n + \frac{1}{12n}$$
Was that the "correction" you cited?

Manel
I'm not sure what your "next term" would be, but there is a very simple correction to Stirling that gives an upper bound on ##n!##:
$$\text{St}(n) < n! < \text{St1}(n) \\ \text{where} \\ \text{St}(n) = \sqrt{2 \pi n} n^n e^{-n}, \; \text{St1}(n) = \sqrt{2 \pi n} n^n e^{-n + \frac{1}{12n}}$$
If we call St1(n) the corrected Stirling, it gives much better accuracy, even for small ##n##:
$$\begin{array}{cccc} n & n! & \text{Stirling} & \text{Corrected Stirling}\\ 1 & 1 & 0.922137 & 1.002274\\ 2 & 2 & 1.919004 & 2.000652 \\ 5 & 120 & 118.0192 & 120.0026 \\ 10 & 3628800 & 3598696 & 3628810 \\ 15 & 1.307674e+12 & 1.300431e+12 & 1.307675e+12 \\ 20 & 2.432902e+18 & 2.422787e+18 & 2.432903e+18 \\ 25 & 1.551121e+25 & 1.545959e+25 & 1.551121e+25 \\ 30 & 2.652529e+32 & 2.645171e+32 & 2.652529e+32 \end{array}$$
Note that
$$\log(\text{St1}(n)) = \frac{1}{2} \log(2 \pi) +\frac{1}{2} \log(n) + n \log(n) - n + \frac{1}{12n}$$
Was that the "correction" you cited?
So the corrected stirling is the most accurate formula to use if we want better precision?

Ray Vickson
Homework Helper
Dearly Missed
So the corrected stirling is the most accurate formula to use if we want better precision?
I would not bother in this problem: P0 = 0.07958923737, P1 = 0.07978845606 and P2 = 0.07958923413, where P0 = exact, P1 uses Stirling and P2 uses corrected Stirling. To 3 digits we have P0 = 0.0796, P1 = 0.0798 and P2 = 0.0796.

The differences would be more significant in smaller problems, such as for n near 20 instead of 100.

Manel
Ray Vickson