hide long namesshow long names
hide short namesshow short names
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(a,x) and Q(a,x)Q(a,x).

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))ta1etdt,
0
P(a,x)=1Γ(a) 0xta-1e-tdt,
Q(a,x) = 1/(Γ (a))ta 1etdt,
x
Q(a,x)=1Γ (a) xta- 1e-t dt,
with x0x0 and a > 0a>0, to a user-specified accuracy. With this normalization, P(a,x) + Q(a,x) = 1P(a,x)+Q(a,x)=1.
Several methods are used to evaluate the functions depending on the arguments aa and xx, the methods including Taylor expansion for P(a,x)P(a,x), Legendre's continued fraction for Q(a,x)Q(a,x), and power series for Q(a,x)Q(a,x). When both aa and xx are large, and axax, the uniform asymptotic expansion of Temme (1987) is employed for greater efficiency – specifically, this expansion is used when a20a20 and 0.7ax1.4a0.7ax1.4a.
Once either PP or QQ is computed, the other is obtained by subtraction from 11. In order to avoid loss of relative precision in this subtraction, the smaller of PP and QQ 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 aa of the functions.
Constraint: a > 0.0a>0.0.
2:     x – double scalar
The argument xx of the functions.
Constraint: x0.0x0.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.01.0 or less than machine precision, then the value of machine precision is used instead.

Optional Input Parameters

None.

Input Parameters Omitted from the MATLAB Interface

None.

Output Parameters

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

Error Indicators and Warnings

Errors or warnings detected by the function:
  ifail = 1ifail=1
On entry,a0.0a0.0.
  ifail = 2ifail=2
On entry,x < 0.0x<0.0.
  ifail = 3ifail=3
Convergence of the Taylor series or Legendre continued fraction fails within 600600 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 1818 decimal places on the achievable accuracy, because constants in the function are given to this precision.

Further Comments

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 aa and xx.

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