arexsutton
Re:Bertrand's Paradox
on Monday August 03, 2015 @10:31PM (#10001315)
I tried to script that together after the same idea occurred to me. What's interesting is the selection plane affects the outcome quite heavily. As the plane of random line selection increases in size, the probability of a random chord having length>sqrt3 seems to approach about 0.13
My math might be wrong; doesn't seem to be a floating point precision issue.
from math import sqrt
from random import random
def randomPoints(width):
return [
[random()*width-width/2, random()*width-width/2],
[random()*width-width/2, random()*width-width/2]
]
def chordCalc(points):
def quadraticEquation(a,b,c):
descriminant=(b**2 - 4*a*c)
if descriminant <= 0:
return None
x1 = (-b+sqrt(descriminant))/(2*a)
x2 = (-b-sqrt(descriminant))/(2*a)
y1 = sqrt(1-x1**2)
y2 = sqrt(1-x2**2)
return [[x1, y1],[x2,y2]]
m = (points[0][1] - points[1][1]) / (points[0][0] - points[1][0])
b = points[0][1] - m*points[0][0]
qa = 1+m**2
qb = 2*b*m
qc = b**2-1
return quadraticEquation(qa, qb, qc)
def distance(points):
return sqrt((points[0][1] - points[1][1])**2
+ (points[0][0] - points[1][0])**2)
chords=0
largeChords=0
sqrt3=sqrt(3)
while True:
if random() > 0.9999:
print float(largeChords)/chords
points = randomPoints(500) #adjust me down to 0.5 and see probability go to ~0.33
intersections=chordCalc(points)
if intersections is None:
continue
chords += 1
if distance(intersections) > sqrt3:
largeChords += 1
Re:Bertrand's Paradox
on Monday August 03, 2015 @09:30PM (#10001107)
The 1/4th answer has a typo.
"The probability of being hit is the probability of being inside the area of fire divided by the total area"
No.
The probability of being hit is the probability of being inside the area of fire.
The probability of being inside the area of fire is the area of fire divided by the entire area.