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

 Contents

    1  Purpose
    2  Syntax
    7  Accuracy
    9  Example

Purpose

nag_specfun_gamma_log_scaled_real (s14ah) returns the value of lnGx, the scaled logarithm of the gamma function Γx, 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 lnGx, where Gx=Γx+1/xex. This is a variant of the lnΓx function (see also nag_specfun_gamma_log_real (s14ab)), which avoids rounding problems for very large arguments by computing lnΓx with the Stirling approximation factored out.
For 0<x<15, lnGx=lnΓx+1-xlnx+x;
and for 15x, lnGx=12 lnx+ln2π+1xR1/x2, where R is a suitable Remez approximation.
For x0.0, the value lnGx is undefined; nag_specfun_gamma_log_scaled_real (s14ah) returns zero and exits with ifail=1.

References

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

Parameters

Compulsory Input Parameters

1:     x – double scalar
The argument x of the function.
Constraint: x>0.0.

Optional Input Parameters

None.

Output Parameters

1:     result – double scalar
The result of the function.
2:     ifail int64int32nag_int scalar
ifail=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
On entry, x0.0. On soft failure, the function value returned is zero.
   ifail=-99
An unexpected error has been triggered by this routine. Please contact NAG.
   ifail=-399
Your licence key may have expired or may not have been installed correctly.
   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.

Further Comments

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