Subject: Calculus

# Stirlings Approximation

Stirling's approximation is a technique widely used in mathematics in approximating factorials. especially large factorials. This approximation is also commonly known as Stirling's Formula named after the famous mathematician James Stirling. One simple application of Stirling's approximation is the Stirling's formula for factorial.

## Stirling's Factorial Approximation

Stirling's formula for the factorial is given by

n! = \sqrt{2 \pi}n^{n+\frac{1}{2}}e^{-n}

So when we want to calculate say 9!, we just play with Stirling's formula;

9! = \sqrt{2 \pi} 9^{9+\frac{1}{2}}e^{-9}
= \sqrt{2 \pi} 9^{\frac{19}{2}}e^{-9}
\approx 2.506*1.16226147 × 10^{9}*0.000123409804

Therefore, using Stirling's formula, we get

9! = \approx 359 446.757

which is not too bad an approximation compared the real value of 9! which is 362 880.

We have just verified that the Stirling's formula works for factorials. Now, maybe we can add a little twist. If we take the natural logarithm of the Stirling's formula, we can also make an approximation of the \ln{n!} out of Stirling's formula;

\ln{n!} = \ln{\sqrt{2 \pi}n^{n+\frac{1}{2}}e^{-n}}
= \ln{\sqrt{2 \pi}} + \ln{n^{n+\frac{1}{2}}} + \ln{e^{-n}}
= \ln{\sqrt{2 \pi n}} + n\ln{n} - n

For large values of n, the first term is usually neglected leaving

\ln{n!} \approx n\ln{n} - n

This is now the Stirling's approximation for the natural logarithm of n!.

### Example #1

Using Stirling's formula, calculate the factorial of 12.

From Stirling's factorial formula,

n! = \sqrt{2 \pi}n^{n+\frac{1}{2}}\cdot e^{-n}

we have the factorial of 12 as

(12)! = \sqrt{6.28318531}\cdot 12^{12.5}\cdot e^{-12}
= 2.506 \cdot 3.0886278 × 10^{13} \cdot 6.14421235 × 10^{-6}
(12)! \approx 475 568 258

The real value of 12! is 479 001 600 which is close to what we got above.

### Example #2

From the calculated value of 9! and 12! using Stirling's formula, show that Stirling's approximation is more accurate for large values of n.

Our goal here is to show that 12! is more accurate than 9! when we use Stirling's approximation in calculating the corresponding factorials, To so this, we will calculate the percent error of each factorials with respect to each real values.

• For 12! :
Using Stirling's formula, the value of 12!, as calculated from example #1, is 475 568 258. The real value of 12! is 479 001 600.

Now,

\%error = \frac{479 001 600-475 568 258}{479 001 600}x100\%
\%error = 0.716\%
• For 9! :
Using Stirling's formula, the value of 12!, as calculated above, is 359446.757. The real value of 9! is 362880.

Now,

\%error = \frac{362880-359446.757}{362880}x100\%
\%error = 0.946\%

From the percent errors above, 12! is clearly less than the corresponding %error of 9!.

### Example #3

Calculate the percent error of 3! when the factorial is calculated using Stirling's formula. Give an assessment regarding the degree of accuracy of Stirling's approximation.

From Stirling's factorial formula,

n! = \sqrt{2 \pi}n^{n+\frac{1}{2}}\cdot e^{-n}

we have the factorial of 3 as

3! = \sqrt{2\pi}\cdot 3^{3.5}\cdot e^{-3}
= 2.506 \cdot 46.7653718 \cdot 0.0497870684
3! =5.83474678

Now, we know that 3! = 6. So, lets compute the error.

\%error = \frac{6-5.83474678}{6}x100\%
\%error = 2.75\%

This error is huge considering the percent error of 12! and 9! in the previous examples. As the value of n goes bigger, the Stirling's approximation gets better and better.

### Example #4

Approximate the value of the natural logarithm of 4! using Stirling's formula.

Stirling's formula holds that,

\ln{n!} \approx n\ln{n} - n

For n=4, we have:

\ln{4!} \approx 4\ln{4} - 4
=1.54517744
.

### Example #5

Using the approximated value of the natural logarithm of 4! in example #4, was it a good approximation?

No.

It was not a good approximation.

Reason? Well, the real value of \ln{4!}=3.178. Whereas Stirling approximates it around 1.54517744 as what is shown in example #4. If we will compute the percent error, it will approach to more than 50\%!. Thus, it is not a good approximation.

NEXT TOPIC: Bernoulli numbers