Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   Math and Science (http://www.chiefdelphi.com/forums/forumdisplay.php?f=70)
-   -   Math Quiz 9 (http://www.chiefdelphi.com/forums/showthread.php?t=149436)

Caleb Sykes 19-07-2016 18:13

Re: Math Quiz 9
 
Quote:

Originally Posted by Richard Wallace (Post 1597587)
So the distribution of lengths is Rayleigh. Neat example.

Rayleigh distributions can't have upper bounds though, right? This distribution will clearly have an upper bound at sqrt(2).

GeeTwo 19-07-2016 19:24

Re: Math Quiz 9
 
Quote:

Originally Posted by Richard Wallace (Post 1597587)
So the distribution of lengths is Rayleigh. Neat example.

What would the distribution look like if the line segments were contained in a cube (3D) boundary? That one may be easier to visualize using a Monte Carlo simulation.

Quote:

Originally Posted by Caleb Sykes (Post 1597589)
Rayleigh distributions can't have upper bounds though, right? This distribution will clearly have an upper bound at sqrt(2).

Similar, but not quite a Rayleigh Distribution.

Quote:

Originally Posted by Rayleigh distribution
The Rayleigh distribution, named for William Strutt, Lord Rayleigh, is the distribution of the magnitude of a two-dimensional random vector whose coordinates are independent, identically distributed, mean 0 normal variables.

After going to signed x ̅ = x1-x2 and y ̅ = y1-y2 components, but before collapsing the four quadrants, this problem is to evaluate the mean of the magnitude of a two-dimensional random vector whose coordinates are independent, identcially distributed, mean 0 triangular variables. That is, x ̅ and y ̅ are defined by the triangle function, max(0,1-abs(x)), rather than the normal distribution which would mean one proportional to e-ax2 (aka the Gaussian "bell curve"). As Caleb notes, this distribution, like the normal distribution, has no upper bound (an infinitely long tail).

If the working space were a cube, the small end of the distribution would start out with zero slope and a parabolic ramp of 4πr2. It would peak at a somewhat higher length (WAG of 0.6), have a similar change of curvature at length 1, and have an upper bound at √3.

Spoiler for Did you notice?:
For those who noticed, yes, the 2πr in the square case is the length of a circle of radius r, and 4πr2 is the area of a sphere of radius r in the cubic case. In the near-zero-radius limit, the size of the locus of points r units away from any given point is the population density.

Ether 19-07-2016 21:31

Re: Math Quiz 9
 
1 Attachment(s)
Quote:

Originally Posted by Richard Wallace (Post 1597587)
What would the distribution look like if the line segments were contained in a cube (3D) boundary?

...

Ether 20-07-2016 15:44

Re: Math Quiz 9
 

Wrapping up some loose ends...

Quote:

Originally Posted by smitikshah (Post 1596706)
by "inside" are they allowed to touch the edge of the square?
Quote:

Originally Posted by Ether (Post 1596712)
Does it matter?


Why or why not? Explain.


Hitchhiker 42 20-07-2016 16:41

Re: Math Quiz 9
 
Quote:

Originally Posted by Ether (Post 1597763)

Wrapping up some loose ends...



Why or why not? Explain.


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.

GeeTwo 21-07-2016 00:34

Re: Math Quiz 9
 
Quote:

Originally Posted by Ether (Post 1597763)

Wrapping up some loose ends...



Why or why not? Explain.


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.

Greg Woelki 21-07-2016 01:48

Re: Math Quiz 9
 
Quote:

Originally Posted by GeeTwo (Post 1597531)
Edit - and thanks, Caleb! I was thinking about attacking the same problem with the unit circle next, and I just realized I can adapt this technique to randomly pick r and theta with a uniform spatial distribution.

You can generate uniformly distributed coordinates in a unit circle much more easily, actually (if you look at genPolyPt() in my code, I do exactly that). Just setting r to the square root of a random number will correct the unevenness of the distribution.

Ether 21-07-2016 09:18

Re: Math Quiz 9
 


What's the average length of all the line segments whose endpoints both lie on the unit square's perimeter?



z_beeblebrox 21-07-2016 11:36

Re: Math Quiz 9
 
Quote:

Originally Posted by Ether (Post 1597872)


What's the average length of all the line segments whose endpoints both lie on the unit square's perimeter?



Modified above Monte Carlo code to solve this:

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')

2.1e7 iterations yields 0.73511, standard deviation 0.00095 (between blocks averaging 1e6 iterations). More iterations will give a more accurate answer.

smitikshah 21-07-2016 18:51

Re: Math Quiz 9
 
Quote:

Originally Posted by Hitchhiker 42 (Post 1597780)
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.

Ah okay that makes sense. Thanks!

smitikshah 21-07-2016 18:52

Re: Math Quiz 9
 
Quote:

Originally Posted by GeeTwo (Post 1597853)
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.

Thank you!

Ether 22-07-2016 11:30

Re: Math Quiz 9
 
5 Attachment(s)
Quote:

Originally Posted by z_beeblebrox (Post 1597886)
2.1e7 iterations yields 0.73511

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


Quote:

Originally Posted by z_beeblebrox (Post 1597886)
standard deviation 0.00095

Standard deviation is not so meaningful when the distribution looks this this.



GeeTwo 22-07-2016 14:14

Re: Math Quiz 9
 
Quote:

Originally Posted by Ether (Post 1598021)
Note that this problem can be easily solved using all three methods discussed in this thread:

Yes, apart from the different piecing together the different lengths, every term in the integrals for this problem appeared in Aren's solution.

Quote:

Originally Posted by Ether (Post 1598021)
Standard deviation is not so meaningful when the distribution looks this this.

This is a non-sequitur. Z.B. was referring to the standard deviation across groups of samples, not standard deviation across line lengths. However, the graph of the population also suggests that a nominal MonteCarlo solution might do well to treat these as three separate populations, as Ether has done with the integration cases.
  • The "same side" population ramps up from zero, follows a third order polynomial, and goes back to zero at 1.0.
  • The "adjacent side" population ramps up linearly from zero to one, has a kink (continuous value, discontinuous slope), and decays back to zero at the square root of two. As Ether has indicated implicitly, note that this side has to be weighted double the other two, because given the first point, the second point can be on only one "same" side, one "opposite" side, or two "adjacent" sides.
  • The "opposite side" set has no population with length less than unity, 13+% of its values between 1.00 and 1.01, and 39+% of its lengths between 1.0 and 1.1, and the population continues to decay down to the square root of two.

Edit: By decay, I mean that the population curve is concave up as it approaches zero, not necessarily an exponential decay.

Ether 22-07-2016 18:42

Re: Math Quiz 9
 
1 Attachment(s)

5000 samples of sample size 1,000,000.

Mean of the sample means = 0.735089
Standard Error of the Mean = 0.000361

GeeTwo 25-07-2016 12:03

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!


All times are GMT -5. The time now is 01:03.

Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi