I have a multidimensional integral (5D), which every time gives a different result with the MonteCarlo strategy.

I tried different methods (MultiPeriodic, ("MonteCarlo", "QuasiMonteCarlo" with "MaxPoints" -> 1000000), ("AdaptiveQuasiMonteCarlo", "BisectionDithering" -> 0.1), and I would prefer to use a MonteCarlo approach as GlobalAdaptive takes very long to calculate.

What I do is something like

points = Table[{ll, 
   NIntegrate[fn[r1, r2, th1, ph1, th3, ll], 
     {r1, 2, 1000}, {r2, 2, 1000}, {th1, 0, Pi}, {ph1, 0, 2 Pi}, {th3, 0, Pi}, 
     WorkingPrecision -> 30, MinRecursion -> 20, 
     MaxRecursion -> 30, AccuracyGoal -> Infinity, 
     PrecisionGoal -> 10, 
     Method -> {"AdaptiveQuasiMonteCarlo", "BisectionDithering" -> 0.1}]}, 
    {ll, 10, 100, 10}]

And I'm trying to have a meaningful plot from these points. I'm somehow sure it should be an exponential, but what comes out is quite random, meaning this:

Plot for "MultiPeriodic" method Monte Carlo, 1 000 000 MaxPoints

EDIT: I can't post a minimal example of the function without omitting details. What I can tell is that it's made of a polynomial which contains all the terms above, two sines in th1 and th3 (they multiply the whole expression), some exponentials in the denominator containing r1 and r2, and a giant square root in the denominator containing square terms of r1 and r2, and also multiplied by cos(th1) and cos(th3). there was another term r3, but it's everywhere substituted by another giant expression in terms of the other variables.

  • 4
    $\begingroup$ "... every time gives a different result with the MonteCarlo strategy" often means the integral is divergent. $\endgroup$ Jul 11, 2019 at 13:51
  • 5
    $\begingroup$ Without seeing the definition of fn it's hard to pinpoint what the exact reason is. $\endgroup$ Jul 11, 2019 at 14:45
  • $\begingroup$ The definition is really long and I don't think that someone would want to understand it all. I was asking for general indications. I added a graph done with MC, there it seems to be more or less exponential, as I was expecting, I was just wondering how to make the points a bit more "in line" $\endgroup$ Jul 11, 2019 at 17:19
  • $\begingroup$ Your integrand contains three angles th1, ph1, ph3. In my experience, angular integrals can very often be done analytically. In this way, maybe you could use Integrate to reduce the number of degrees of freedom that need to be integrated numerically. But, as @ThiesHeidecke says, it's difficult to help without having the function (or a minimal equivalent problem). $\endgroup$
    – Roman
    Jul 12, 2019 at 5:52
  • $\begingroup$ I was more eager to suggestions on how to use Mathematica's Monte Carlo integration options, something more like the first comment. Asking about function optimization in order to give better numerical results, would be given on another network. $\endgroup$ Jul 12, 2019 at 10:06

1 Answer 1


It was a matter of points only. When I increased the MaxPoints to 2 millions, it gave a neat exponential increase.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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