# polygamma¶

## Purpose¶

Computes the polygamma function.

## Format¶

f = polygamma(z, n)
Parameters: z (NxK matrix) – z may be complex n (The order of the function) – If n is 0 then f will be the Digamma function. If n = 1,2,3, etc., then f will be the tri-, tetra-, penta-, s-, etc., Gamma function. Real (n) must be positive. f (NxK matrix) – f may be complex.

## Examples¶

### Example 1: Basic usage¶

// Both calls are equivalent
f = digamma(1);
f2 = polygamma(1, 0);


After the code above, both f and f2 should be equal to -g, where g represents the Euler-Mascheroni constant:

-0.57721566


### Compute the pentagamma function¶

f = polygamma(1.5, 4);


After the code above, f should be equal to:

-3.47425


### Complex input¶

// Set 'z' equal to complex number -45.6-29.4i
z = { -45.6 - 29.4i };
polygamma(z, 101);

12.501909 + 9.0829590i


### Example 4¶

z = { -11.5 - 0.577007813568142i };
polygamma(z, 10);


will return the value:

-4.984e-06 + 8.217e-07i


## Remarks¶

The polygamma() function of order n is defined by the equation:

$\psi^{(n)}(z) = \frac{d^n}{dz^n}\psi(z) = \frac{d^{n+1}}{dz^{n+1}}ln\Gamma(z)$

This program uses the partial fraction expansion of the derivative of the log of the Lanczos series approximation for the Gamma function. Accurate to about 12 digits.