[Search for users] [Overall Top Noters] [List of all Conferences] [Download this site]

Conference rusure::math

Title:Mathematics at DEC
Moderator:RUSURE::EDP
Created:Mon Feb 03 1986
Last Modified:Fri Jun 06 1997
Last Successful Update:Fri Jun 06 1997
Number of topics:2083
Total number of notes:14613

1971.0. "Gamma Function formula help wanted" by ALICAT::MACKAY (Don Mackay) Fri May 05 1995 00:33

It was suggested that I ask this here.

By the way, I'm not a maths guru...


           <<< AUSSIE::DISK$TOOLS:[NOTES$LIBRARY]ALGORITHMS.NOTE;1 >>>
                                -< ALGORITHMS >-
================================================================================
Note 248.0             Gamma Function fortmula help wanted             2 replies
ALICAT::MACKAY "Don Mackay"                          29 lines   4-MAY-1995 14:39
--------------------------------------------------------------------------------
I am trying to write a routine to calculate the Gamma function and I
have come across Strilings Asymptotic  series formula

                                                 1        1         139
Gamma(x+1) = sqrt( 2*Pi*x ) * x^x * e^-x * {1 + ---- + ------- - --------- +...}
                                                12*x   288*x^2   51840*x^3

This formula only creates a value to (what looks like) 4 significant
figures and I would like to increase this (partly for a good reason,
mostly because of interest)

I have also found the formula:

gamma(x+1) = sqrt( 2*Pi*x) * x^x * e^-x * e^(t/(12 * (x+1)))

	where 0 < t < 1

and I can apply the Taylors series expansion to the last term and derive
the first 3 parts of the last bit of the first equation.

However I can't understand where the 4th term comes from (the one with
139 as the numerator), nor can I work out what *should* be the next
term.

Any help would be appreciated.

Thanks

Don Mackay
T.RTitleUserPersonal
Name
DateLines
1971.1a very little helpRANGER::BRADLEYChuck BradleyFri May 05 1995 17:1313
i figured this would be answered immediately with full details, but 
here is a little help.  the next term is also negative, and with a
much larger denominator. most of the series i saw were for log(gamma(1+x)).

at least one promised 7 significant digits from 9(i think) terms.

to get the best advice, tell us what accuracy you need, and for what
range of argument. also, do you have constraints on the error?
for instance, min value of max error, or min average error over what range.

do you have a math library, or are you restricted to an algebraic expansion?

1971.2It's a subtractionEVMS::HALLYBFish have no concept of fireFri May 05 1995 23:1911
> However I can't understand where the 4th term comes from (the one with
> 139 as the numerator), nor can I work out what *should* be the next
> term.
							571
    Me neither, but the next term is     -	---------------------
    						   2488320 * x^4
    
    Doncha just hate it when somebody gives you an infinite series without
    bothering to explain where the coefficients come from?
    
      John
1971.3WRKSYS::ROTHGeometry is the real life!Mon May 08 1995 15:0938
   There is a better way to calculate gamma - that's to calculate
   log(gamma) instead, and then exponentiate to get gamma itself.

   One reason is that the the asymptotic series is more accurate for
   a given number of terms, and only has odd powers of 1/x^k in the
   expansion, and also that the coefficients have a very simple form
   in terms of Bernoulli numbers so you can in principle have as many
   terms as you want.

   The mysterious coefficients in the series you give come from
   exponentiating the series for log(gamma), (known in terms of
   Bernoulli numbers) by formal power series manipulation.  There
   is no simple closed form for them.

   Also, the series is asymptotic - this means that accuracy for a
   given number of terms in the series increases as x increases, but
   does *not* mean that for a given x, you adding more terms to the
   series increases accuracy without limit.  In fact, accuracy gets worse
   after a point in the series!

   A simple "fix" for this last problem is to use the relation

	gamma(z+1) = z*gamma(z)

   and work backwards to get an accurate gamma for a small number.

   For example, suppose you want gamma(4.5).  Since the series is
   more accurate for larger x, instead calculate gamma(10.5) (say)
   and then use

	gamma(10.5) = 9.5*8.5*7.5*6.5*5.5*4.5*gamma(4.5)

   to find gamma(4.5).

   This is now the multiprecision package "MP" calculates gamma to
   arbitrary precision.

   - Jim
1971.4Haven't seen series for log(gamma(1+x)) yetEVMS::HALLYBFish have no concept of fireMon May 08 1995 16:069
1971.5WRKSYS::ROTHGeometry is the real life!Tue May 09 1995 10:31105