Main Content

gammainc

Regularized incomplete gamma function

Description

example

Y = gammainc(X,A) returns the regularized lower incomplete gamma function evaluated at the elements of X and A. Both X and A must be real, and A must be nonnegative.

example

Y = gammainc(X,A,type) returns the regularized lower or upper incomplete gamma function. The choices for type are 'lower' (the default) and 'upper'.

example

Y = gammainc(X,A,scale) scales the resulting regularized lower or upper incomplete gamma function to avoid underflow to zero or loss of accuracy. The choices for scale are 'scaledlower' and 'scaledupper'.

Examples

collapse all

Calculate the regularized lower incomplete gamma function for a = 0.5, 1, 1.5, and 2 within the interval 0x10. Loop over values of a, evaluate the function at each one, and assign each result to a column of Y.

A = [0.5 1 1.5 2];
X = 0:0.05:10;
Y = zeros(201,4);
for i = 1:4
    Y(:,i) = gammainc(X,A(i));
end

Plot all of the functions in the same figure.

plot(X,Y)
grid on
legend('$a = 0.5$','$a = 1$','$a = 1.5$','$a = 2$','interpreter','latex')
title('Regularized lower incomplete gamma function for $a = 0.5, 1, 1.5,$ and $2$','interpreter','latex')
xlabel('$x$','interpreter','latex')
ylabel('$P(x,a)$','interpreter','latex')

Calculate the regularized upper incomplete gamma function for a = 0.5, 1, 1.5, and 2 within the interval 0x10. Loop over values of a, evaluate the function at each one, and assign each result to a column of Y.

A = [0.5 1 1.5 2];
X = 0:0.05:10;
Y = zeros(201,4);
for i = 1:4
    Y(:,i) = gammainc(X,A(i),'upper');
end

Plot all of the functions in the same figure.

plot(X,Y)
grid on
legend('$a = 0.5$','$a = 1$','$a = 1.5$','$a = 2$','interpreter','latex');
title('Regularized upper incomplete gamma function for $a = 0.5, 1, 1.5,$ and $2$','interpreter','latex')
xlabel('$x$','interpreter','latex')
ylabel('$Q(x,a)$','interpreter','latex')

Calculate the unscaled regularized lower incomplete gamma function for a=1 within the interval 0x2. Plot the function.

a = 1;
x = 0:0.001:2;
Y = gammainc(x,a);
plot(x,Y);
xlabel('$x$','interpreter','latex');
ylabel('$P(x,1)$','interpreter','latex')
hold on

Next, calculate the scaled lower incomplete gamma function. Plot the function on the same graph. The scaled function has different asymptotic behavior near 0, which avoids underflow when x is close to 0.

Ys = gammainc(x,a,'scaledlower');
plot(x,Ys,'--');
legend('unscaled','scaled')

Input Arguments

collapse all

Input array, specified as a scalar, vector, matrix, or multidimensional array. The elements of X must be real. X and A must be the same size, or else one of them must be a scalar.

Data Types: single | double

Input array, specified as a scalar, vector, matrix, or multidimensional array. The elements of A must be real and nonnegative. X and A must be the same size, or else one of them must be a scalar.

Data Types: single | double

Type of regularized incomplete gamma function, specified as 'lower' or 'upper'. If type is 'lower', then gammainc returns the regularized lower incomplete gamma function. If type is 'upper', then gammainc returns the regularized upper incomplete gamma function.

Scaling option, specified as 'scaledlower' or 'scaledupper'. If scale is 'scaledlower' or 'scaledupper', then gammainc scales the regularized lower or upper incomplete gamma function by a factor of Γ(a+1)ex/xa, where Γ(a) is the gamma function. This scaling cancels out the asymptotic behavior of the function near 0, which avoids underflow with small arguments.

Limitations

  • When x is negative, the regularized incomplete gamma function can be inaccurate for abs(x) > a+1.

More About

collapse all

Incomplete Gamma Function

The regularized lower incomplete gamma function P and the regularized upper incomplete gamma function Q are defined by

P(x,a)=1Γ(a)0xta1etdt,Q(x,a)=1Γ(a)xta1etdt.

The gamma function Γ(a) is defined by

Γ(a)=0ta1etdt.

MATLAB® uses the regularized or normalized definition of the incomplete gamma function, where P(x,a)+Q(x,a)=1.

The scaled lower and upper incomplete gamma function are defined by

Ps(x,a)=Γ(a+1)Γ(a)exxa0xta1etdt,Qs(x,a)=Γ(a+1)Γ(a)exxaxta1etdt.

Some properties of the regularized lower incomplete gamma function are:

  • limxP(x,a)=1fora0

  • limx,a0P(x,a)=1

Tips

  • When the regularized upper incomplete gamma function is close to 0, specifying the 'upper' option to calculate the function is more accurate than subtracting the regularized lower incomplete gamma function from 1.

References

[1] Olver, F. W. J., A. B. Olde Daalhuis, D. W. Lozier, B. I. Schneider, R. F. Boisvert, C. W. Clark, B. R. Miller, and B. V. Saunders, eds., Chapter 8. Incomplete Gamma and Related Functions, NIST Digital Library of Mathematical Functions, Release 1.0.22, Mar. 15, 2018.

Extended Capabilities

Version History

Introduced before R2006a