Subject: Gamma function
Date: 4 Feb 91 06:17:59 GMT
Organization: Lawrence Berkeley Laboratory (theoretical physics group)
Summary: Here's a program to compute gamma(z) for arbitrary complex z.
X-Local-Date: Sun, 3 Feb 91 22:17:59 PST
Lines: 51
 
The gamma function is one of the standard "special functions" of
complex analysis.  It is therefore a little bit frustrating to see
that the gamma function on the HP 48 only accepts real arguments.
(Not that I'm complaining, of course: HP is the only company I know
of that puts the gamma function on its calculators at all.)
 
The following program corrects this.  The algorithm isn't as accurate
as that on the HP 48, but it still is quite good: better than 1 part
in 10^9.

This program uses an algorithm from Numerical Recipes.  (Press, et.
al.) They give no theory behind the algorithm, besides the obvious
observation that it asymptotically approaches Stirling's
approximation, but they do give a reference.  It is only valid for
Re (z) > 1, so I use the "reflection formula" if given an argument
with Re(z) < 1.

You'll note that this program calls itself (in the reflection
formula), so you should either store it under the name GAMMA or
change that call.


--
Matthew Austern    austern@lbl.bitnet     Proverbs for paranoids, 3: If
(415) 644-2618     austern@lbl.gov        they can get you asking the wrong
                                          questions, they don't have to worry
                                          about answers.
