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."
Answer
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.
Comments
Post a Comment