1
$\begingroup$

I'm trying to compute 10-dimensional volume of a 9-sphere with radius r using Monte Carlo.

r = 1000
F = Piecewise[{{1, Sum[x[i]^2, {i, 10}] <= r}}, 0]
NIntegrate[F, {x[1], -1000, 1000}, {x[2], -1000, 1000}, {x[3], -1000, 1000}, {x[4], -1000, 1000}, {x[5], -1000, 1000}, {x[6], -1000, 1000}, {x[7], -1000, 1000}, {x[8], -1000, 1000}, {x[9], -1000, 1000}, {x[10], -1000, 1000}, Method -> {"MonteCarloRule", "Points" -> 1000000}]

But the results always off by the factor of 1e(P/2), where 1eP = The correct factoring. I'm wondering where did I do wrong? enter image description here

Also I want to clean up the code

NIntegrate[F, {x[1], -1000, 1000}, {x[2], -1000, 1000}, {x[3], -1000, 1000}, {x[4], -1000, 1000}, {x[5], -1000, 1000}, {x[6], -1000, 1000}, {x[7], -1000, 1000}, {x[8], -1000, 1000}, {x[9], -1000, 1000}, {x[10], -1000, 1000}, Method -> {"MonteCarloRule", "Points" -> 1000000}]

I try to do this

NIntegrate[F, Table[{x[i], -r, r}, {i, 10}], Method -> {"MonteCarloRule", "Points" -> 1000000}]

But it doesn't work as Table[] gives list. I need to make it into sequence somehow. But trying to apply Sequence[] to Table[] still give me a list. Is there anyway to get around this?

$\endgroup$
0

2 Answers 2

7
$\begingroup$

The sum of the squares should be less than or equal to r^2 rather than r.

d = 10;
r = 1000;
F = Piecewise[{{1, Sum[x[i]^2, {i, d}] <= r^2}}, 0];

NIntegrate[F, {x[1], -1000, 1000}, {x[2], -1000, 1000},
 {x[3], -1000, 1000}, {x[4], -1000, 1000},
 {x[5], -1000, 1000}, {x[6], -1000, 1000},
 {x[7], -1000, 1000}, {x[8], -1000, 1000},
 {x[9], -1000, 1000}, {x[10], -1000, 1000},
 Method -> {"MonteCarloRule", "Points" -> 1000000}]

2.54812*10^30

Attributes[NIntegrate]

{HoldAll, Protected}

The iterators must be a Sequence of lists rather than a list of lists and must be evaluated since NIntegrate has attribute HoldAll

NIntegrate[F, Evaluate[Sequence @@ Table[{x[i], -r, r}, {i, d}]],
 Method -> {"MonteCarloRule", "Points" -> 1000000}]

2.5401*10^30

$\endgroup$
9
$\begingroup$

In Mathematica 10, this computation may be made as follows:

Clear @ r
volSphere9[r_] = RegionMeasure[Ball[ConstantArray[0, 10], r]]

(π^5 r^10)/120

volSphere9[1000.]
2.55016*10^30
$\endgroup$
1
  • $\begingroup$ You can also integrate over regions: Integrate[1, Table[Unique[], {10}] \[Element] Ball[ConstantArray[0, 10], 10]]. $\endgroup$
    – kirma
    Aug 23, 2014 at 8:25

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