I have forgotten
my Password

Or login with:

  • Facebookhttp://facebook.com/
  • Googlehttps://www.google.com/accounts/o8/id
  • Yahoohttps://me.yahoo.com
get GPL
COST (GBP)
this unit 5.62
sub units 0.50
+
0
MathsSpecialGamma

log gamma stirling

viewed 2354 times and licensed 58 times
Natural Logarithm of Gamma function
Controller: CodeCogs

Dependents

Info

Interface

C++

Log Gamma Stirling

 
doublelog_gamma_stirlingdoublex
int*sign = NULL )
The logarithm of the gamma function is sometimes treated as a special function to avoid additional 'branch cut' stuctures that are introduced by the logarithm function (see http://mathworld.wolfram.com/LogGammaFunction.html )

The log-gamma function can be defined by

Stirling series (in its normal form) also provides a solution, given by a simple analytic expression

The function returns the base e (2.718...) logarithm of the absolute value of the gamma function of the argument.

The sign (+1 or -1) of the gamma function is returned in a global (extern) variable named sgngam.

For arguments greater than 13, the logarithm of the gamma function is approximated by the logarithmic version of Stirling's formula using a polynomial approximation of degree 4. Arguments between -33 and +33 are reduced by recurrence to the interval [2,3] of a rational approximation.

The cosecant reflection formula is employed for arguments less than -33.

Arguments greater than MAXLGM return MAXNUM and an error message. MAXLGM = 2.035093e36 for DEC arithmetic or 2.556348e305 for IEEE arithmetic.

Accuracy:

<pre> domain # trials peak rms 0, 3 28000 5.4e-16 1.1e-16 2.718, 2.556e305 40000 3.5e-16 8.3e-17 </pre> The error criterion was relative when the function magnitude was greater than one but absolute when it was less than one.

Example:

#include <codecogs/maths/special/gamma/log_gamma_stirling.h>
#include <stdio.h>
 
int main()
{
  for(double x=10; x<=20; x+=0.5)
    printf("\n x=%lf log_gamma_stirling(x)=%lf",x, Maths::Special::Gamma::log_gamma_stirling(x));
}

Output:

x=10.000000 log_gamma_stirling(x)=12.801827
x=10.500000 log_gamma_stirling(x)=13.940625
x=11.000000 log_gamma_stirling(x)=15.104413
x=11.500000 log_gamma_stirling(x)=16.292000
x=12.000000 log_gamma_stirling(x)=17.502308
x=12.500000 log_gamma_stirling(x)=18.734348
x=13.000000 log_gamma_stirling(x)=19.987214
x=13.500000 log_gamma_stirling(x)=21.260076
x=14.000000 log_gamma_stirling(x)=22.552164
x=14.500000 log_gamma_stirling(x)=23.862766
x=15.000000 log_gamma_stirling(x)=25.191221
x=15.500000 log_gamma_stirling(x)=26.536914
x=16.000000 log_gamma_stirling(x)=27.899271
x=16.500000 log_gamma_stirling(x)=29.277755
x=17.000000 log_gamma_stirling(x)=30.671860
x=17.500000 log_gamma_stirling(x)=32.081115
x=18.000000 log_gamma_stirling(x)=33.505073
x=18.500000 log_gamma_stirling(x)=34.943316
x=19.000000 log_gamma_stirling(x)=36.395445
x=19.500000 log_gamma_stirling(x)=37.861087
x=20.000000 log_gamma_stirling(x)=39.339884

References:

  • Cephes Math Library Release 2.8: June, 2000
  • http://mathworld.wolfram.com/LogGammaFunction.html

Parameters

xis primary argument.
signis a pointer to a variable, into which the sign of the solution is placed, if sign not equal to NULL (default=NULL).

Authors

Stephen L.Moshier. Copyright 1984, 1987, 1989, 1992, 2000
Updated by Will Bateman
Source Code

Source code is available when you agree to a GP Licence or buy a Commercial Licence.

Not a member, then Register with CodeCogs. Already a Member, then Login.