MATLAB Function Reference
psi

Psi (polygamma) function

Syntax

• ```Y = psi(X)
Y = psi(k,X)
Y = psi(k0:k1,X)
```

Description

```Y = psi(X) ``` evaluates the function for each element of array `X`. `X` must be real and nonnegative. The function, also known as the digamma function, is the logarithmic derivative of the gamma function

```Y = psi(k,X) ``` evaluates the `k`th derivative of at the elements of `X`. `psi(0,X)` is the digamma function, `psi(1,X)` is the trigamma function, `psi(2,X)` is the tetragamma function, etc.

```Y = psi(k0:k1,X) ``` evaluates derivatives of order `k0` through `k1` at `X`. `Y(k,j)` is the `(k-1+k0)`th derivative of , evaluated at `X(j)`.

Examples

Example 1. Use the `psi` function to calculate Euler's constant, .

• ```format long
-psi(1)
ans =
0.57721566490153

-psi(0,1)
ans =
0.57721566490153
```

Example 2. The trigamma function of 2, `psi(1,2)`, is the same as .

• ```format long
psi(1,2)
ans =
0.64493406684823

pi^2/6 - 1
ans =
0.64493406684823
```

Example 3. This code produces the first page of Table 6.1 in Abramowitz and Stegun [1].

• ```x = (1:.005:1.250)';
[x gamma(x) gammaln(x) psi(0:1,x)' x-1]
```

Example 4. This code produces a portion of Table 6.2 in [1].

• ```psi(2:3,1:.01:2)'
```

`gamma`, `gammainc`, `gammaln`