       Re: Length distribution of random secants on a unit square

• To: mathgroup at smc.vnet.net
• Subject: [mg95720] Re: Length distribution of random secants on a unit square
• From: Mark Fisher <particlefilter at gmail.com>
• Date: Sun, 25 Jan 2009 21:47:24 -0500 (EST)
• References: <glhjse\$np\$1@smc.vnet.net>

```On Jan 25, 6:53 am, andreas.kohlma... at gmx.de wrote:
> I need to work with the length distribution of random secants (of two
> random points on the perimeter) on a unit square. It's easy to
> generate some random data and a histogram. I used the following code
> (Mathematica 7.0):
>
> len = Norm[(First[#] - Last[#])] &;
> corners = {{0, 0}, {1, 0}, {1, 1}, {0, 1}};
> dir = {{1, 0}, {0, 1}, {-1, 0}, {0, -1}};
>
> p[t_] := Block[{n, r},
>   n = Mod[IntegerPart[t], 4];
>   r = FractionalPart[t];
>   corners[[n + 1]] + r dir[[n + 1]]
>   ]
>
> Histogram[
>  Table[len[{p[RandomReal[{0, 4}]], p[RandomReal[{0, 4}]]}], {100000}],
>   PlotRange -> All]
>
> The histogram shows a small increase close to 1, a big peak at 1 and
> some kind of exponential decay to Sqrt (= maximum).
>
> Does anybody know how to calculate this distribution exactly? What
> about moving from a unit square to a random rectangle or a random
> polygon? Thanks!

Hi,

I don't have an analytical solution. But I have a faster way to
generate the random draws:

ran = Norm /@ (Subtract @@@ Partition[
RandomChoice[{{z, 0}, {1, z}, {z, 1}, {0, z}}, 2*10^5] /. z :>
RandomReal[], 2]);

Here's another way that's a bit slower, but it can be applied to other
shapes:

xcoord = Interpolation[{{0, 0}, {1, 1}, {2, 1}, {3, 0}, {4, 0}},
InterpolationOrder -> 1];
ycoord = Interpolation[{{0, 0}, {1, 0}, {2, 1}, {3, 1}, {4, 0}},
InterpolationOrder -> 1];

ran1 = Norm /@ (Subtract @@@ Partition[
{xcoord[#], ycoord[#]} & /@ RandomReal[{0, 4}, 2*10^5], 2]);

--Mark

```

• Prev by Date: Re: Re: Frames on Density Plots in Version 7
• Next by Date: Re: Frames on Density Plots in Version 7
• Previous by thread: Length distribution of random secants on a unit square
• Next by thread: mathematica's syntax is very like lisp language