|
|
|
![]() |
|
|||||||
|
||||||||
![]() |
|
|
Thread Tools | Rate Thread | Display Modes |
|
|
|
#1
|
||||
|
||||
|
Re: Math Quiz 9
Here's a script I wrote in order to try to solve this problem. My second attempt was to, for each line length find the area where the center of the line could be. This resulted, for line length 0 --> 1 in a box with quarter circles cut out. For 1 --> sqrt(2), it was a little more complicated. Overall, it gives the answer of 0.77019523
|
|
#2
|
||||
|
||||
|
Re: Math Quiz 9
Sanity-check your answer with a simple Monte Carlo simulation.
*this can be done with a one-line AWK script |
|
#3
|
||||
|
||||
|
Re: Math Quiz 9
What is a Monte Carlo simulation?
|
|
#4
|
||||
|
||||
|
Re: Math Quiz 9
https://en.wikipedia.org/wiki/Monte_Carlo_method
Randomly sample the set of all line segments, and find the mean length of only the segments in the sample (a finite number chosen to suit your computational resources, rather than the uncountably infinite number in the entire set). If the sampling matches the probability distribution/weighting of the set, then the law of large numbers says your mean will approach the true mean as sample size increases. |
|
#6
|
||||
|
||||
|
Re: Math Quiz 9
I ran the Monte Carlo thing in a python script and the answers, each run with 1,000,000 trials, were all around 0.333. I'm gonna keep thinking, though, how to get an exact answer.
Quote:
EDIT: I found the error - the value comes out to 0.521 Last edited by Hitchhiker 42 : 16-07-2016 at 22:01. |
|
#7
|
|||
|
|||
|
Re: Math Quiz 9
I am thinking the answer is a number that is very small (close to 0), as you can draw a ton more 0.000000000000000000000000000000000000000000000000 00000000000000000000000000000000000000000000000000 00000000000000000000000000000000000000000000000000 01 lines than you can 1 inch (or larger on a diagonal) lines.
|
|
#8
|
||||
|
||||
|
Re: Math Quiz 9
Quote:
Last edited by Hitchhiker 42 : 16-07-2016 at 22:01. |
|
#9
|
|||||
|
|||||
|
Re: Math Quiz 9
My simple Python Monte Carlo script gave me an average of 0.521408 (or 0.52141 rounded to 5 digits) in ~5e9 iterations (10 miles of hiking worth).
Code is below: Code:
import numpy as np
iterations = 10000000
avg = 0
for i in range(100000):
for i in range(iterations):
pos = np.random.rand(4)
length = np.sqrt((pos[0]-pos[1])**2+(pos[2]-pos[3])**2)
avg = (avg*i + length)/(i+1)
with open("test.txt", "a") as f:
f.write(str(avg)+'\n')
Code:
import numpy as np
f = np.loadtxt('test.txt')
print(np.average(f))
print(len(f))
Edit: Reps to whoever finds the bug in my code and explains what it does. Last edited by z_beeblebrox : 16-07-2016 at 22:57. Reason: New challenge |
|
#10
|
||||
|
||||
|
Re: Math Quiz 9
That is the correct answer. Reps to you
![]() |
|
#11
|
||||
|
||||
|
Re: Math Quiz 9
Now, how would you get the correct answer accurate to, let's say, 8 decimal places? |
|
#12
|
|||
|
|||
|
Re: Math Quiz 9
Makes no logical sense unless the question is improperly worded or bounded. You can fit an infinite number of lines in the box, and fact is, more lines closer to 0 in length fit in the box than lines averaging 0.52xxxx
|
|
#13
|
|||||
|
|||||
|
Re: Math Quiz 9
I think the problem is more "Choose two random points inside by a 1" square and measure the distance between them. Repeat infinitely. What's the average of those measurements?"
|
|
#14
|
||||
|
||||
|
Re: Math Quiz 9
Quote:
It makes no logical sense to say that there are "more" or "less" of one uncountably infinite thing than another uncountably infinite thing. |
|
#15
|
||||
|
||||
|
Re: Math Quiz 9
Quote:
Your script has an error. Compare it to the one-line AWK script I posted. |
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|