NAG FL Interface
s14aef (psi_​deriv_​real)

1 Purpose

s14aef returns the value of the kth derivative of the psi function ψx for real x and k=0,1,,6, via the function name.

2 Specification

Fortran Interface
Function s14aef ( x, k, ifail)
Real (Kind=nag_wp) :: s14aef
Integer, Intent (In) :: k
Integer, Intent (Inout) :: ifail
Real (Kind=nag_wp), Intent (In) :: x
C Header Interface
#include <nag.h>
double  s14aef_ (const double *x, const Integer *k, Integer *ifail)
The routine may be called by the names s14aef or nagf_specfun_psi_deriv_real.

3 Description

s14aef evaluates an approximation to the kth derivative of the psi function ψx given by
ψ k x=dkdxk ψx=dkdxk ddx logeΓx ,  
where x is real with x0,-1,-2, and k=0,1,,6. For negative noninteger values of x, the recurrence relationship
ψ k x+1=ψ k x+dkdxk 1x  
is used. The value of -1k+1ψ k x k! is obtained by a call to s14adf, which is based on the routine PSIFN in Amos (1983).
Note that ψ k x is also known as the polygamma function. Specifically, ψ 0 x is often referred to as the digamma function and ψ 1 x as the trigamma function in the literature. Further details can be found in Abramowitz and Stegun (1972).

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 Arguments

1: x Real (Kind=nag_wp) Input
On entry: the argument x of the function.
Constraint: x must not be ‘too close’ (see Section 6) to a non-positive integer.
2: k Integer Input
On entry: the function ψkx to be evaluated.
Constraint: 0k6.
3: ifail Integer Input/Output
On entry: ifail must be set to 0, -1 or 1. If you are unfamiliar with this argument you should refer to Section 4 in the Introduction to the NAG Library FL Interface 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 argument, 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:
On entry, k=value.
Constraint: k6.
On entry, k=value.
Constraint: k0.
On entry, x is ‘too close’ to a non-positive integer: x=value and nintx=value.
Evaluation abandoned due to likelihood of underflow.
Evaluation abandoned due to likelihood of overflow.
An unexpected error has been triggered by this routine. Please contact NAG.
See Section 7 in the Introduction to the NAG Library FL Interface for further information.
Your licence key may have expired or may not have been installed correctly.
See Section 8 in the Introduction to the NAG Library FL Interface for further information.
Dynamic memory allocation failed.
See Section 9 in the Introduction to the NAG Library FL Interface for further information.

7 Accuracy

All constants in s14adf are given to approximately 18 digits of precision. If t denotes the number of digits of precision in the floating-point arithmetic being used, then clearly the maximum number in the results obtained is limited by p=mint,18. Empirical tests by Amos (1983) have shown that the maximum relative error is a loss of approximately two decimal places of precision. Further tests with the function -ψ 0 x have shown somewhat improved accuracy, except at points near the positive zero of ψ 0 x at x=1.46, where only absolute accuracy can be obtained.

8 Parallelism and Performance

s14aef is not threaded in any implementation.

9 Further Comments


10 Example

This example evaluates ψ 2 x at x=2.5, and prints the results.

10.1 Program Text

Program Text (s14aefe.f90)

10.2 Program Data

Program Data (s14aefe.d)

10.3 Program Results

Program Results (s14aefe.r)