SuanShu, a Java numerical and statistical library

com.numericalmethod.suanshu.analysis.function.special
Class Gamma

java.lang.Object
  extended by com.numericalmethod.suanshu.analysis.function.rn2r1.UnivariateRealFunction
      extended by com.numericalmethod.suanshu.analysis.function.special.Gamma
All Implemented Interfaces:
Function, RealScalarFunction

public class Gamma
extends UnivariateRealFunction

This computes an approximation to the Gamma function, Γ(z), for real numbers.

       ∞
       /
 Γ(z)= | tz-1e-t dt
       /
       0
 

Γ(z) is an extension of the factorial function to real and complex numbers, with its argument shifted down by 1.

We provide a few ways to compute Γ(z). Each method differs in accuracy and speed. For example,

The full Lanczos approximation can be made arbitrarily precise because it is computed using BigDecimal.

The quick Lanczos approximation is quick but could be less precise because the computations are done in double precision.

See Also:

Nested Class Summary
static class Gamma.Method
          the methods available to compute Γ(z)
 
Nested classes/interfaces inherited from interface com.numericalmethod.suanshu.analysis.function.Function
Function.EvaluationException
 
Constructor Summary
Gamma()
          Construct an instance to compute for Gamma function using Lanczos approximation with default settings.
Gamma(double g, int n, int scale)
          Construct an instance to compute for Gamma function using Lanczos approximation.
Gamma(Gamma.Method method)
          Construct an instance to compute for Gamma function using a specified method with default settings.
 
Method Summary
 double evaluate(double x)
          Compute for the Gamma function in the Real domain.
 
Methods inherited from class com.numericalmethod.suanshu.analysis.function.rn2r1.UnivariateRealFunction
dimension4Domain, dimension4Range, evaluate
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Gamma

public Gamma()
Construct an instance to compute for Gamma function using Lanczos approximation with default settings.

See Also:
Wikipedia: Lanczos approximation

Gamma

public Gamma(double g,
             int n,
             int scale)
Construct an instance to compute for Gamma function using Lanczos approximation.

Recommended settings are

g = 607.0 / 128.0 n = 15 scale = 30

Parameters:
g - g
n - n
scale - precision
See Also:
Wikipedia: Lanczos approximation

Gamma

public Gamma(Gamma.Method method)
Construct an instance to compute for Gamma function using a specified method with default settings.

Parameters:
method - the algorithm to use, c.f., Gamma.Method
Method Detail

evaluate

public double evaluate(double x)
Compute for the Gamma function in the Real domain.

Specified by:
evaluate in class UnivariateRealFunction
Parameters:
x - a real number
Returns:
Γ(x)

SuanShu, a Java numerical and statistical library

Copyright © 2011 Numerical Method Inc. Ltd. All Rights Reserved.