8
$\begingroup$

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 {NIntegrate`XR[1]} contains NIntegrate`XR[1], which is not a symbol or an assignment to a symbol."
$\endgroup$
15
$\begingroup$

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.

$\endgroup$
  • 2
    $\begingroup$ If you're going to use low-discrepancy sequences anyway, NIntegrate[] does take a "QuasiMonteCarlo" setting… $\endgroup$ – J. M. will be back soon May 10 '15 at 8:26
  • $\begingroup$ @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. $\endgroup$ – Histograms May 10 '15 at 8:56
  • $\begingroup$ I have another related problem,can you help me?mathematica.stackexchange.com/questions/83069/… $\endgroup$ – WateSoyan May 10 '15 at 11:21
3
$\begingroup$

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[]]

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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