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

# Syntax

C# |
---|

public static void s14ba( double a, double x, double tol, out double p, out double q, out int ifail ) |

Visual Basic |
---|

Public Shared Sub s14ba ( _ a As Double, _ x As Double, _ tol As Double, _ <OutAttribute> ByRef p As Double, _ <OutAttribute> ByRef q As Double, _ <OutAttribute> ByRef ifail As Integer _ ) |

Visual C++ |
---|

public: static void s14ba( double a, double x, double tol, [OutAttribute] double% p, [OutAttribute] double% q, [OutAttribute] int% ifail ) |

F# |
---|

static member s14ba : a : float * x : float * tol : float * p : float byref * q : float byref * ifail : int byref -> unit |

#### Parameters

- a
- Type: System..::..Double
*On entry*: the argument $a$ of the functions.*Constraint*: ${\mathbf{a}}>0.0$.

- x
- Type: System..::..Double
*On entry*: the argument $x$ of the functions.*Constraint*: ${\mathbf{x}}\ge 0.0$.

- tol
- Type: System..::..Double

- p
- Type: System..::..Double%
*On exit*: the values of the functions $P\left(a,x\right)$ and $Q\left(a,x\right)$ respectively.

- q
- Type: System..::..Double%
*On exit*: the values of the functions $P\left(a,x\right)$ and $Q\left(a,x\right)$ respectively.

- ifail
- Type: System..::..Int32%
*On exit*: ${\mathbf{ifail}}={0}$ unless the method detects an error or a warning has been flagged (see [Error Indicators and Warnings]).

# Description

s14ba evaluates the incomplete gamma functions in the normalized form

with $x\ge 0$ and $a>0$, to a user-specified accuracy. With this normalization, $P\left(a,x\right)+Q\left(a,x\right)=1$.

$$P\left(a,x\right)=\frac{1}{\Gamma \left(a\right)}\underset{0}{\overset{x}{\int}}{t}^{a-1}{e}^{-t}dt\text{,}$$ |

$$Q\left(a,x\right)=\frac{1}{\Gamma \left(a\right)}\underset{x}{\overset{\infty}{\int}}{t}^{a-1}{e}^{-t}dt\text{,}$$ |

Several methods are used to evaluate the functions depending on the arguments $a$ and $x$, the methods including Taylor expansion for $P\left(a,x\right)$, Legendre's continued fraction for $Q\left(a,x\right)$, and power series for $Q\left(a,x\right)$. When both $a$ and $x$ are large, and $a\simeq x$, the uniform asymptotic expansion of Temme (1987) is employed for greater efficiency – specifically, this expansion is used when $a\ge 20$ and $0.7a\le x\le 1.4a$.

Once either $P$ or $Q$ is computed, the other is obtained by subtraction from $1$. In order to avoid loss of relative precision in this subtraction, the smaller of $P$ and $Q$ is computed first.

This method is derived from the method GAM in Gautschi (1979b).

# References

Gautschi W (1979a) A computational procedure for incomplete gamma functions

*ACM Trans. Math. Software***5**466–481Gautschi W (1979b) Algorithm 542: Incomplete gamma functions

*ACM Trans. Math. Software***5**482–489Temme 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# Error Indicators and Warnings

Errors or warnings detected by the method:

- ${\mathbf{ifail}}=1$
On entry, ${\mathbf{a}}\le 0.0$.

- ${\mathbf{ifail}}=2$
On entry, ${\mathbf{x}}<0.0$.

- ${\mathbf{ifail}}=3$
- Convergence of the Taylor series or Legendre continued fraction fails within $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$ decimal places on the achievable accuracy, because constants in the method are given to this precision.

# Parallelism and Performance

None.

# Further Comments

# Example

This example reads values of the argument $a$ and $x$ from a file, evaluates the function and prints the results.

Example program (C#): s14bae.cs