1

I am confused about incomplete gamma function calculation in Mathematica and MATLAB:

For example, in Mathematica: Gamma[5,3] = 19.56

But in MATLAB: gammainc(5,3) = 0.8753

I don't know which one is correct, MATLAB result or Mathematica result?

J. M.'s missing motivation
  • 124,525
  • 11
  • 401
  • 574
sky-light
  • 827
  • 1
  • 12
  • 24
  • Also, this relationship is valid: gammainc(a,b,'upper')*gamma(b) in Matlab gives the same result as Gamma[b,a] in Mathematica. – Masoud Moeini Jan 11 '22 at 23:37

1 Answers1

15

In Mathematica, Gamma[a, z] refers to the upper incomplete Gamma function, given by

$$\Gamma(a,z)=\int_z^\infty t^{a-1}e^{-t}\,dt$$

whereas in MATLAB, gammainc(z, a) refers to the regularized lower incomplete Gamma function

$$P(a,z)=\frac{1}{\Gamma(a)}\int_0^z t^{a-1}e^{-t}\, dt$$

Obviously, they give different results. To get MATLAB's result in Mathematica, use the following:

gammainc[a_, z_] := Gamma[a, 0, z]/Gamma[a]
N@gammainc[3, 5]

(* 0.875348 *)
rm -rf
  • 88,781
  • 21
  • 293
  • 472
  • 3
    In fact, you could simplify things slightly: gammainc[a_, z_] := GammaRegularized[a, 0, z]; it has been anticipated that people would frequently want the scaled version. – J. M.'s missing motivation May 10 '15 at 10:12