Subject: Stirling; r objects from am

From: "Mark Hanning-Lee" <[email-masked]>
Date: Fri, 20 Oct 1995 15:06:44 -0700

Fritz Daalmans wrote:

> 1) calculate (n over r), the binomial. Be careful to calculate it using
> long integer (in C), otherwise it will overflow and end up negative :-(
> I used this routine, it will work for n and k not too big:
> /* N over K = N! / (K! (N-K)! ) */

To calculate large factorials, use the Stirling approximation. See a
mathematics book like Abramowitz and Stegun. It states that

log n! ~= n * log n + (other terms which I don't recall offhand)

So you can estimate "n over k" without working out large factorials. If n is
too large to calculate n! directly, the Stirling approximation will be very
accurate.

The A&S book gives many useful approximations which have been most helpful.
For example you can use their approximate error function erf x to add a
Gaussian distribution of noise to simulated data.

Mark

Dr. Mark A. Hanning-Lee    |  Tel:  (310) 336 2835
The Aerospace Corporation  |  FAX:  (310) 336 7680
PO Box 92957, M5-754       |
Los Angeles CA 90009-2957  |  Email: [email-masked]
USA