Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

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?

share|improve this question

closed as off-topic by RunnyKine, m_goldberg, Öskå, Oleksandr R., bobthechemist Aug 22 at 23:28

  • The question does not concern the technical computing software Mathematica by Wolfram Research. Please see the help center to find out about the topics that can be asked here.
If this question can be reworded to fit the rules in the help center, please edit the question.

2 Answers 2

up vote 7 down vote accepted

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

share|improve this answer

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
share|improve this answer
    
You can also integrate over regions: Integrate[1, Table[Unique[], {10}] \[Element] Ball[ConstantArray[0, 10], 10]]. –  kirma Aug 23 at 8:25

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