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, ∞}]
Answer
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.
Comments
Post a Comment