# NAG CL Interfaces14afc (psi_​deriv_​complex)

Settings help

CL Name Style:

## 1Purpose

s14afc returns the value of the $k$th derivative of the psi function $\psi \left(z\right)$ for complex $z$ and $k=0,1,\dots ,4$.

## 2Specification

 #include
 Complex s14afc (Complex z, Integer k, NagError *fail)
The function may be called by the names: s14afc, nag_specfun_psi_deriv_complex or nag_complex_polygamma.

## 3Description

s14afc evaluates an approximation to the $k$th derivative of the psi function $\psi \left(z\right)$ given by
 $ψ (k) (z)=dkdzk ψ(z)=dkdzk (ddz loge⁡Γ(z)) ,$
where $z=x+iy$ is complex provided $y\ne 0$ and $k=0,1,\dots ,4$. If $y=0$, $z$ is real and thus ${\psi }^{\left(k\right)}\left(z\right)$ is singular when $z=0,-1,-2,\dots \text{}$.
Note that ${\psi }^{\left(k\right)}\left(z\right)$ is also known as the polygamma function. Specifically, ${\psi }^{\left(0\right)}\left(z\right)$ is often referred to as the digamma function and ${\psi }^{\left(1\right)}\left(z\right)$ as the trigamma function in the literature. Further details can be found in Abramowitz and Stegun (1972).
s14afc is based on a modification of the method proposed by Kölbig (1972).
To obtain the value of ${\psi }^{\left(k\right)}\left(z\right)$ when $z$ is real, s14aec can be used.

## 4References

Abramowitz M and Stegun I A (1972) Handbook of Mathematical Functions (3rd Edition) Dover Publications
Kölbig K S (1972) Programs for computing the logarithm of the gamma function, and the digamma function, for complex arguments Comp. Phys. Comm. 4 221–226

## 5Arguments

1: $\mathbf{z}$Complex Input
On entry: the argument $z$ of the function.
Constraint: ${\mathbf{z}}\mathbf{.}\mathbf{re}$ must not be ‘too close’ (see Section 6) to a non-positive integer when ${\mathbf{z}}\mathbf{.}\mathbf{im}=0.0$.
2: $\mathbf{k}$Integer Input
On entry: the function ${\psi }^{\left(k\right)}\left(z\right)$ to be evaluated.
Constraint: $0\le {\mathbf{k}}\le 4$.
3: $\mathbf{fail}$NagError * Input/Output
The NAG error argument (see Section 7 in the Introduction to the NAG Library CL Interface).

## 6Error Indicators and Warnings

NE_ALLOC_FAIL
Dynamic memory allocation failed.
See Section 3.1.2 in the Introduction to the NAG Library CL Interface for further information.
NE_COMPLEX
On entry, ${\mathbf{z}}\mathbf{.}\mathbf{re}$ is ‘too close’ to a non-positive integer when ${\mathbf{z}}\mathbf{.}\mathbf{im}=0.0$: ${\mathbf{z}}\mathbf{.}\mathbf{re}=⟨\mathit{\text{value}}⟩$, $\mathrm{nint}\left({\mathbf{z}}\mathbf{.}\mathbf{re}\right)=⟨\mathit{\text{value}}⟩$.
NE_INT
On entry, ${\mathbf{k}}=⟨\mathit{\text{value}}⟩$.
Constraint: ${\mathbf{k}}\le 4$.
On entry, ${\mathbf{k}}=⟨\mathit{\text{value}}⟩$.
Constraint: ${\mathbf{k}}\ge 0$.
NE_INTERNAL_ERROR
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.
NE_NO_LICENCE
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.
NE_OVERFLOW_LIKELY
Evaluation abandoned due to likelihood of overflow.

## 7Accuracy

Empirical tests have shown that the maximum relative error is a loss of approximately two decimal places of precision.

## 8Parallelism and Performance

s14afc is not threaded in any implementation.

None.

## 10Example

This example evaluates the psi (trigamma) function ${\psi }^{\left(1\right)}\left(z\right)$ at $z=-1.5+2.5i$, and prints the results.

### 10.1Program Text

Program Text (s14afce.c)

### 10.2Program Data

Program Data (s14afce.d)

### 10.3Program Results

Program Results (s14afce.r)