|
|
|
![]() |
|
|||||||
|
||||||||
![]() |
|
|
Thread Tools | Rate Thread | Display Modes |
|
|
|
#1
|
|||||
|
|||||
|
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 |
|
#2
|
||||
|
||||
|
Re: Math Quiz 9
That is the correct answer. Reps to you
![]() |
|
#3
|
||||
|
||||
|
Re: Math Quiz 9
Quote:
Your script has an error. Compare it to the one-line AWK script I posted. |
|
#4
|
|||||
|
|||||
|
Re: Math Quiz 9
OK, another follow-on challenge (cleared with Ether):
What is the average length of all the line segments which can be drawn within the unit circle (1 unit in radius, 2 units in diameter)? Reps for both the first numeric (good to 1 part per million) and first closed form solution. Edit: Of course, you must show your work in either case! Last edited by GeeTwo : 25-07-2016 at 14:05. |
|
#5
|
|||||
|
|||||
|
Re: Math Quiz 9
Quote:
Some warmup questions to this if you can't figure out where to start:
OBTW, with proper scaling, Greg's answer for the 100000-gon of area 1 provides an answer to the original problem good to within 1 part per 10,000: And, OBTW2: if you can find the closed form, each of the four questions can be calculated in fewer than 10 keystrokes on a calculator with the following buttons: Quote:
|
|
#6
|
|||||
|
|||||
|
Re: Math Quiz 9
I have posted this figure which I created to describe variables in my calculation of the length of the average line segment from a point on the edge of a circle to a point on the interior. I used this, or a very similar coordinate system, to solve all the "circle questions" except for the one about the mean square of the segments. I am also confident that the same questions can be answered for the sphere using a similar point of view.
|
|
#7
|
|||||
|
|||||
|
Re: Math Quiz 9
I did the integral for the average length of a line segment within a sphere, and found that the answer is rational! This problem was actually simpler to integrate (though just a bit trickier to set up) than any of the two-dimensional problems. If no one posts anything (yes, even a "hold on, I'm working it!") on the circle or sphere questions by Wednesday at 1800 US-CDT, I'll post my solutions so we can close out these quiz questions.
|
|
#8
|
||||
|
||||
|
Re: Math Quiz 9
Quote:
|
|
#9
|
|||||
|
|||||
|
Re: Math Quiz 9
Yes, as well as the intermediate case where one endpoint is on the sphere and the other is internal. I don't recall whether the mean square length was rational or not; I'll check this evening.
|
|
#10
|
|||
|
|||
|
Re: Math Quiz 9
0.9525383819936485
Sample size: 60 million |
|
#11
|
||||
|
||||
|
Re: Math Quiz 9
Post your code and we'll show you where you went wrong.
|
|
#12
|
||||
|
||||
|
Re: Math Quiz 9
Precisely ln(1+sqrt(2))/3 + sqrt(2)/15 + 2/15
Or approximately 0.52140543316 Rounded to 8 digits: 0.52140543 Rounded to 5 digits: 0.52141 A fun exercise in every integration tool I've ever learned, plus a cool rationalization trick I wasn't familiar with. The computation took a bit to hash through some arithmetic errors and one silly differential error (chain rule!). In practice you probably wouldn't bother to do this (or use a symbolic manipulation tool like Mathematica - this is how I checked my work), and sometimes there is no closed form for the integral. To get 8 digits simply run a larger Monte Carlo simulation (a couple lines of code instead of several pages of derivation). In the end we are always limited to some finite number of digits, so numerical methods win out. |
|
#13
|
|||||||||||
|
|||||||||||
|
Re: Math Quiz 9
Quote:
Edit - Now that I've had a chance to spend more than a few minutes on it, I see that wasn't the trick at all. I just need to go back and re-learn integration by parts. Edit2: Gathering up my paper notes, this is what I had so far (haven't double-checked everything yet): Checking the CRC Handbook integrals table (2000 edition): Quote:
Quote:
I know or quickly found all but the forms with ln(1+√(1+y2)) in an online table of integrals or the CRC table: http://2000clicks.com/mathhelp/Calcu...rals.aspx#CatL Quote:
Quote:
Quote:
Quote:
Quote:
Quote:
Quote:
Quote:
Last edited by GeeTwo : 17-07-2016 at 15:23. |
|
#14
|
||||
|
||||
|
Re: Math Quiz 9
Really nice work Aren and Gus.
Here's how I did it. |
|
#15
|
|||||
|
|||||
|
Re: Math Quiz 9
Now that this has been satisfactorily solved, I'll post a youtube video of this problem that I literally saw the week before Ether posted. I didn't feel right in just posting it, or claiming it as my own solution.
The problem gets to the 4ʃʃ(1-x)(1-y)√(x^2+y^2)dxdy GeeTwo derived, but then it does a polar coordinate substitution to make the integration "easier" It's another approach which gives a closed form solution, demonstrating that there can be multiple ways to validly solve a problem. |
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|