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.

Returns:

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.

References

    1. Lanczos, SIAM JNA 1, 1964. pp. 86-96.

    1. Luke, “The Special … approximations,” 1969 pp. 29-31.

    1. Luke, “Algorithms … functions,” 1977.

    1. Spouge, SIAM JNA 31, 1994. pp. 931.

    1. Press, “Numerical Recipes.”

    1. Chang, “Computation of special functions,” 1996.

  1. Abramowitz & Stegun, section eq 6.4.6

  2. Original code by Paul Godfrey