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


public static void s14ad(
	double x,
	int n,
	int m,
	double[] ans,
	out int ifail
Visual Basic
Public Shared Sub s14ad ( _
	x As Double, _
	n As Integer, _
	m As Integer, _
	ans As Double(), _
	<OutAttribute> ByRef ifail As Integer _
Visual C++
static void s14ad(
	double x, 
	int n, 
	int m, 
	array<double>^ ans, 
	[OutAttribute] int% ifail
static member s14ad : 
        x : float * 
        n : int * 
        m : int * 
        ans : float[] * 
        ifail : int byref -> unit 


Type: System..::..Double
On entry: the argument x of the function.
Constraint: x>0.0.
Type: System..::..Int32
On entry: the index of the first member n of the sequence of functions.
Constraint: n0.
Type: System..::..Int32
On entry: the number of members m required in the sequence wk,x, for k=n,,n+m-1.
Constraint: m1.
Type: array<System..::..Double>[]()[][]
An array of size [m]
On exit: the first m elements of ans contain the required values wk,x, for k=n,,n+m-1.
Type: System..::..Int32%
On exit: ifail=0 unless the method detects an error or a warning has been flagged (see [Error Indicators and Warnings]).


s14ad computes m values of the function
for x>0, k=n, n+1,,n+m-1, where ψ is the psi function
and ψk denotes the kth derivative of ψ.
The method is derived from the method PSIFN in Amos (1983). The basic method of evaluation of wk,x is the asymptotic series
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.


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

Error Indicators and Warnings

Errors or warnings detected by the method:
On entry,x0.0.
On entry,n<0.
On entry,m<1.
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 s14ad again.
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 s14ad again.
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 s14ad again.
An error occured, see message report.
Negative dimension for array value
Invalid Parameters value


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

Parallelism and Performance


Further Comments

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


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

Example program (C#): s14ade.cs

Example program data: s14ade.d

Example program results: s14ade.r

See Also