[1] What is the mean distance between two random points on the perimeter of a unit square?
[2] What is the mean distance between two random points on the interior of a unit square?
(In reply to
Part 2 in two different ways. by Jer)
The following program does the numerical integration for n = 2 to 20:
DEFDBL A-Z
RANDOMIZE TIMER
CLS
FOR n = 2 TO 20
tdist = 0: numdist = 0
st = 1 / (2 * n): incr = 1 / n
FOR x1 = st TO 1 STEP incr
FOR x2 = st TO 1 STEP incr
FOR y1 = st TO 1 STEP incr
FOR y2 = st TO 1 STEP incr
dist = SQR((x1 - x2) ^ 2 + (y1 - y2) ^ 2)
tdist = tdist + dist
numdist = numdist + 1
NEXT
NEXT
NEXT
NEXT
PRINT n, numdist, tdist / numdist
NEXT
The results for n=2 and n=3 agree with Jer's, but not for n=4:
n number of mean distance
distances
2 16 .4267766952966369
3 81 .4844370910985638
4 256 .5020037423450223
5 625 .5095129960727699
6 1296 .5133861693773205
7 2401 .5156379202536392
8 4096 .517060338925679
9 6561 .5180153643456192
10 10000 .5186872221213226
11 14641 .5191776353130316
12 20736 .5195464665681498
13 28561 .5198307970458254
14 38416 .5200545852311136
15 50625 .5202338670624983
16 65536 .520379702532333
17 83521 .5204999191245344
18 104976 .5206001822997849
19 130321 .5206846742324516
20 160000 .5207565364233291
I think it makes sense that the distance is continually increasing as it gets to include larger and larger almost-full diagonal lengths.
|
Posted by Charlie
on 2013-06-02 10:43:12 |