You are not logged in.
Pages: 1
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
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
Hi gAr;
Could you pseudocode that?
In mathematics, you don't understand things. You just get used to them.
If it ain't broke, fix it until it is.
Always satisfy the Prime Directive of getting the right answer above all else.
Offline
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
Hi gAr;
Okay got it.
In mathematics, you don't understand things. You just get used to them.
If it ain't broke, fix it until it is.
Always satisfy the Prime Directive of getting the right answer above all else.
Offline
Pages: 1