I just want to use numerical integration, and I can not trust the results and it seems something goes wrong. the problem is as follow : I have a totally positive two variable function and from elementary high school mathematics, integration over bigger intervals must be greater than smaller intervals, but NIntegration can not realize this fact. for example :
NIntegrate[Exp[-(x - y)^2], {x, -200, 200}, {y, -200, 200}]
and the answer is 42.4266
but when I integrate over smaller intervals
NIntegrate[Exp[-(x - y)^2], {x, -100, 100}, {y, -100, 100}]
and the answer is 209.479.
How can I trust to the mathematica, and what to do to fix the problem. thanks
NIntegrate
gives error messages, you didn't mention. $\endgroup${y, -200, x, 200}
. $\endgroup$WorkingPrecision
. Even then, you need to proceed with caution. $\endgroup$NIntegrate[ Exp[-(x - y)^2], {x, -200, 200}, {y, -200, x - 3, x + 3, 200}]
to get707.967
very close to the analytical707.982
$\endgroup${y, -200, x, 200}
means the integration will be broken up aty == x
, where the Exp has a maximumExp[-(x-y)^2] == 1
. Akku14’s breaking up the region just before and after the maximum is more reliable in general. The trouble is with error estimation. When the function is nearly flat almost everywhere, then discrete sampling will probably lead to a very small error estimate unless some sample points land in a region where the function varies rapidly. By dividing the region into subregions where the function changes a lot, the error estimates will be greater and NIntegrate will work harder. $\endgroup$