# What's wrong with NIntegrate with "MonteCarlo" Method?

Bug fixed in version 10.2.0

My code is:

NIntegrate[1,
x ∈
ImplicitRegion[(x > 5 && x < 9) || (x > 11 && x < 13), {x}],
Method -> "MonteCarlo"]


Something wrong happens:

Block::lvsym: "Local variable specification {NIntegrateXR[1]} contains NIntegrateXR[1], which is not a symbol or an assignment to a symbol."


The correct syntax is

NIntegrate[1,
{x} ∈ ImplicitRegion[(x > 5 && x < 9) || (x > 11 && x < 13), x],
Method -> "MonteCarlo"]


The {x} has moved out in front. Alternatively you can do:

NIntegrate[Boole[(x > 5 && x < 9) || (x > 11 && x < 13)], {x, 5, 13},
Method -> "MonteCarlo"]


Also, if you want any more control over the Monte Carlo, you need to generate the random numbers yourself. This example uses the Quasi-Random Sobol generator in the MKL library provided you have it on your system (see documentation ) to produce low-discrepancy quasi-random numbers :

support = {0, 20}; (* we generate quasi randoms over the support *)
supLen = #[[2]] - #[[1]] &@support;
n = 10000;
randoms = BlockRandom[SeedRandom[Method -> {"MKL",Method -> {"Sobol",
"Dimension" -> 1}}]; RandomReal[support, n]];
supLen * Mean[Function[{x},
Boole[(x > 5 && x < 9) || (x > 11 && x < 13)]
] /@ randoms]


Other methods available are the Mersenne Twister, Niederreiter etc.

• If you're going to use low-discrepancy sequences anyway, NIntegrate[] does take a "QuasiMonteCarlo" setting… May 10, 2015 at 8:26
• @Guesswhoitis. Ahh right thanks, I just read the ref . Incidentally I was looking at the Classify function's SVM and it seems documentation is missing all over the place for the Method while things like NIntegrate look more fleshed out. May 10, 2015 at 8:56
• I have another related problem,can you help me?mathematica.stackexchange.com/questions/83069/… May 10, 2015 at 11:21

This issue has been fixed as of version 10.2.0.

NIntegrate[1, x ∈ ImplicitRegion[(x > 5 && x < 9) || (x > 11 && x < 13), {x}],
Method -> "MonteCarlo"]

(* 6.06192 *)


The syntax is fine, since x is taken to be a vector variable, similarly to NIntegrate[1, x ∈ Ball[]]