|
|
|
![]() |
|
|||||||
|
||||||||
![]() |
| Thread Tools | Rate Thread | Display Modes |
|
#91
|
|||||
|
|||||
|
Re: Math Quiz 9
Quote:
Code:
sum += sin(pi_2*random); Also, as no one has attempted a closed form solution for these averages, I'm attaching the solutions. I have solved all of the circle and sphere problems for both the mean length and the mean square length. As such, these results can be used to solve for the variance or standard deviation of the population, by calling that:
|
|
#92
|
||||
|
||||
|
Re: Math Quiz 9
Quote:
Code:
// naive implementation q1 := 2*pi*random; q2 := 2*pi*random; theta := abs(q2-q1); len := 2*sin(theta/2.0); sum := sum + len; // get rid of q1 and q2 theta := 2*pi*abs(random-random); len := 2*sin(theta/2.0); sum := sum + len; // get rid of theta len := 2*sin(pi*abs(random-random)); sum := sum + len; // get rid of len sum := sum + 2*sin(pi*abs(random-random)); // move factor of 2 outside the loop sum := sum + sin(pi*abs(random-random)); Some readers may be wondering why. It is due to the interaction between the symmetry of sin(x) around x=pi/2 and the shape of the pi*abs(random-random) distribution. The distribution of pi*abs(random-random) has the shape f(x):=1-x/pi. That function is symmetric about the point [pi/2,0.5] and has the property that, for any value "a" between -pi/2 and pi/2, f(pi/2-a)+f(pi/2+a) is always equal to 1. This interacts with the symmetry of sin(pi/2±a) to make the distribution sin(pi*abs(random-random)) be the same as sin(pi*random). Last edited by Ether : 11-08-2016 at 15:36. |
|
#93
|
||||
|
||||
|
Re: Math Quiz 9
Hey Math Quiz 9 thread readers, I'm a bit disappointed to see Gus' paper has only 4 downloads. He put a lot of work into it, and there's some very interesting stuff in there. If you're a math-gifted high school or college student, do yourself a favor and take a look at it. |
|
#94
|
|||||
|
|||||
|
Re: Math Quiz 9
Thanks, Ether! I really did put more work into making it readable than doing the math (though not nearly as much work as for a textbook, which I can vouch is a truly painstaking task if you've never done it). I don't think there's anything in there beyond second semester calculus; I know I was routinely doing more complex multidimensional integrals in second semester college physics.
Anyway, as I promised a while back, I came back to solving the square problem in radial coordinates. Once I didn't try too hard for symmetry and integrated over r first, it was pretty straightforward: As already established, the mean segment length in Cartesian coordinates is: Ḹ = 4∫01∫01 (1-x)(1-y)√(x2+y2) dx dyConverting to polar coordinates, placing the lower left corner of the square at the origin and aligning so that the x axis is along θ=0, the y axis along θ=π/2, we replace √(x2+y2) = r, x=rcosθ, y=rsinθ, and dxdy = rdrdθ. For bounds of integration, note that the lower and left sides of the square are θ=0 and θ=π/2 for 0<=r<=1. The right side is defined by rcosθ=1, or r=secθ for 1<=r <= √2. Similarly the top side is r=cscθ for 1<=r <= √2. This yields: Ḹ = 4∫0π/4∫0secθ(1- rcosθ)(1- rsinθ)r rdrdθ + 4∫π/4π/2∫0cscθ(1- rcosθ)(1- rsinθ)r rdrdθIn the first integral, we substitute α=θ, and in the second we substitute α=π/2-θ, which means cscθ = secα, cosθ = sinα, and sinθ = cosα. After these substitutions and a reversal of the limits of integration on the second term, the first and second term are identical, so combine them: Ḹ = 8∫0π/4∫0secα(1- rcosα)(1- rsinα)r rdrdαThe integrals over r are polynomials: Ḹ = 8∫0π/4[⅓r3 – ¼(cosα+sinα)r4 + ⅕cosαsinαr5 ]0secα dαTo solve the integral of sec3α, try tanαsecα. By the product rule, dtanαsecα/dα = sec3α + tan2αsecα = sec3α + (sec2α-1)secα = 2sec3α - secαWe can fill in with the well-known integral of secα to offset. The integral of 3tanαsec3α is seen to be sec3α: Ḹ = 2/15[5(secαtanα + ln|secα+tanα|)/2 – sec3α]0π/4Which is the same result achieved by Aren Siekmeier through a much longer process. -------------------------------------------------------- The above process did not result in a population density of segment lengths (many of Ether's histograms), which was my primary motivation to do the polar integral. To get this population, leave out the "r" factor representing segment length and integrate over angle only:Ƥ(r) = 4∫□(1- rcosθ)(1- rsinθ)rdθFor 0<=r <=1, the limits of integration are 0 to π/2. This is the integral over the intersection of the unit circle and this unit square: Ƥ(r)|r<=1 = 4[rθ - r2(sinθ-cosθ) + r3sin2θ/2]0π/2For 1<=r <= √2, the limits are cos-1(1/r) and sin-1(1/r) (or equivalently sec-1r and csc-1r); this is the integral over the part of the unit square which is outside of the unit circle. To evaluate sin(cos-1(1/r)) and cos(sin-1(1/r)), recall that sin2x = 1-cos2x: Ƥ(r)|r>=1 = 4[rθ - r2(sinθ-cosθ)+ r3sin2θ/2]cos-1(1/r)sin-1(1/r)As a sanity check, I calculated the population, population * length, and the integrals of each using excel with a step size of 0.001, and plotted all four (image and excel file attached). The sum of the population was 0.99999947, good to six decimal places, and the average length came out to 0.521405427, which is good to eight decimal places. Last edited by GeeTwo : 13-08-2016 at 17:13. Reason: Added "To evaluate sin(cos-1(1/r...", left out two 5s, another typo. |
|
#95
|
||||
|
||||
|
Re: Math Quiz 9
Quote:
The correct answer to the OP, as worded, is 0.33634 Aren was the first to articulate the key principle when he wrote: Quote:
Last edited by Ether : 22-08-2016 at 16:32. |
|
#96
|
||||
|
||||
|
Re: Math Quiz 9
Quote:
If you can switch the order of integration and then integrate the pdf over theta, then you should have a pdf for L only. I'm trying to wrap my head around why that pdf for L should be different than the one effected by a uniform weighting of dx1dx2dy1dy2 differential elements. The concept in my head is that there's no invertible change of variables with which to set up that translation. The transformation from coordinates to length is not injective, so the Jacobian in the change of variables is zero: hard to divide by, conceivably giving the ratio between our answers in some sort of limit. Or from another view the four-dimensional differential element is of measure zero within the one-dimensional one, reflected by a pdf for the coordinates that is somehow undefined or not finite?? I'm very curious if there is an appropriate pdf for the coordinate approach that would give this result. Or is it just the wrong way to look at the problem? This seems to boil down to the difference between: [1] Average distance between all unordered pairs of points [2] Average length of all line segments But what's the difference? Last edited by Aren Siekmeier : 22-08-2016 at 19:04. |
|
#97
|
||||
|
||||
|
Re: Math Quiz 9
Quote:
If you want the average distance between all unordered pairs of points, then you choose coordinates of pairs of points from a uniform random distribution, and compute the corresponding distance. If you want the average length of all segments, you randomly choose a segment length, a segment orientation, and the coordinates of the center of the segment. Then you discard any chosen segments which are not inside the square. If you run a Monte Carlo sim of that, you'll get 0.3363 ...and you'll get a pdf of L only, if you make a histogram of the data and adjust it to have an area of 1. |
|
#98
|
||||
|
||||
|
Re: Math Quiz 9
Quote:
I'd like to think it's possible to parametrize the choice of line segment by end points. Curious about the difference between that and the problem (simply choosing uniformly distributed end points) that we wrote 94 posts about. Obviously the end points of all line segments are not uniformly distributed in the square. I've got an idea for finding just what their distribution is that I might get to if ever get unswamped this week. |
|
#99
|
||||
|
||||
|
Re: Math Quiz 9
FWIW: seglen pdf for L theta x y versus x1 y1 x2 y2 sampling |
|
#100
|
||||
|
||||
|
Re: Math Quiz 9
Still stuck in my old ways aren't I.
Here's the distribution of endpoints using your sampling procedure. https://plot.ly/~compwiztobe/9/ Code:
from random import random from math import pi,cos,sin,sqrt import numpy def randseg(): hl=random()/sqrt(2) th=random()*pi cx=random() cy=random() return [cx-hl*cos(th),cx+hl*cos(th),cy-hl*sin(th),cy+hl*sin(th)] def inbox(seg): return(all([x>=0 and x<=1 for x in seg])) def go(n): l=[] for i in range(n): x=randseg() if inbox(x): l.append(x) return(l) def pts(l): p=[] for x in l: p.append([x[0],x[2]]) p.append([x[1],x[3]]) return(p) data=pts(go(1000000)) #then bin and plot 2d histrogram with plotly API |
|
#101
|
|||||
|
|||||
|
Re: Math Quiz 9
Quote:
When you take this into account, the integral in the denominator becomes: If you then integrate the adjusted calculation using 1/8 for the deominator, just substitute r for L and α for θ, and you will have the third equation of my most recent post in this thread. Addition: Also, the idea of the average segment in a square of size 1 being within 1% of the average segment on any of its sides is .. counter-intuitive, to say the least. Last edited by GeeTwo : 22-08-2016 at 22:24. |
|
#102
|
||||
|
||||
|
Re: Math Quiz 9
For the center point at (0.1, 0.1) and length 0.2, the candidate segments are the diameters of a circle of radius 0.1. For the center point at (0.1, 0.1) and length 1.0, the number of candidate segments is zero. |
|
#103
|
|||||
|
|||||
|
Re: Math Quiz 9
Quote:
Here's another case which more clearly shows the fallacy.
Solving the first question in Cartesian coordinates, we find the answer to be (√2 + ln(1+√2))/3 = 0.765... Solving the second question using the logic used by Ether to count radials, the answer comes out to √2/2 = 0.707.. As the quadrant of the large circle includes all the same points as the unit square plus others which area all farther away than either average, there is a fallacy here somewhere. By weighting the density by r, the second question is properly answered 2√2//3 = .942... Addition: To more fully explore this point, I propose the following questions:
Last edited by GeeTwo : 23-08-2016 at 08:32. Reason: Addition: on |
|
#104
|
||||
|
||||
|
Re: Math Quiz 9
Question for Gus: What is the average length of all the vertical line segments in a unit circle? |
|
#105
|
||||
|
||||
|
Re: Math Quiz 9
Quote:
Spoiler for Thoughts:
Work attached below. EDIT: Gosh darn I only did those with both points touching the the edges. Lemme work on that. Last edited by Hitchhiker 42 : 23-08-2016 at 11:27. |
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|