Gamma function valid in the entire complex plane.

gammaz(z)

Arguments

z

Real or complex number or a numeric or complex vector.

Details

Computes the Gamma function for complex arguments using the Lanczos series approximation.

Accuracy is 15 significant digits along the real axis and 13 significant digits elsewhere.

To compute the logarithmic Gamma function use log(gammaz(z)).

Value

Returns a complex vector of function values.

References

Zhang, Sh., and J. Jin (1996). Computation of Special Functions. Wiley-Interscience, New York.

Note

Copyright (c) 2001 Paul Godfrey for a Matlab version available on Mathwork's Matlab Central under BSD license.

Numerical Recipes used a 7 terms formula for a less effective approximation.

See also

gamma, gsl::lngamma_complex

Examples

max(gamma(1:10) - gammaz(1:10))
#> [1] 9.094947e-13
gammaz(-1)
#> [1] Inf
gammaz(c(-2-2i, -1-1i, 0, 1+1i, 2+2i))
#> [1]  0.01089768-0.005282966i -0.17153292-0.326482748i         Inf+0.000000000i
#> [4]  0.49801567-0.154949828i  0.11229424+0.323612886i

# Euler's reflection formula
z <- 1+1i
gammaz(1-z) * gammaz(z)  # == pi/sin(pi*z)
#> [1] 5.134781e-16+0.2720291i