Integer type:  int32  int64  nag_int  show int32  show int32  show int64  show int64  show nag_int  show nag_int

Chapter Contents
Chapter Introduction
NAG Toolbox

# NAG Toolbox: nag_specfun_psi_deriv_complex (s14af)

## Purpose

nag_specfun_psi_deriv_complex (s14af) 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$, via the function name.

## Syntax

[result, ifail] = s14af(z, k)
[result, ifail] = nag_specfun_psi_deriv_complex(z, k)

## Description

nag_specfun_psi_deriv_complex (s14af) 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).
nag_specfun_psi_deriv_complex (s14af) 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, nag_specfun_psi_deriv_real (s14ae) can be used.

## References

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

## Parameters

### Compulsory Input Parameters

1:     $\mathrm{z}$ – complex scalar
The argument $z$ of the function.
Constraint: $\mathrm{Re}\left({\mathbf{z}}\right)$ must not be ‘too close’ (see Error Indicators and Warnings) to a non-positive integer when $\mathrm{Im}\left({\mathbf{z}}\right)=0.0$.
2:     $\mathrm{k}$int64int32nag_int scalar
The function ${\psi }^{\left(k\right)}\left(z\right)$ to be evaluated.
Constraint: $0\le {\mathbf{k}}\le 4$.

None.

### Output Parameters

1:     $\mathrm{result}$ – complex scalar
The result of the function.
2:     $\mathrm{ifail}$int64int32nag_int scalar
${\mathbf{ifail}}={\mathbf{0}}$ unless the function detects an error (see Error Indicators and Warnings).

## Error Indicators and Warnings

Errors or warnings detected by the function:
${\mathbf{ifail}}=1$
 On entry, ${\mathbf{k}}<0$, or ${\mathbf{k}}>4$, or $\mathrm{Re}\left({\mathbf{z}}\right)$ is ‘too close’ to a non-positive integer when $\mathrm{Im}\left({\mathbf{z}}\right)=0.0$. That is, .
${\mathbf{ifail}}=2$
The evaluation has been abandoned due to the likelihood of overflow. The result is returned as zero.
${\mathbf{ifail}}=-99$
${\mathbf{ifail}}=-399$
Your licence key may have expired or may not have been installed correctly.
${\mathbf{ifail}}=-999$
Dynamic memory allocation failed.

## Accuracy

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

None.

## Example

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

fprintf('s14af example results\n\n');

z =  -1.5 + 2.5i;
k = int64(1);
[pk, ifail] = s14af(z, k);

disp('      z        k      (d^K/dx^K)psi(z)');
fprintf('%5.1f%+5.1fi%5d', real(z), imag(z), k);
fprintf('  %12.4e%+12.4ei\n', real(pk), imag(pk));

```
```s14af example results

z        k      (d^K/dx^K)psi(z)
-1.5 +2.5i    1   -1.9737e-01 -2.4271e-01i
```