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

Chapter Contents
Chapter Introduction
NAG Toolbox

# NAG Toolbox: nag_specfun_gamma_log_complex (s14ag)

## Purpose

nag_specfun_gamma_log_complex (s14ag) returns the value of the logarithm of the gamma function $\mathrm{ln}\Gamma \left(z\right)$ for complex $z$, via the function name.

## Syntax

[result, ifail] = s14ag(z)
[result, ifail] = nag_specfun_gamma_log_complex(z)

## Description

nag_specfun_gamma_log_complex (s14ag) evaluates an approximation to the logarithm of the gamma function $\mathrm{ln}\Gamma \left(z\right)$ defined for $\mathrm{Re}\left(z\right)>0$ by
 $ln⁡Γz=ln⁡∫0∞e-ttz-1dt$
where $z=x+iy$ is complex. It is extended to the rest of the complex plane by analytic continuation unless $y=0$, in which case $z$ is real and each of the points $z=0,-1,-2,\dots \text{}$ is a singularity and a branch point.
nag_specfun_gamma_log_complex (s14ag) is based on the method proposed by Kölbig (1972) in which the value of $\mathrm{ln}\Gamma \left(z\right)$ is computed in the different regions of the $z$ plane by means of the formulae
 $ln⁡Γz = z-12ln⁡z-z+12ln⁡2π+z∑k=1K B2k2k2k-1 z-2k+RKz if ​x≥x0≥0, = ln⁡Γz+n-ln⁡∏ν=0 n-1z+ν if ​x0>x≥0, = ln⁡π-ln⁡Γ1-z-lnsin⁡πz if ​x<0,$
where $n=\left[{x}_{0}\right]-\left[x\right]$, $\left\{{B}_{2k}\right\}$ are Bernoulli numbers (see Abramowitz and Stegun (1972)) and $\left[x\right]$ is the largest integer $\text{}\le x$. Note that care is taken to ensure that the imaginary part is computed correctly, and not merely modulo $2\pi$.
The function uses the values $K=10$ and ${x}_{0}=7$. The remainder term ${R}_{K}\left(z\right)$ is discussed in Accuracy.
To obtain the value of $\mathrm{ln}\Gamma \left(z\right)$ when $z$ is real and positive, nag_specfun_gamma_log_real (s14ab) can be used.

## References

Abramowitz M and Stegun I A (1972) Handbook of Mathematical Functions (3rd Edition) Dover Publications
Kölbig K S (1972) Programs for computing the logarithm of the gamma function, and the digamma function, for complex arguments Comp. Phys. Comm. 4 221–226

## Parameters

### Compulsory Input Parameters

1:     $\mathrm{z}$ – complex scalar
The argument $z$ of the function.
Constraint: $\mathrm{Re}\left({\mathbf{z}}\right)$ must not be ‘too close’ (see Error Indicators and Warnings) to a non-positive integer when $\mathrm{Im}\left({\mathbf{z}}\right)=0.0$.

None.

### Output Parameters

1:     $\mathrm{result}$ – complex scalar
The result of the function.
2:     $\mathrm{ifail}$int64int32nag_int scalar
${\mathbf{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:
${\mathbf{ifail}}=1$
On entry, $\mathrm{Re}\left({\mathbf{z}}\right)$ is ‘too close’ to a non-positive integer when $\mathrm{Im}\left({\mathbf{z}}\right)=0.0$. That is, .
${\mathbf{ifail}}=-99$
${\mathbf{ifail}}=-399$
Your licence key may have expired or may not have been installed correctly.
${\mathbf{ifail}}=-999$
Dynamic memory allocation failed.

## Accuracy

The remainder term ${R}_{K}\left(z\right)$ satisfies the following error bound:
 $RKz ≤ B2K 2K-1 z1-2K ≤ B2K 2K-1 x1-2Kif ​x≥0.$
Thus $\left|{R}_{10}\left(7\right)\right|<2.5×{10}^{-15}$ and hence in theory the function is capable of achieving an accuracy of approximately $15$ significant digits.

None.

## Example

This example evaluates the logarithm of the gamma function $\mathrm{ln}\Gamma \left(z\right)$ at $z=-1.5+2.5i$, and prints the results.
```function s14ag_example

fprintf('s14ag example results\n\n');

z =  -1.5 + 2.5i;
[lgz, ifail] = s14ag(z);

disp('      z           ln(Gamma(z))');
fprintf('%5.1f%+5.1fi', real(z), imag(z));
fprintf('  %12.4e%+12.4ei\n', real(lgz), imag(lgz));

```
```s14ag example results

z           ln(Gamma(z))
-1.5 +2.5i   -5.0140e+00 -4.0718e+00i
```