psi
Digamma function
Description
psi( computes the digamma function of
x)x.
psi( computes the
polygamma function of
k,x)x, which is the kth derivative of the digamma
function at x.
Examples
Compute Digamma and Polygamma for Numeric Inputs
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 Digamma and Polygamma for Symbolic Inputs
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 Derivatives of Digamma and Polygamma Functions
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 Digamma and Polygamma Functions
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)
Limit of Digamma and Polygamma Functions
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 Digamma for Matrix Input
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 Polygamma for Matrix Input
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]
Input Arguments
More About
Tips
Calling
psifor a number that is not a symbolic object invokes the MATLAB®psifunction. This function accepts real nonnegative argumentsx. If you want to compute the polygamma function for a complex number, usesymto convert that number to a symbolic object, and then callpsifor that symbolic object.psi(0, x)is equivalent topsi(x).
Version History
Introduced in R2011b