Math Is Fun Forum
  Discussion about math, puzzles, games and fun.   Useful symbols: ÷ × ½ √ ∞ ≠ ≤ ≥ ≈ ⇒ ± ∈ Δ θ ∴ ∑ ∫ • π ƒ -¹ ² ³ °

You are not logged in.

#1 2013-12-06 01:56:52

gAr
Member
Registered: 2011-01-09
Posts: 3,478

Finding average distance (circle)

From http://www.mathisfunforum.com/viewtopic … =19518&p=5 #117

A point 'P' inside a unit circle is chosen at random.
a) A direction is chosen at random at P and a line is drawn from P to the point in the circumference 'Q' in that direction. What is the expected length of the line segment PQ ?
b)  A direction is chosen at random at the center and a line is drawn from P to the point in the circumference 'Q' in that direction. What is the expected length of the line segment PQ ?

Analytical answer is given in #147.

Here, we'll see how to do a simulation in J.
Suppose 'r' is the distance between P and center of the circle, and θ is the angle chosen,
we can write the line segment length as


and

for (a) and (b), respectively.
r^2 must be uniformly distributed in [0,1], since area is proportional to r^2.

load 'trig'
r=:%:?10000000#0 
th=:2p1*?10000000#0
(+/%#)(%:(1-(r*sin th)^2))-r*cos th  NB. appx. 0.848544
(+/%#) %:(((r-cos th)^2)+(sin th)^2) NB. appx. 1.131613

"Believe nothing, no matter where you read it, or who said it, no matter if I have said it, unless it agrees with your own reason and your own common sense"  - Buddha?

"Data! Data! Data!" he cried impatiently. "I can't make bricks without clay."

Offline

#2 2013-12-06 02:44:33

bobbym
Administrator
From: Bumpkinland
Registered: 2009-04-12
Posts: 85,315

Re: Finding average distance (circle)

Hi gAr;

Could you pseudocode that?


In mathematics, you don't understand things. You just get used to them.
Of course that result can be rigorously obtained, but who cares?
Combinatorics is Algebra and Algebra is Combinatorics.

Offline

#3 2013-12-06 03:01:21

gAr
Member
Registered: 2011-01-09
Posts: 3,478

Re: Finding average distance (circle)

Hi,

Perhaps the R code would be more readable:

r=sqrt(runif(10000000,0,1))
th=2*pi*runif(10000000,0,1)
mean(sqrt(1-(r*sin(th))^2)-r*cos(th))   # 0.8485681
mean(sqrt(((r-cos(th))^2)+(sin(th))^2)) # 1.131671

"Believe nothing, no matter where you read it, or who said it, no matter if I have said it, unless it agrees with your own reason and your own common sense"  - Buddha?

"Data! Data! Data!" he cried impatiently. "I can't make bricks without clay."

Offline

#4 2013-12-06 05:45:34

bobbym
Administrator
From: Bumpkinland
Registered: 2009-04-12
Posts: 85,315

Re: Finding average distance (circle)

Hi gAr;

Okay got it.


In mathematics, you don't understand things. You just get used to them.
Of course that result can be rigorously obtained, but who cares?
Combinatorics is Algebra and Algebra is Combinatorics.

Offline

Board footer

Powered by FluxBB