NAG CL Interface
s14adc (polygamma_​deriv)

1 Purpose

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

2 Specification

#include <nag.h>
void  s14adc (double x, Integer n, Integer m, double ans[], NagError *fail)
The function may be called by the names: s14adc, nag_specfun_polygamma_deriv or nag_polygamma_deriv.

3 Description

s14adc 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 function is derived from the function 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
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
which converges rapidly for large k, is used instead.

4 References

NIST Digital Library of Mathematical Functions
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 double Input
On entry: the argument x of the function.
Constraint: x>0.0.
2: n Integer Input
On entry: the index of the first member n of the sequence of functions.
Constraint: n0.
3: m Integer Input
On entry: the number of members m required in the sequence wk,x, for k=n,,n+m-1.
Constraint: m1.
4: ans[m] double Output
On exit: the first m elements of ans contain the required values wk,x, for k=n,,n+m-1.
5: fail NagError * Input/Output
The NAG error argument (see Section 7 in the Introduction to the NAG Library CL Interface).

6 Error Indicators and Warnings

Dynamic memory allocation failed.
See Section 3.1.2 in the Introduction to the NAG Library CL Interface for further information.
On entry, argument value had an illegal value.
On entry, m=value.
Constraint: m1.
On entry, n=value.
Constraint: n0.
An internal error has occurred in this function. Check the function call and any array sizes. If the call is correct then please contact NAG for assistance.
See Section 7.5 in the Introduction to the NAG Library CL Interface for further information.
There is not enough internal workspace to continue computation. m is probably too large.
Your licence key may have expired or may not have been installed correctly.
See Section 8 in the Introduction to the NAG Library CL Interface for further information.
Computation abandoned due to the likelihood of overflow.
On entry, x=value.
Constraint: x>0.0.
Computation abandoned due to the likelihood of underflow.

7 Accuracy

All constants in s14adc 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 s14adc, 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

s14adc is not threaded in any implementation.

9 Further Comments

The time taken for a call of s14adc is approximately proportional to m, plus a constant. In general, it is much cheaper to call s14adc 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 s14adc.

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 (s14adce.c)

10.2 Program Data

Program Data (s14adce.d)

10.3 Program Results

Program Results (s14adce.r)