S14ADF (PDF version)
S Chapter Contents
S Chapter Introduction
NAG Library Manual

NAG Library Routine Document

S14ADF

Note:  before using this routine, please read the Users' Note for your implementation to check the interpretation of bold italicised terms and other implementation-dependent details.

 Contents

    1  Purpose
    7  Accuracy

1  Purpose

S14ADF returns a sequence of values of scaled derivatives of the psi function ψx (also known as the digamma function).

2  Specification

SUBROUTINE S14ADF ( X, N, M, ANS, IFAIL)
INTEGER  N, M, IFAIL
REAL (KIND=nag_wp)  X, ANS(M)

3  Description

S14ADF computes m values of the function
wk,x=-1k+1ψ k x k! ,  
for x>0, k=n, n+1,,n+m-1, where ψ is the psi function
ψx=ddx lnΓx=Γx Γx ,  
and ψ k  denotes the kth derivative of ψ.
The routine is derived from the routine PSIFN in Amos (1983). The basic method of evaluation of wk,x is the asymptotic series
wk,xεk,x+12xk+1 +1xkj=1B2j2j+k-1! 2j!k!x2j  
for large x greater than a machine-dependent value xmin, followed by backward recurrence using
wk,x=wk,x+1+x-k-1  
for smaller values of x, where εk,x=-lnx when k=0, εk,x= 1kxk  when k>0, and B2j, j=1,2,, are the Bernoulli numbers.
When k is large, the above procedure may be inefficient, and the expansion
wk,x=j=11x+jk+1,  
which converges rapidly for large k, is used instead.

4  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

5  Parameters

1:     X – REAL (KIND=nag_wp)Input
On entry: the argument x of the function.
Constraint: X>0.0.
2:     N – INTEGERInput
On entry: the index of the first member n of the sequence of functions.
Constraint: N0.
3:     M – INTEGERInput
On entry: the number of members m required in the sequence wk,x, for k=n,,n+m-1.
Constraint: M1.
4:     ANSM – REAL (KIND=nag_wp) arrayOutput
On exit: the first m elements of ANS contain the required values wk,x, for k=n,,n+m-1.
5:     IFAIL – INTEGERInput/Output
On entry: IFAIL must be set to 0, -1​ or ​1. If you are unfamiliar with this parameter you should refer to Section 3.3 in the Essential Introduction for details.
For environments where it might be inappropriate to halt program execution when an error is detected, the value -1​ or ​1 is recommended. If the output of error messages is undesirable, then the value 1 is recommended. Otherwise, if you are not familiar with this parameter, the recommended value is 0. When the value -1​ or ​1 is used it is essential to test the value of IFAIL on exit.
On exit: IFAIL=0 unless the routine detects an error or a warning has been flagged (see Section 6).

6  Error Indicators and Warnings

If on entry IFAIL=0 or -1, explanatory error messages are output on the current error message unit (as defined by X04AAF).
Errors or warnings detected by the routine:
IFAIL=1
On entry,X0.0.
IFAIL=2
On entry,N<0.
IFAIL=3
On entry,M<1.
IFAIL=4
No results are returned because underflow is likely. Either X or N+M-1 is too large. If possible, reduce the value of M and call S14ADF again.
IFAIL=5
No results are returned because overflow is likely. Either X is too small, or N+M-1 is too large. If possible, reduce the value of M and call S14ADF again.
IFAIL=6
No results are returned because there is not enough internal workspace to continue computation. N+M-1 may be too large. If possible, reduce the value of M and call S14ADF again.
IFAIL=-99
An unexpected error has been triggered by this routine. Please contact NAG.
See Section 3.8 in the Essential Introduction for further information.
IFAIL=-399
Your licence key may have expired or may not have been installed correctly.
See Section 3.7 in the Essential Introduction for further information.
IFAIL=-999
Dynamic memory allocation failed.
See Section 3.6 in the Essential Introduction for further information.

7  Accuracy

All constants in S14ADF 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. Empirical tests of S14ADF, taking values of x in the range 0.0<x<50.0, and n in the range 1n50, have shown that the maximum relative error is a loss of approximately two decimal places of precision. Tests with n=0, i.e., testing the function -ψx, have shown somewhat better accuracy, except at points close to the zero of ψx, x1.461632, where only absolute accuracy can be obtained.

8  Parallelism and Performance

Not applicable.

9  Further Comments

The time taken for a call of S14ADF is approximately proportional to m, plus a constant. In general, it is much cheaper to call S14ADF with m greater than 1 to evaluate the function wk,x, for k=n,,n+m-1, rather than to make m separate calls of S14ADF.

10  Example

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

10.1  Program Text

Program Text (s14adfe.f90)

10.2  Program Data

Program Data (s14adfe.d)

10.3  Program Results

Program Results (s14adfe.r)


S14ADF (PDF version)
S Chapter Contents
S Chapter Introduction
NAG Library Manual

© The Numerical Algorithms Group Ltd, Oxford, UK. 2015