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_log_scaled_real (s14ah)

## Purpose

nag_specfun_gamma_log_scaled_real (s14ah) returns the value of $\mathrm{ln}G\left(x\right)$, the scaled logarithm of the gamma function $\Gamma \left(x\right)$, via the function name.

## Syntax

[result, ifail] = s14ah(x)
[result, ifail] = nag_specfun_gamma_log_scaled_real(x)

## Description

nag_specfun_gamma_log_scaled_real (s14ah) calculates an approximate value for $\mathrm{ln}G\left(x\right)$, where $G\left(x\right)=\Gamma \left(x+1\right)/{\left(\frac{x}{e}\right)}^{x}$. This is a variant of the $\mathrm{ln}\Gamma \left(x\right)$ function (see also nag_specfun_gamma_log_real (s14ab)), which avoids rounding problems for very large arguments by computing $\mathrm{ln}\Gamma \left(x\right)$ with the Stirling approximation factored out.
For $0, $\mathrm{ln}G\left(x\right)=\mathrm{ln}\Gamma \left(x+1\right)-x\mathrm{ln}x+x$;
and for $15\le x$, $\mathrm{ln}G\left(x\right)=\frac{1}{2}\mathrm{ln}x+\mathrm{ln}\left(\sqrt{2\pi }\right)+\frac{1}{x}R\left(1/{x}^{2}\right)$, where $R$ is a suitable Remez approximation.
For $x\le 0.0$, the value $\mathrm{ln}G\left(x\right)$ is undefined; nag_specfun_gamma_log_scaled_real (s14ah) returns zero and exits with ${\mathbf{ifail}}={\mathbf{1}}$.

## References

Abramowitz M and Stegun I A (1972) Handbook of Mathematical Functions (3rd Edition) Dover Publications

## Parameters

### Compulsory Input Parameters

1:     $\mathrm{x}$ – double scalar
The argument $x$ of the function.
Constraint: ${\mathbf{x}}>0.0$.

None.

### Output Parameters

1:     $\mathrm{result}$ – double 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, ${\mathbf{x}}\le 0.0$. On soft failure, the function value returned is zero.
${\mathbf{ifail}}=-99$
An unexpected error has been triggered by this routine. Please contact NAG.
${\mathbf{ifail}}=-399$
Your licence key may have expired or may not have been installed correctly.
${\mathbf{ifail}}=-999$
Dynamic memory allocation failed.

## Accuracy

nag_specfun_gamma_log_scaled_real (s14ah) has been designed to produce full relative accuracy for all input arguments. Empirical results obtained by comparing with multiprecision software confirm this.

None.

## Example

This example reads values of the argument $x$ from a file, evaluates the function at each value of $x$ and prints the results.
```function s14ah_example

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

x = [1, 1.25, 1.5, 1.75, 2, 5, 10, 20, 1000];
n = size(x,2);
result = x;

for j=1:n
[result(j), ifail] = s14ah(x(j));
end

disp('      x        ln G(x)');
fprintf('%12.3e%12.3e\n',[x; result]);

```
```s14ah example results

x        ln G(x)
1.000e+00   1.000e+00
1.250e+00   1.096e+00
1.500e+00   1.176e+00
1.750e+00   1.246e+00
2.000e+00   1.307e+00
5.000e+00   1.740e+00
1.000e+01   2.079e+00
2.000e+01   2.421e+00
1.000e+03   4.373e+00
```

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–2015