1. Limited time only! Sign up for a free 30min personal tutor trial with Chegg Tutors
    Dismiss Notice
Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Homework Help: Trouble with Stirling's formula

  1. Mar 23, 2013 #1
    I am trying to solve for probabilities in systems with a large number of elements. To deal with the large factorials that appear in these formulas, I use Stirling's formula, lnm!=mlnm-m+(1/2)ln(2πm). My problem is that after I get the approximation and try to plug it into the probability formula, N!/(n!(N-n)!)(p^n)(q^(N-n)), I get overflows on my calculator. How can I get around this?

    Here is an example problem:

    Using Stirling's formula, calculate the probability of getting exactly 500 heads and 500 tails when flipping 1000 coins.

    The probability equation looks like: (1000!/(2!998!))(1/2)^2(1/2)^998

    I used lnm!=mlnm-m+(1/2)ln(2πm) to get: ln998!=5898.3 and ln1000!=5912.2

    I wound up with somehting that looked like this: (e^5912.2/2e^5898.3)(1/2)^2(1/2)^998

    How do I get my calculate to work with these kind of numbers??

    Thanks for any help!!
  2. jcsd
  3. Mar 24, 2013 #2


    User Avatar
    Homework Helper
    Gold Member
    2017 Award

    Looks like you switched from 500 heads and 500 tails to 998 heads and 2 tails (or 2 heads and 998 tails).
    If you collect all of your factors of 2, you get 21001 in the denominator. Can you write that as e raised to some power? If so, you should be able to combine all of the exponential factors and express the answer as e raised to a large negative power.
  4. Mar 26, 2013 #3


    User Avatar
    Staff Emeritus
    Science Advisor
    Homework Helper

    The factor (1000!/(2! 998!)) can be reduced as follows:

    1000! = 1000 * 999 * 998!

    therefore (1000!/(2! 998!)) = 1000 * 999 * 998! / (2 * 998!) = 999000 / 2 = 499,500
Share this great discussion with others via Reddit, Google+, Twitter, or Facebook

Have something to add?
Draft saved Draft deleted