3
$\begingroup$

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.

$\endgroup$
10
$\begingroup$

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.01416292`16;
a = 2.84082292`16;
b = 0.39397473`16;
Integrate[f[x], {x, Exp[x0], 10}]
(*  1.14435621208982531824685420020762304511`0.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.)

$\endgroup$
  • $\begingroup$ 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) . $\endgroup$ – 2012rcampion Apr 4 '15 at 18:00
  • $\begingroup$ @Ivan You're welcome. $\endgroup$ – Michael E2 Apr 4 '15 at 20:58
1
$\begingroup$

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 *)
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.