|
|
|
![]() |
|
|||||||
|
||||||||
![]() |
|
|
Thread Tools | Rate Thread | Display Modes |
|
|
|
#1
|
||||
|
||||
|
Math Quiz 9
What's the average length of all the line segments which can be drawn inside a 1 inch square? (accurate to 5 decimal digits) (show your work) |
|
#2
|
||||
|
||||
|
Re: Math Quiz 9
point of clarification: I assume you mean the average of all possible line segments, which allows for intersecting and overlapping lines, if drawn within a single square. For example, you could have an X formed by two lines stretching from opposite corners, or you could have two lines that lay on top of each other, one going from corner to opposite corner and the other from the center to the same corner.
|
|
#3
|
|||||
|
|||||
|
Re: Math Quiz 9
by "inside" are they allowed to touch the edge of the square?
|
|
#4
|
||||
|
||||
|
Re: Math Quiz 9
Quote:
|
|
#5
|
||||
|
||||
|
Re: Math Quiz 9
My second attempt over lunch came up with 0.55272, but I'm pretty sure that's not right (It's too high). I know what i'm missing from my equations (logically, even if i haven't figured out how to express it mathematically just yet) though.
I just wish I remembered more of my calculus than I do! |
|
#6
|
||||
|
||||
|
Re: Math Quiz 9
I finally came up with 0.28967 as my final answer. Work below, colored white so people can ignore it until they've done their own work on the problem
Note: I don't remember my calculus very well anymore, so I had to use wolfram alpha to get me (hopefully) close enough!To solve this (assuming it's correct), I needed a couple of components and assumptions/assertions. Lets start with a simple case - the average length of line segments contained within a N length line. A good description of this can be found here: http://math.stackexchange.com/questi...ints-on-a-line What that boils down to, is that if I draw a line such that it intersects two edges of the square, taking the length of that line divided by 3 gives me the average length of every line segment that sits on that line. This little trick lets us GREATLY simplify the calculations, as we can use it to assume we're only looking at lines that intersect two walls of the square, and effectively ignore snort lines that don't intersect the lines of the square. So, with that in hand, we can now figure out the length of every possible line that intersects two lines of the square. This can be broken down into two categories: lines that intersect adjacent edges of the square, and lines that intersect non-adjacent edges. Due to the symmetry of a square, we know that the first group can be simplified into 4 repetitions (top/right, right/bottom, bottom/left, left/top) and the second into 2 repetitions (top/bottom, left/right). This will come in handy later. So, lets look at the case where you have adjacent sides. You really have two variables here, X and Y, each being an independent number between 0 and 1 representing their location on one of the sides, and the line that stretches between them. The length of that line, as defined by the Pythagorean Theorem is sqrt(x^2+y^2)... but remember we want that length/3 to get the average length of line segments along it. And remember that we have an infinite number of points between 0 and 1 for both x and y... calculus! So, written in a form wolfram alpha will recognize, integrating over x and y gives us: integrate integrate (sqrt(x^2+y^2)/3) dx dy from 0 to 1 from 0 to 1 or 0.255065. We can do the same for the case of non adjacent sides. Here the equation is a little trickier, but ultimately the line length is sqrt((x-y)^2+1). Dividing by 3 and integrating gives us: integrate integrate (sqrt((x-y)^2+1)/3) dx dy from 0 to 1 from 0 to 1 or 0.358879. Keep in mind that the average of an integral is that integral times 1/(b-a) - in this case, b-a is 1, so we don't need to do anything else. So, lets get these two numbers together. Remember, we have 4 sets of the adjacent sides, and 2 sets of the non-adjacent sides. And since those sides all integrated over the same values, we should just be able to average the sets, right? So, averaging those in proportion gives us: (4*0.255065 + 2*0.358879)/6 or 0.28967. |
|
#7
|
||||
|
||||
|
Re: Math Quiz 9
Do a sanity check with a simple Monte Carlo simulation.
|
|
#8
|
||||
|
||||
|
Re: Math Quiz 9
Wrapping up some loose ends... Quote:
|
|
#9
|
||||
|
||||
|
Re: Math Quiz 9
If I could,
The reason I don't think it matters is that let's say you were to take one end point of any line very very very close to the edge. If you keep pushing it infinetly closer, it's essentially on the edge already (limits woo), so it doesn't matter. |
|
#10
|
|||||
|
|||||
|
Re: Math Quiz 9
Ah okay that makes sense. Thanks!
|
|
#11
|
|||||
|
|||||
|
Re: Math Quiz 9
Enough hours have passed:
Allowing the borders of the square does NOT matter. The likelihood of one of the endpoints falling in any given area within the permissible bounds is proportional to the area. The lines at the edge of the square have length but zero area, so even if they're allowed, the selected point will "never" be on the edge. A bit more formally, the chances of a point on an edge being chosen is infinitesimally small and (excepting something massively discontinuous like a delta function) does not affect the integration over the area. |
|
#12
|
|||||
|
|||||
|
Re: Math Quiz 9
Quote:
|
|
#13
|
||||
|
||||
|
Re: Math Quiz 9
What's the average length of all the line segments whose endpoints both lie on the unit square's perimeter? |
|
#14
|
|||||
|
|||||
|
Re: Math Quiz 9
Quote:
Code:
import numpy as np
iterations = 100000
avg = 0
for i in range(1000):
print(i)
for j in range(iterations):
perimeter = 4*np.random.rand(2)
if perimeter[0] < 1:
y1 = 0
x1 = perimeter[0]
elif perimeter [0] < 2:
y1 = perimeter[0] - 1
x1 = 1
elif perimeter[0] < 3:
y1 = 1
x1 = 3 - perimeter[0]
else:
y1 = 4 - perimeter[0]
x1 = 0
if perimeter[1] < 1:
y2 = 0
x2 = perimeter[1]
elif perimeter[1] < 2:
y2 = perimeter[1] - 1
x2 = 1
elif perimeter[1] < 3:
y2 = 1
x2 = 3 - perimeter[1]
else:
y2 = 4 - perimeter[1]
x2 = 0
length = np.sqrt((x1-x2)**2+(y1-y2)**2)
avg = (avg*j + length)/(j+1)
with open("9.1.txt", "a") as f:
f.write(str(avg)+'\n')
Last edited by z_beeblebrox : 21-07-2016 at 11:44. |
|
#15
|
||||
|
||||
|
Re: Math Quiz 9
Close enough
Two billion samples yields a value about 0.003% less than that. Plotting the average vs the number of samples gives a rough view of when you've reached the point of diminishing returns. Note that this problem can be easily solved using all three methods discussed in this thread: Monte Carlo simulation Numerical Integration Symbolic Integration Standard deviation is not so meaningful when the distribution looks this this. |
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|