|
|
|
![]() |
|
|||||||
|
||||||||
![]() |
|
|
Thread Tools | Rate Thread | Display Modes |
|
|
|
#1
|
||||
|
||||
|
Re: Math Quiz 9
Cool, I much prefer how you dropped to the double integral, I don't think about stats enough when doing these things.
Quote:
The immediate trig sub works wonders on the rest of it.Thanks for the link! |
|
#2
|
|||||
|
|||||
|
Re: Math Quiz 9
Quote:
Quote:
|
|
#3
|
||||
|
||||
|
Re: Math Quiz 9
Quote:
The integers are countably infinite. The reals are uncountably infinite. Quote:
![]() If you mean "the set of all even integers has an asymptotic density of ˝", then yes, it's meaningful. Otherwise, not. Last edited by Ether : 17-07-2016 at 23:08. |
|
#4
|
|||||
|
|||||
|
Re: Math Quiz 9
These solutions are quite above my mathematics level, but nonetheless I can somewhat follow along, thanks for the cool thread.
|
|
#5
|
|||||
|
|||||
|
Re: Math Quiz 9
Quote:
Quote:
A far as I am aware, any argument that decides the statement "Half of the integers are even." as meaningless can also be used to decide the concept of "average length of a line segment located within the unit square" as meaningless -- or worse. Edit: Quote:
Here's a bit more precise statement: For every set of consecutive integers with a non-zero, even number of members, exactly half are even. Last edited by GeeTwo : 18-07-2016 at 06:38. Reason: fixed cardinality, added last sentence. |
|
#6
|
||||
|
||||
|
Re: Math Quiz 9
FWIW Last edited by Ether : 18-07-2016 at 01:07. |
|
#7
|
|||||
|
|||||
|
Re: Math Quiz 9
It's worth enough to make me reconsider doing theta integration first so I can generate a closed form for this distribution.
![]() |
|
#8
|
||||
|
||||
|
Re: Math Quiz 9
Descriptive statistics for 10 million random samples: Code:
mean 0.52151 median 0.51212 mode* 0.48 meansq 0.33346 IQR 0.37633 std 0.24795 var 0.06148 skewness 0.18406 kurtosis -0.66077 *based on 100 bins, max slope of smoothed percentile vs length |
|
#9
|
|||||
|
|||||
|
Re: Math Quiz 9
Quote:
So thanks for the sanity check! Other stats so far:
Definitely an easier way to go unless that last one proves nastier than it looks. Also, doing the integral this way explains the sudden change in behavior of the histogram at length=1. |
|
#10
|
||||
|
||||
|
Re: Math Quiz 9
Here is a generalized Monte Carlo simulation in python for the average line segment length in any regular polygon with one square unit of area:
Code:
%matplotlib inline
import matplotlib.pyplot as plt
import numpy as np
import time
def isInPoly(r,theta,cr,n):
theta = theta%(2*np.pi/n) #Rotates point to first "sector" of the polygon for simplicity
x = r*np.cos(theta)
y = r*np.sin(theta)
x1 = cr #x coordinate of vertex at theta = 0
y1 = 0.0 #y coordinate of vertex at theta = 0
x2 = cr*np.cos(2*np.pi/n) #x coordinate of vertex at theta = 2pi/n
y2 = cr*np.sin(2*np.pi/n) #y coordinate of vertex at theta = 2pi/n
if y < ((y2 - y1)/(x2 - x1))*(x - x1) + y1: #Check using 2-point line formula
return True
else:
return False
def genPolyPt(n, cr):
'''Return tuple of random rectangular coordinate within an n-sided regular polygon centered
at (0,0) with circumradius = cr and a vertex at (cr,0).'''
r = cr*(np.random.random()**0.5) #Square root correction ensures even probability distribution over area
theta = 2*np.pi*np.random.random()
x = r*np.cos(theta)
y = r*np.sin(theta)
if r < cr*np.cos(np.pi/n): #If r < apothem of polygon then point is in the polygon's incircle
return x,y
if isInPoly(r,theta,cr,n): #Checks if point is between polygon and incircle
return x,y
else: #If point not in polygon
return genPolyPt(n, cr)
t = time.time()
n = 4 #Number of sides of polygon
area = 1.0
trials = 10**7 #Number of random samples
cr = (area/(n*np.sin(2*np.pi/n)/2))**0.5 #Solves for circumradius that yields polygon with specified area
total = 0.0
#fig = plt.figure()
#ax1 = fig.gca()
#xlist = []
#ylist = []
for i in range(trials):
x1,y1 = genPolyPt(n,cr)
x2,y2 = genPolyPt(n,cr)
#xlist.append(x1)
#ylist.append(y1)
total += ((x2-x1)**2 + (y2-y1)**2)**0.5
#plt.xlim(-.85, .85)
#plt.ylim(-.85, .85)
#ax1.set_aspect('equal')
#ax1.scatter(xlist,ylist,s=5)
print(total/trials)
print(time.time()-t)
Triangle: 0.554367342879 Square: 0.521395852676 Pentagon: 0.514797872593 Hexagon: 0.512588030594 Heptagon: 0.51176618103 Octagon: 0.511213933924 Nonagon: 0.511120940654 Decagon: 0.511039068646 25-gon: 0.510860752385 100-gon: 0.510794294963 1000-gon: 0.510750983962 1000000-gon: 0.510902061585 Can anyone think of another general way of generating a random point in an n-gon that is more efficient than mine for small values of n (without sacrificing significantly for larger values of n, of course)? When n=3, my program is discarding almost 60% of the points it generates. |
|
#11
|
|||||
|
|||||
|
Re: Math Quiz 9
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. |
|
#12
|
||||
|
||||
|
Re: Math Quiz 9
Quote:
|
|
#13
|
||||
|
||||
|
Re: Math Quiz 9
...
|
|
#14
|
||||
|
||||
|
Re: Math Quiz 9
Quote:
Quote:
The error bounding condition is still error <= 1/2n, so not quite that fast. You just happen to hit the limit exactly on every other term. |
|
#15
|
||||
|
||||
|
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. |
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|