{xt, yt, zt} = {1.1, 0, 0};
runs = 200000;
totalRinverse = 0;
total = 0;<br>0;
For[i = 1, i < runs, i++,
x = RandomReal[]*2 - 1;
y = RandomReal[]*2 - 1;
z = RandomReal[]*2 - 1;
inside = x^2/0.81 + y^2/0.81 + z^2 < 1;
total = If[inside, total + 1, total];
totalRinverse =
totalRinverse +
If[inside, 1/Sqrt[(x - xt)^2 + (y - yt)^2 + (z - zt)^2], 0];
]
res1 = N[total/runs / (4 Pi/3/8)]
res2 = N[totalRinverse/runs / (4 Pi/3/8)]
res2/res1
Luboš Motl
- 181.3k
- 15
- 413
- 643
Luboš Motl
- 181.3k
- 15
- 413
- 643
added 948 characters in body; added 10 characters in body; added 6 characters in body
Luboš Motl
- 181.3k
- 15
- 413
- 643