psi

Digamma function

Syntax

psi(x)
psi(k,x)

Description

psi(x) computes the digamma function of x.

psi(k,x) computes the polygamma function of x, which is the kth derivative of the digamma function at x.

Input Arguments

x

Symbolic number, variable, expression, or a vector, matrix, or multidimensional array of these.

k

Nonnegative integer or vector, matrix or multidimensional array of nonnegative integers. If x is nonscalar and k is scalar, then k is expanded into a nonscalar of the same dimensions as x with each element being equal to k. If both x and k are nonscalars, they must have the same dimensions.

Examples

Compute the digamma and polygamma functions for these numbers. Because these numbers are not symbolic objects, you get the floating-point results.

[psi(1/2) psi(2, 1/2) psi(1.34) psi(1, sin(pi/3))]
ans =
   -1.9635  -16.8288   -0.1248    2.0372

Compute the digamma and polygamma functions for the numbers converted to symbolic objects.

[psi(sym(1/2)), psi(1, sym(1/2)), psi(sym(1/4))]
ans =
[ - eulergamma - 2*log(2), pi^2/2, - eulergamma - pi/2 - 3*log(2)]

For some symbolic (exact) numbers, psi returns unresolved symbolic calls.

psi(sym(sqrt(2)))
ans =
psi(2^(1/2))

Compute the derivatives of these expressions containing the digamma and polygamma functions.

syms x
diff(psi(1, x^3 + 1), x)
diff(psi(sin(x)), x)
ans =
3*x^2*psi(2, x^3 + 1)
 
ans =
cos(x)*psi(1, sin(x))

Expand the expressions containing the digamma functions.

syms x
expand(psi(2*x + 3))
expand(psi(x + 2)*psi(x))
ans =
psi(x + 1/2)/2 + log(2) + psi(x)/2 +...
1/(2*x + 1) + 1/(2*x + 2) + 1/(2*x)
 
ans =
psi(x)/x + psi(x)^2 + psi(x)/(x + 1)

Compute the limits for expressions containing the digamma and polygamma functions.

syms x
limit(x*psi(x), x, 0)
limit(psi(3, x), x, inf)
ans =
-1
 
ans =
0

Compute the digamma function for elements of matrix M and vector V.

M = sym([0 inf; 1/3 1/2]);
V = sym([1, inf]);
psi(M)
psi(V)
ans =
[                                          Inf,                     Inf]
[ - eulergamma - (3*log(3))/2 - (pi*3^(1/2))/6, - eulergamma - 2*log(2)]

ans =
[ -eulergamma, Inf]

Compute the polygamma function for elements of matrix M and vector V. The psi function acts elementwise on nonscalar inputs.

M = sym([0 inf; 1/3 1/2]);
polyGammaM = [1 3; 2 2];
V = sym([1, inf]);
polyGammaV = [6 6];
psi(polyGammaM,M)
psi(polyGammaV,V)
ans =
[                               Inf,           0]
[ - 26*zeta(3) - (4*3^(1/2)*pi^3)/9, -14*zeta(3)]
 
ans =
[ -720*zeta(7), 0]

Because all elements of polyGammaV have the same value, you can replace polyGammaV by a scalar of that value. psi expands the scalar into a nonscalar of the same size as V and computes the result.

V = sym([1, inf]);
psi(6,V)
ans =
[ -720*zeta(7), 0]

More About

expand all

Digamma Function

The digamma function is the first derivative of the logarithm of the gamma function:

ψ(x)=ddxlnΓ(x)=Γ(x)Γ(x)

Polygamma Function

The polygamma function of the order k is the (k + 1)th derivative of the logarithm of the gamma function:

ψ(k)(x)=dk+1dxk+1lnΓ(x)=dkdxkψ(x)

Tips

  • Calling psi for a number that is not a symbolic object invokes the MATLAB® psi function. This function accepts real nonnegative arguments x. If you want to compute the polygamma function for a complex number, use sym to convert that number to a symbolic object, and then call psi for that symbolic object.

  • psi(0, x) is equivalent to psi(x).

Was this topic helpful?