ANSI C99 and POSIX compliant compilers include functions tgamma and lgamma for computing the gamma function and its natural logarithm respectively. Visual Studio 2008, however, does not support these standards.

Found this fact during the last few weeks, so decided to explore these exotic mathematical functions which microsoft decided not to include in the visual studio 2008.

So lets start with the definition

Gamma function computes the the gamma function,. The gamma function is a shifted version of the ordinary factorial, satisfying for integers $ n > 0 $. More generally, it is defined by

for any real or complex with and for by analytic continuation.

LogGamma function computes the principal branch of the log-gamma function, Unlike , which has infinitely many complex branch cuts, the principal log-gamma function only has a single branch cut along the negative half-axis. The principal branch continuously matches the asymptotic Stirling expansion

The real parts of both functions agree, but their imaginary parts generally differ by for some .

They coincide for .

Computationally, it is advantageous to use loggamma() instead of gamma() for extremely large arguments.

Error Functions

Computes the error function, . The error function is the normalized antiderivative of the Gaussian function . More precisely,

Scipy provides ton of special functions. The error functions, the gamma functions are part of them. All of them are found in the scipy.special module

So lets see how they look like.

import scipy.special as sp
import numpy as np
import matplotlib.pyplot as plt
x=np.linspace(-4.5,6,6601)
# gamma function
g=sp.gamma(x)
g=np.ma.masked_outside(g,-200,400)
# plot
f, ax = plt.subplots(figsize=(10,5))
ax.plot(x,g)
ax.grid(True)

# loggamma function
g=sp.gammaln(x)
g=np.ma.masked_outside(g,-200,400)
#plot
f, ax = plt.subplots(figsize=(10,5))
ax.plot(x,g)
ax.grid(True)

# erf function
g=sp.erf(x)
g=np.ma.masked_outside(g,-200,400)
# plot
f, ax = plt.subplots(figsize=(10,5))
ax.plot(x,g)
ax.grid(True)

### Like this:

Like Loading...

*Related*