Main Content

psi

Digamma and polygamma functions

Description

example

Y = psi(X) evaluates the digamma function for each element of array X, which must be real and nonnegative.

example

Y = psi(k,X) evaluates the polygamma function of X, which is the kth derivative of the digamma function at X. Thus, psi(0,X) is the digamma function, psi(1,X) is the trigamma function, psi(2,X) is the tetragamma function, and so on.

Examples

collapse all

Use the psi function to evaluate the Euler-Mascheroni constant γ, also known as Euler's constant.

format long
Y = -psi(1)
Y = 
   0.577215664901532

Evaluate the trigamma function of 2.

format long
Y1 = psi(1,2)
Y1 = 
   0.644934066848226

Check that the result is equal to π2/6-1.

Y2 = pi^2/6 - 1
Y2 = 
   0.644934066848226

isequal(Y1,Y2)
ans = logical
   1

Define the domain.

X = 0:0.05:5;

Calculate the digamma and the next three polygamma functions.

Y = zeros(4,101);
for i = 0:3
    Y(i+1,:) = psi(i,X);
end

Plot the digamma and the next three polygamma functions.

plot(X,Y)
axis([0 5 -10 10])
legend('\psi','\psi_1','\psi_2','\psi_3','Location','Best')
title('Digamma and The Next Three Polygamma Functions','interpreter','latex')
xlabel('$x$','interpreter','latex')
ylabel('$\psi_k(x)$','interpreter','latex')

Figure contains an axes object. The axes object with title Digamma and The Next Three Polygamma Functions, xlabel $x$, ylabel psi indexOf k baseline leftParenthesis x rightParenthesis contains 4 objects of type line. These objects represent \psi, \psi_1, \psi_2, \psi_3.

Input Arguments

collapse all

Input, specified as a scalar, vector, matrix, or multidimensional array of nonnegative real numbers. X cannot be sparse.

Data Types: single | double

Order of derivative, specified as a nonnegative integer scalar. k must be smaller than 231-1.

Data Types: single | double

More About

collapse 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).

References

[1] Abramowitz, M. and I. A. Stegun, Handbook of Mathematical Functions, Dover Publications, 1965, Sections 6.3 and 6.4.

Extended Capabilities

Version History

Introduced before R2006a

See Also

| |