When I solve the following integral analytically and numerically the answers are different. Why? how can I get similar answers?

a = 10^-6;
t = 10000;
NIntegrate [E^(-w/ a) t, {w, 0, ∞},
MaxRecursion -> 300, AccuracyGoal -> 10] 

here the answer is $0$. But when I solve it analytically, as follows, the answer is $0.01$.

Integrate[E^(-w/a) t , {w, 0, ∞}]
  • 1
    $\begingroup$ With[{a = 1*^-6, t = 10000}, NIntegrate[E^(-w/a) t, {w, 0, ∞}, WorkingPrecision -> 20]] works, tho. $\endgroup$ – J. M.'s torpor Jul 13 '16 at 15:38
  • $\begingroup$ NIntegrate[E^(-w/a) t, {w, 0, \[Infinity]}, Method -> "LocalAdaptive"] correct answer, no messages. $\endgroup$ – vapor Jul 13 '16 at 15:40

Of course in this case you can trust the symbolic result of Integrate, but the point raised by the question becomes especially important when there is no analytical solution.

Here is an example suffering from an even more rapid decay that causes the same numerical problems. Finding the right options for NIntegrate isn't so obvious:

a = 10^6;

integrand = E^(- a w^w );

Integrate[integrand, {w, 0, Infinity}]

(* returns unevaluated because no symbolic solution exists *)

NIntegrate[integrand, {w, 0, Infinity}]

(* ==> 0., with warning message *)

NIntegrate[integrand, {w, 0, Infinity}, Method -> "LocalAdaptive"]

(* ==> 0. *)

None of these results are what we want.

What I would suggest is to try symbolic integration first, but then automatically fall back to numerical integration if that fails. As explained in the documentation for Integrate (under "Scope > Basic Usage"), this can be done by simply wrapping Integrate in N. The advantage for our problem is then that N allows a second argument for the desired precision:

N[Integrate[integrand, {w, 0, Infinity}], 10]

(* ==> 2.233104982*10^-300622 *)

Here, I get a numerical result without having to think about the choice of integration method.


Most of the value of the integral occurs before $w\le 0.00002$.

NIntegrate[Exp[-w/a] t, {w, 0, 0.00002}, WorkingPrecision -> 16]


At MachinePrecision, the total value of the integral can be found at $w\le 0.1$.

NIntegrate[Exp[-w/a] t , {w, 0, 0.1}]


It is therefore not just a question of MaxRecursion:

NIntegrate[Exp[-w/a] t , {w, 0, \[Infinity]}, MinRecursion -> 10, MaxRecursion -> 30]

Provides the answer as well, but Mathematica needs to know that it is not just integrating a horizontal line at zero, after all: $e^{-0.1/a}\approx3.563*10^{-43430}$. Hence the error message.

Integral and error estimates are 0 on all integration subregions. Try increasing the value of the MinRecursion option. If value of integral may be 0, specify a finite value for the AccuracyGoal option. >>

  • $\begingroup$ Using numerical integration all the way to infinity is suspect anyway. Why do it at all? $\endgroup$ – rhomboidRhipper Jul 13 '16 at 16:09
  • $\begingroup$ @rhomboid, because there are in fact numerical methods for dealing with improper integrals; this is an active area of research. $\endgroup$ – J. M.'s torpor Jul 13 '16 at 16:18

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.