I'm having an issue integrating numerically with Mathematica. This is a very simple MWE of a much larger calculation, in which I have no option to integrate analytically. I'd like to understand how I can get better results just by numerically integrating.
The setup:
Consider the one-dimensional Gaussian integral, $\int_{-\infty}^\infty e^{-x^2}=\sqrt{\pi}$. I can evaluate it very easily:
both Integrate[Exp[-x^2], {x, -Infinity, Infinity}]
and NIntegrate[Exp[-x^2], {x, -Infinity, Infinity}]
return the correct result.
The problem:
In my current situation, I have a squared parameter added to the exponent, which shouldn't change the behavior of the integral:
Integrate[Exp[-(x+a^2)^2], {x, -Infinity, Infinity}]
still returns $\sqrt{\pi}$.
However, the numerical integration is very sensitive to the value of a
. It works for small values of the parameter, but NIntegrate[Exp[-(x+a^2)^2] /. a -> 100, {x, -Infinity, Infinity}]
returns 0 and an error. Changing the integration method to LocalAdaptive
gets rid of the error but still returns 0 instead of the expected $\sqrt{\pi}\simeq1.77$, even with very high PrecisionGoal
or AccuracyGoal
. Same goes for most other integration methods I tried, including for example Adaptive(Quasi)MonteCarlo
.
I get something nonzero with Method->{"MonteCarloRule","Points"->10^7}
, but anything higher than that just crashes my kernel and the calculation is still very far from the expected value of the integral.
Is there any integration strategy to avoid this problem and get an accurate result?