Integer type:  int32  int64  nag_int  show int32  show int32  show int64  show int64  show nag_int  show nag_int

PDF version (NAG web site, 64-bit version, 64-bit version)
Chapter Contents
Chapter Introduction
NAG Toolbox

# NAG Toolbox: nag_specfun_gamma_incomplete (s14ba)

## Purpose

nag_specfun_gamma_incomplete (s14ba) computes values for the incomplete gamma functions P(a,x)$P\left(a,x\right)$ and Q(a,x)$Q\left(a,x\right)$.

## Syntax

[p, q, ifail] = s14ba(a, x, tol)
[p, q, ifail] = nag_specfun_gamma_incomplete(a, x, tol)

## Description

nag_specfun_gamma_incomplete (s14ba) evaluates the incomplete gamma functions in the normalized form
 x P(a,x) = 1/(Γ(a)) ∫ ta − 1e − tdt, 0
$P(a,x)=1Γ(a) ∫0xta-1e-tdt,$
 ∞ Q(a,x) = 1/(Γ (a)) ∫ ta − 1e − tdt, x
$Q(a,x)=1Γ (a) ∫x∞ta- 1e-t dt,$
with x0$x\ge 0$ and a > 0$a>0$, to a user-specified accuracy. With this normalization, P(a,x) + Q(a,x) = 1$P\left(a,x\right)+Q\left(a,x\right)=1$.
Several methods are used to evaluate the functions depending on the arguments a$a$ and x$x$, the methods including Taylor expansion for P(a,x)$P\left(a,x\right)$, Legendre's continued fraction for Q(a,x)$Q\left(a,x\right)$, and power series for Q(a,x)$Q\left(a,x\right)$. When both a$a$ and x$x$ are large, and ax$a\simeq x$, the uniform asymptotic expansion of Temme (1987) is employed for greater efficiency – specifically, this expansion is used when a20$a\ge 20$ and 0.7ax1.4a$0.7a\le x\le 1.4a$.
Once either P$P$ or Q$Q$ is computed, the other is obtained by subtraction from 1$1$. In order to avoid loss of relative precision in this subtraction, the smaller of P$P$ and Q$Q$ is computed first.
This function is derived from the function GAM in Gautschi (1979b).

## References

Gautschi W (1979a) A computational procedure for incomplete gamma functions ACM Trans. Math. Software 5 466–481
Gautschi W (1979b) Algorithm 542: Incomplete gamma functions ACM Trans. Math. Software 5 482–489
Temme N M (1987) On the computation of the incomplete gamma functions for large values of the parameters Algorithms for Approximation (eds J C Mason and M G Cox) Oxford University Press

## Parameters

### Compulsory Input Parameters

1:     a – double scalar
The argument a$a$ of the functions.
Constraint: a > 0.0${\mathbf{a}}>0.0$.
2:     x – double scalar
The argument x$x$ of the functions.
Constraint: x0.0${\mathbf{x}}\ge 0.0$.
3:     tol – double scalar
The relative accuracy required by you in the results. If nag_specfun_gamma_incomplete (s14ba) is entered with tol greater than 1.0$1.0$ or less than machine precision, then the value of machine precision is used instead.

None.

None.

### Output Parameters

1:     p – double scalar
2:     q – double scalar
The values of the functions P(a,x)$P\left(a,x\right)$ and Q(a,x)$Q\left(a,x\right)$ respectively.
3:     ifail – int64int32nag_int scalar
${\mathrm{ifail}}={\mathbf{0}}$ unless the function detects an error (see [Error Indicators and Warnings]).

## Error Indicators and Warnings

Errors or warnings detected by the function:
ifail = 1${\mathbf{ifail}}=1$
 On entry, a ≤ 0.0${\mathbf{a}}\le 0.0$.
ifail = 2${\mathbf{ifail}}=2$
 On entry, x < 0.0${\mathbf{x}}<0.0$.
ifail = 3${\mathbf{ifail}}=3$
Convergence of the Taylor series or Legendre continued fraction fails within 600$600$ iterations. This error is extremely unlikely to occur; if it does, contact NAG.

## Accuracy

There are rare occasions when the relative accuracy attained is somewhat less than that specified by parameter tol. However, the error should never exceed more than one or two decimal places. Note also that there is a limit of 18$18$ decimal places on the achievable accuracy, because constants in the function are given to this precision.

The time taken for a call of nag_specfun_gamma_incomplete (s14ba) depends on the precision requested through tol, and also varies slightly with the input arguments a$a$ and x$x$.

## Example

```function nag_specfun_gamma_incomplete_example
a = 2;
x = 3;
tol = 1.111307226797642e-16;
[p, q, ifail] = nag_specfun_gamma_incomplete(a, x, tol)
```
```

p =

0.8009

q =

0.1991

ifail =

0

```
```function s14ba_example
a = 2;
x = 3;
tol = 1.111307226797642e-16;
[p, q, ifail] = s14ba(a, x, tol)
```
```

p =

0.8009

q =

0.1991

ifail =

0

```

PDF version (NAG web site, 64-bit version, 64-bit version)
Chapter Contents
Chapter Introduction
NAG Toolbox

© The Numerical Algorithms Group Ltd, Oxford, UK. 2009–2013