Skip to content

gammainc

specfun · scripts/specfun/gammainc.m

: y = gammainc (x, a)
: y = gammainc (x, a, tail)

Regularized incomplete gamma function.

With tail equal to "lower" (default) the function returns P(a,x) = 1/gamma(a) * integral_0^x t^(a-1) exp(-t) dt; with "upper" the complement Q(a,x) = 1 - P(a,x), evaluated directly so that tiny upper tails keep their relative accuracy. The options "scaledlower" and "scaledupper" return P or Q multiplied by gamma(a+1) * exp(x) / x^a, which stays representable when P or Q underflow.

x and a must be real, the same size or scalars, with x >= 0 and a >= 0. The result is single if either input is single.

Small a uses the power series and a continued fraction; for a >= 12 the integral is evaluated by Gauss-Legendre quadrature in a variable adapted to the peak of the integrand, which remains accurate for arbitrarily large arguments.