Integrate and NIntegrate not the same

Why am I getting two different results here?

x0 = -1.01416292;
a = 2.84082292;
b = 0.39397473;
f[x_] := (Log[x] - x0)^(a - 1) Exp[-(Log[x] - x0)/b]/(b^a*Gamma[a] x);
Integrate[f[x], {x, Exp[x0], 10}]
NIntegrate[f[x], {x, Exp[x0], 10}]

(* 1.14436 *)
(* 0.992038 *)


I'm pretty sure the NIntegrate result is the correct one, since it's a probability distribution and it shouldn't be greater than 1.

2 Answers

Using approximate numbers (e.g. ones with decimal points) can lead to issues with exact solvers such as Integrate. One way around, if the function can be integrated with symbolic parameters, is to use Block to block the numeric values from being substituted until after the integration is complete:

Block[{x0, a, b},
Assuming[a > 0 && b > 0 && x0 < Log[10],
Integrate[f[x], {x, Exp[x0], 10}]
]]
(*  0.992038  *)


One can confirm the numeric issue by using arbitrary precision numbers for the parameters:

x0 = -1.0141629216;
a = 2.8408229216;
b = 0.3939747316;
Integrate[f[x], {x, Exp[x0], 10}]
(*  1.144356212089825318246854200207623045110.6569554175313712  *)


The result has a precision of less than 1., which shows that the 1.14 is a close enough approximation at that (horrible) precision. (The result represents a real number between 0.892 and 1.396.)

• Note that evaluating the integral without defining x0, a, and b (resulting in 1 - Gamma[a, (Log[10]-x0)/b]/Gamma[a]), then substituting in the numerical values leads to the correct result (the same as, to 14 decimal places, the result of NIntegrate) . Apr 4, 2015 at 18:00
• @Ivan You're welcome. Apr 4, 2015 at 20:58

I believe it's a bug, integrating to Infinity yields the correct result of 1.:

Integrate[f[x], {x, Exp[x0], Infinity}]
(* 1. *)


Also, I think it's also a part of the possible issues for definite integrals, listed in the Integrate:

eq = Integrate[f[x], x];
(eq /. {x -> 10}) - (eq /. {x -> Exp[x0]})
(* 0.992038 *)