Post Reply 
Gamma Function Using Spouge's Method
08-20-2015, 12:36 PM
Post: #10
RE: Gamma Function Using Spouge's Methjod
(08-19-2015 05:32 PM)lcwright1964 Wrote:  I think I was once drawn to this pseudocode (edited by me to include Luschny's suggested simplification in the formula) which implements the Stieltjes continued fraction:

Stieltjes3Factorial(x)
y = x+1; p = 1;
while y < 7 do p = p*y; y = y+1; od;
r = exp(y*(log(y)-1)+1/(2*(6*y+1/(5*(y+1/(4*y))))));
if x < 7 then r = r/p fi;
return r*sqrt(2*Pi / y) end;

As far as I can see the last x<7 test can be omitted. I tried this in VBA for Excel:

Code:
Function Gamma(x)
y = x
p = 1
Do While y < 7
   p = p * y
   y = y + 1
Loop
r = Exp(y * (Log(y) - 1) + 1 / (2 * (6 * y + 1 / (5 * (y + 1 / (4 * y))))))
Gamma = 2.506628274631 * r / p / Sqr(y)
End Function

The constant in the last line is sqrt(2*pi). It turned out that the results seem to have not just eight but 10 valid digits, at least when evaluated with 15-digit precision. Only in some close cases I noticed that the 10th digit may be rounded down instead of up (e.g. for x=1,7 or 7,8). I'll try this one on my '41. ;-)

Thank you very much for reminding me of Peter Luschny's excellent Gamma/factorial pages.

Dieter
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
RE: Gamma Function Using Spouge's Methjod - Dieter - 08-20-2015 12:36 PM



User(s) browsing this thread: 1 Guest(s)