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

You are not logged in.

- Topics: Active | Unanswered

Pages: **1**

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

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

**bobbym****Administrator**- From: Bumpkinland
- Registered: 2009-04-12
- Posts: 84,468

Hi gAr;

Could you pseudocode that?

**In mathematics, you don't understand things. You just get used to them.I have the result, but I do not yet know how to get it.All physicists, and a good many quite respectable mathematicians are contemptuous about proof.**

Offline

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

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

**bobbym****Administrator**- From: Bumpkinland
- Registered: 2009-04-12
- Posts: 84,468

Hi gAr;

Okay got it.

**In mathematics, you don't understand things. You just get used to them.I have the result, but I do not yet know how to get it.All physicists, and a good many quite respectable mathematicians are contemptuous about proof.**

Offline

Pages: **1**