Skip to main content
deleted 4 characters in body; Post Made Community Wiki
Source Link
Luboš Motl
  • 181.3k
  • 15
  • 413
  • 643
{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
{xt, yt, zt} = {1.1, 0, 0};

runs = 200000;
totalRinverse = 0;
total = 0;<br>

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
{xt, yt, zt} = {1.1, 0, 0};

runs = 200000;
totalRinverse = 0;
total = 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
added 223 characters in body
Source Link
Luboš Motl
  • 181.3k
  • 15
  • 413
  • 643

Bonus from Isaac

Mariano C. has pointed out the following solution by a rather well-known author:

http://books.google.com/books?id=ySYULc7VEwsC&lpg=PP1&dq=principia%20mathematica&pg=PA424#v=onepage&q&f=false

Bonus from Isaac

Mariano C. has pointed out the following solution by a rather well-known author:

http://books.google.com/books?id=ySYULc7VEwsC&lpg=PP1&dq=principia%20mathematica&pg=PA424#v=onepage&q&f=false

deleted 27 characters in body
Source Link
Luboš Motl
  • 181.3k
  • 15
  • 413
  • 643
{xt, yt, zt} = {1.1, 0, 0};

runs = 200000;
totalRinverse = 0;
total = 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

{xt, yt, zt} = {1.1, 0, 0};

runs = 200000;
totalRinverse = 0;
total = 0;<br>

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
{xt, yt, zt} = {1.1, 0, 0};

runs = 200000;
totalRinverse = 0;
total = 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

{xt, yt, zt} = {1.1, 0, 0};

runs = 200000;
totalRinverse = 0;
total = 0;<br>

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
added 389 characters in body
Source Link
Luboš Motl
  • 181.3k
  • 15
  • 413
  • 643
Loading
added 322 characters in body
Source Link
Luboš Motl
  • 181.3k
  • 15
  • 413
  • 643
Loading
added 170 characters in body
Source Link
Luboš Motl
  • 181.3k
  • 15
  • 413
  • 643
Loading
added 245 characters in body
Source Link
Luboš Motl
  • 181.3k
  • 15
  • 413
  • 643
Loading
added 68 characters in body; added 75 characters in body
Source Link
Luboš Motl
  • 181.3k
  • 15
  • 413
  • 643
Loading
added 948 characters in body; added 10 characters in body; added 6 characters in body
Source Link
Luboš Motl
  • 181.3k
  • 15
  • 413
  • 643
Loading
added 703 characters in body
Source Link
Luboš Motl
  • 181.3k
  • 15
  • 413
  • 643
Loading
added 203 characters in body
Source Link
Luboš Motl
  • 181.3k
  • 15
  • 413
  • 643
Loading
Source Link
Luboš Motl
  • 181.3k
  • 15
  • 413
  • 643
Loading