s14ae 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$.

# Syntax

C# |
---|

public static double s14ae( double x, int k, out int ifail ) |

Visual Basic |
---|

Public Shared Function s14ae ( _ x As Double, _ k As Integer, _ <OutAttribute> ByRef ifail As Integer _ ) As Double |

Visual C++ |
---|

public: static double s14ae( double x, int k, [OutAttribute] int% ifail ) |

F# |
---|

static member s14ae : x : float * k : int * ifail : int byref -> float |

#### Parameters

- x
- Type: System..::..Double
*On entry*: the argument $x$ of the function.*Constraint*: ${\mathbf{x}}$ must not be ‘too close’ (see [Error Indicators and Warnings]) to a non-positive integer.

- k
- Type: System..::..Int32
*On entry*: the function ${\psi}^{\left(k\right)}\left(x\right)$ to be evaluated.*Constraint*: $0\le {\mathbf{k}}\le 6$.

- ifail
- Type: System..::..Int32%
*On exit*: ${\mathbf{ifail}}={0}$ unless the method detects an error or a warning has been flagged (see [Error Indicators and Warnings]).

#### Return Value

s14ae 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$.

# Description

s14ae evaluates an approximation to the $k$th derivative of the psi function $\psi \left(x\right)$ given by

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

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 s14ad, which is based on the method PSIFN in Amos (1983).

$${\psi}^{\left(k\right)}\left(x\right)=\frac{{d}^{k}}{d{x}^{k}}\psi \left(x\right)=\frac{{d}^{k}}{d{x}^{k}}\left(\frac{d}{dx}{\mathrm{log}}_{\mathrm{e}}\u200a\Gamma \left(x\right)\right)\text{,}$$ |

$${\psi}^{\left(k\right)}\left(x+1\right)={\psi}^{\left(k\right)}\left(x\right)+\frac{{d}^{k}}{d{x}^{k}}\left(\frac{1}{x}\right)$$ |

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).

# References

Abramowitz M and Stegun I A (1972)

*Handbook of Mathematical Functions*(3rd Edition) Dover PublicationsAmos 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:

- ${\mathbf{ifail}}=1$
On entry, ${\mathbf{k}}<0$, or ${\mathbf{k}}>6$, or x is ‘too close’ to a non-positive integer. That is, $\mathrm{abs}\left({\mathbf{x}}-\mathrm{nint}\left({\mathbf{x}}\right)\right)<\phantom{\rule{0ex}{0ex}}\mathit{machineprecision}\times \mathrm{nint}\left(\mathrm{abs}\left({\mathbf{x}}\right)\right)$.

- ${\mathbf{ifail}}=2$
- The evaluation has been abandoned due to the likelihood of underflow. The result is returned as zero.

- ${\mathbf{ifail}}=3$
- The evaluation has been abandoned due to the likelihood of overflow. The result is returned as zero.

# Accuracy

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

# Parallelism and Performance

None.

# Further Comments

None.

# Example

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

Example program (C#): s14aee.cs