gamma

From DavinciWiki
Jump to: navigation, search

Description

Gamma function (extended factorial).

Arguments and Return Values

Arguments: One numeric array

Return Value: An array of the same organization as the input, containing the gamma function evaluated at each element of the input.

gamma(n) = fact(n-1) = (n-1)! for positive integers and half-integers

gamma(x) = Γ(x) = integral from zero to infinity of t^(x-1)*exp(-t) with respect to t

Γ(x+1) = x*Γ(x)

The gamma function is undefined (infinite) for negative integers and zero. This function returns zero for those values.

This function uses a numerical approximation from W. J. Cody and L. Stoltz, which is accurate to the precision of the input.

Return format is double for double input; float otherwise.

If no arguments are input, gamma() prints its description, as shown below.

Usage

Syntax: gamma(x)

'x' - any numeric array

If x is double format, gamma(x) for x > 171 evaluates to infinity, since the calculated value is greater than the maximum double value.

If x is not double format, gamma(x) for x > 35 evaluates to infinity, being above the maximum float value.

Examples

dv> gamma()

Gamma function - extended factorial
gamma(x) = fact(x-1)
gamma(x) = integral from 0 to Inf of t^(x-1)*exp(-t) dt
gamma(x+1) = x*gamma(x)
Accurate within precision of input
Works for arrays
This function uses an algorithm from W. J. Cody and L. Stoltz
See http://www.netlib.org/specfun/gamma
S.Marshall 02-22-2008

0
dv> x
10x1x1 array of float, bsq format [40 bytes]
0.500000        1.00000 1.50000 2.00000 2.50000 3.00000 3.50000 4.00000 4.50000 5.00000
dv> gamma(x)
10x1x1 array of float, bsq format [40 bytes]
1.77245 1.00000 0.886227        1.00000 1.32934 2.00000 3.32335 6.00000 11.6317 24.0000
dv> gamma(0)
Division by zero, 1 times

Negative integers and zero are not allowed! Output set to zero at those values.

0.00000
dv> gamma(35//36)
2x1x1 array of float, bsq format [8 bytes]
2.95232e+38     inf

DavinciWiki Mini-Nav Bar

Contents


Contact Developers

  • davinci-dev [AT] mars.asu.edu

All other topics

  • See navigation on the left

Major Sub-Functions

Related Functions

Recent Library Changes

Created On: 02-22-2008
Modified On: 02-26-2008

Personal tools