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_polygamma (s14ac)

 Contents

    1  Purpose
    2  Syntax
    7  Accuracy
    9  Example

Purpose

nag_specfun_polygamma (s14ac) returns a value of the function ψx-lnx, where ψ is the psi function ψx= ddx lnΓx= Γx Γx .

Syntax

[result, ifail] = s14ac(x)
[result, ifail] = nag_specfun_polygamma(x)

Description

nag_specfun_polygamma (s14ac) returns a value of the function ψx-lnx. The psi function is computed without the logarithmic term so that when x is large, sums or differences of psi functions may be computed without unnecessary loss of precision, by analytically combining the logarithmic terms. For example, the difference d=ψ x+12-ψx has an asymptotic behaviour for large x given by dlnx+12-lnx+O 1x2ln1+ 12x 12x .
Computing d directly would amount to subtracting two large numbers which are close to lnx+12  and lnx to produce a small number close to 12x , resulting in a loss of significant digits. However, using this function to compute fx=ψx-lnx, we can compute d=f x+12-fx+ln1+12x , and the dominant logarithmic term may be computed accurately from its power series when x is large. Thus we avoid the unnecessary loss of precision.
The function is derived from the function PSIFN in Amos (1983).

References

Abramowitz M and Stegun I A (1972) Handbook of Mathematical Functions (3rd Edition) Dover Publications
Amos D E (1983) Algorithm 610: A portable FORTRAN subroutine for derivatives of the psi function ACM Trans. Math. Software 9 494–502

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. nag_specfun_polygamma (s14ac) returns the value zero.
   ifail=2
No result is computed because underflow is likely. The value of x is too large. nag_specfun_polygamma (s14ac) returns the value zero.
   ifail=3
No result is computed because overflow is likely. The value of x is too small. nag_specfun_polygamma (s14ac) returns the value 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

All constants in nag_specfun_polygamma (s14ac) are given to approximately 18 digits of precision. Calling the number of digits of precision in the floating-point arithmetic being used t, then clearly the maximum number of correct digits in the results obtained is limited by p=mint,18.
With the above proviso, results returned by this function should be accurate almost to full precision, except at points close to the zero of ψx, x1.461632, where only absolute rather than relative accuracy can be obtained.

Further Comments

None.

Example

The example program reads values of the argument x from a file, evaluates the function at each value of x and prints the results.
function s14ac_example


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

x = [0.1  0.5  3.6  8];
n = size(x,2);
result = x;

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

disp('        x      Psi(x)-ln(x)');
fprintf('%12.4f%12.4f\n',[x; result]);

s14ac_plot;



function s14ac_plot
  x = [0.1:0.1:8];

  for j=1:numel(x)
    [pml(j), ifail] = s14ac(x(j));
  end

  fig1 = figure;
  plot(x,pml,'-r');
  xlabel('x');
  ylabel('\Psi(x) - ln(x)');
  title('\Psi(x) - ln(x)');
  axis([0 8 -7 0]);

s14ac example results

        x      Psi(x)-ln(x)
      0.1000     -8.1212
      0.5000     -1.2704
      3.6000     -0.1453
      8.0000     -0.0638
s14ac_fig1.png

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