# NAG FL Interfaces14aef (psi_​deriv_​real)

## ▸▿ Contents

Settings help

FL Name Style:

FL Specification Language:

## 1Purpose

s14aef returns the value of the $k$th derivative of the psi function $\psi \left(x\right)$ for real $x$ and $k=0,1,\dots ,6$, via the function name.

## 2Specification

Fortran Interface
 Function s14aef ( x, k,
 Real (Kind=nag_wp) :: s14aef Integer, Intent (In) :: k Integer, Intent (Inout) :: ifail Real (Kind=nag_wp), Intent (In) :: x
#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.

## 3Description

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

## 4References

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

## 5Arguments

1: $\mathbf{x}$Real (Kind=nag_wp) Input
On entry: the argument $x$ of the function.
Constraint: ${\mathbf{x}}$ must not be ‘too close’ (see Section 6) to a non-positive integer.
2: $\mathbf{k}$Integer Input
On entry: the function ${\psi }^{\left(k\right)}\left(x\right)$ to be evaluated.
Constraint: $0\le {\mathbf{k}}\le 6$.
3: $\mathbf{ifail}$Integer Input/Output
On entry: ifail must be set to $0$, $-1$ or $1$ to set behaviour on detection of an error; these values have no effect when no error is detected.
A value of $0$ causes the printing of an error message and program execution will be halted; otherwise program execution continues. A value of $-1$ means that an error message is printed while a value of $1$ means that it is not.
If halting is not appropriate, the value $-1$ or $1$ is recommended. If message printing is undesirable, then the value $1$ is recommended. Otherwise, the value $0$ is recommended. When the value $-\mathbf{1}$ or $\mathbf{1}$ is used it is essential to test the value of ifail on exit.
On exit: ${\mathbf{ifail}}={\mathbf{0}}$ unless the routine detects an error or a warning has been flagged (see Section 6).

## 6Error Indicators and Warnings

If on entry ${\mathbf{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:
${\mathbf{ifail}}=1$
On entry, ${\mathbf{k}}=⟨\mathit{\text{value}}⟩$.
Constraint: ${\mathbf{k}}\le 6$.
On entry, ${\mathbf{k}}=⟨\mathit{\text{value}}⟩$.
Constraint: ${\mathbf{k}}\ge 0$.
On entry, x is ‘too close’ to a non-positive integer: ${\mathbf{x}}=⟨\mathit{\text{value}}⟩$ and $\mathrm{nint}\left({\mathbf{x}}\right)=⟨\mathit{\text{value}}⟩$.
${\mathbf{ifail}}=2$
Evaluation abandoned due to likelihood of underflow.
${\mathbf{ifail}}=3$
Evaluation abandoned due to likelihood of overflow.
${\mathbf{ifail}}=-99$
See Section 7 in the Introduction to the NAG Library FL Interface for further information.
${\mathbf{ifail}}=-399$
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.
${\mathbf{ifail}}=-999$
Dynamic memory allocation failed.
See Section 9 in the Introduction to the NAG Library FL Interface for further information.

## 7Accuracy

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=\mathrm{min}\phantom{\rule{0.125em}{0ex}}\left(t,18\right)$. 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 $-{\psi }^{\left(0\right)}\left(x\right)$ have shown somewhat improved accuracy, except at points near the positive zero of ${\psi }^{\left(0\right)}\left(x\right)$ at $x=1.46\dots \text{}$, where only absolute accuracy can be obtained.

## 8Parallelism and Performance

s14aef is not threaded in any implementation.

None.

## 10Example

This example evaluates ${\psi }^{\left(2\right)}\left(x\right)$ at $x=2.5$, and prints the results.

### 10.1Program Text

Program Text (s14aefe.f90)

### 10.2Program Data

Program Data (s14aefe.d)

### 10.3Program Results

Program Results (s14aefe.r)