When I enter
N[Gamma[2, -40]]
into my Mathematica notebook, I get
-9.18003*10^18 + 1124.23 i
However, Wolfram Alpha will give me a real expression. Why do these two numbers disagree - and which one is correct?
When I enter
N[Gamma[2, -40]]
into my Mathematica notebook, I get
-9.18003*10^18 + 1124.23 i
However, Wolfram Alpha will give me a real expression. Why do these two numbers disagree - and which one is correct?
This is a precision issue. If you use arbitrary precision
rather than machine precision, Mathematica will track and control the precision.
$Version
(* "10.4.1 for Mac OS X x86 (64-bit) (April 11, 2016)" *)
N[Gamma[2, -40]]
(* -9.18003*10^18 + 1124.23 I *)
N[Gamma[2, -40], 30] // Chop
(* -9.18002540664377943090809651921*10^18 *)
This Gamma
function can be evaluated exactly using FunctionExpand
Gamma[2, -40] // FunctionExpand
(* -39 E^40 *)
Gamma[2, -40] // FunctionExpand // N
(* -9.18003*10^18 *)
A later version does not have these problems
$Version
(* "11.1.1 for Mac OS X x86 (64-bit) (April 18, 2017)" *)
Gamma[2, -40]
(* -39 E^40 *)
Gamma[2, -40] // N
(* -9.18003*10^18 *)
N[Gamma[2, -40], 20]
$\endgroup$N[x, 20]
aroundGamma
whenever I use Gamma in longer equations, if I want to kill those imaginary terms in the result? Sounds somewhat suspicious to me. $\endgroup$N[Gamma[2, -40], 6]
. You could also force theGamma
function to evaluate before asking for the numerical approximation:Evaluate[Gamma[2, -40]] // N
$\endgroup$Evaluate, //
chain also yields an imaginary component $\endgroup$version 11.1.1 for Mac OS X x86 (64-bit) (April 18, 2017)
$\endgroup$