## Saturday, June 10, 2017

### An Expected Value problem II

We saw the explicit expression for the expected distance from a random point inside a rectangle to an edge of the rectangle in the previous post. We deal with a similar problem here.

There are a lot of reference in the internet to find the expected distance between two random points in a rectangle (Stack Exchange post). Here we ask 'what is the expected distance between two random points in a right angled triangle?'.

Basically the question is conceptually simple and the expression for the expected value can be readily written as follows:

$\mathbb{E}_T(L)=\displaystyle\int\limits_0^a \int\limits_0^{mx}\int\limits_0^a\int\limits_0^{mu}\sqrt{(x-u)^2+(y-v)^2}\,dv\,du\,dy\,dx$

where the right angled triangle is formed by the points $(0, 0)$, $(a, 0)$, and $(a, b)$. Also, for simplicity we used $m=b/a$.

Now, the difficulty of this integral (and the one that makes it different from the rectangle case) is the variable limits of the integral. In case of a rectangle, all the limits would be constants which makes it a little easier.

I'm not going to go through all the details and trouble I went through to solve this. But it is a combination of both Mathematica and a lot of paper work. Finally, after a few days and hell-a-lot completely messed up ideas later, I ended up with the following explicit expression for the expected value.

$\mathbb{E}_T(L)=\displaystyle\frac{a^3+b^3+2 d^3}{15 d^2}+\frac{a^2 }{15 b}\left(\frac{b^3}{d^3}+1\right)\text{csch}^{-1}\left(\frac{a}{b}\right)+ \frac{b^2}{15 a}\left(\frac{a^3}{d^3}+1\right) \text{csch}^{-1}\left(\frac{b}{a}\right)$

where $d=\sqrt{a^2+b^2}$.

I also wrote a small python program in an Online IDE to verify the correctness of this result.

For example, for $a=2$ and $b=3$, the formula gives

$\mathbb{E}_T(L)=\displaystyle\frac{1}{195} \left(35+26 \sqrt{13}\right)+\frac{4}{45} \left(1+\frac{27}{13 \sqrt{13}}\right) \text{csch}^{-1}\left(\frac{2}{3}\right)+\frac{3}{10} \left(1+\frac{8}{13\sqrt{13}}\right) \text{csch}^{-1}\left(\frac{3}{2}\right) \approx 1.047156999$

whereas the simulation gives $1.047117963$ after $10^8$ trials (takes about 200 secs).

Now for completion sake we also give the expected length of two random points in a rectangle. Here we have,

$\mathbb{E}_R(L)=\displaystyle\frac{a^5+b^5-\left(a^4-3 a^2 b^2+b^4\right)d}{15 a^2 b^2}+\frac{a^2}{6 b}\text{csch}^{-1}\left(\frac{a}{b}\right)+\frac{b^2 }{6 a}\text{csch}^{-1}\left(\frac{b}{a}\right)$

One of the nice things of putting these two together is, now we can also get an expression for the length of two random points lying on opposite sides of diagonal $AC$ of rectangle $ABCD$. Denoting this expected length by $\mathbb{E}_D(L)$ (D denoting diagonal), we have this relation from which we can find the required value.

$\mathbb{E}_R(L)=\displaystyle\frac{1}{4}\mathbb{E}_T(L)+\frac{1}{4}\mathbb{E}_T(L)+\frac{1}{2}\mathbb{E}_D(L)$

I tried to get an expression but it doesn't factor nicely but so it better left out. Hope you enjoyed this.

Until then
Yours aye
Me

## Wednesday, June 7, 2017

### An Expected Value Problem

Hi All... Recently I thought of a problem and tried to solve it. To my surprise, I ended up with a closed form solution for the same which I would like to share with you by this post.

Consider a rectangle $ABCD$ with the longest side $AB=CD=a$ units and shorter side $BC=DC=b$ units. Now pick a random point in this rectangle and a draw a straight line from this point at a random angle until the line meets the edge of the rectangle. What will be the expected value of this line?

We can attack the problem head-on with multiple integrals. Let $L$ be the length of the line. Then we have,

$\mathbb{E}(L)=\displaystyle\frac{1}{ab}\frac{1}{2\pi}\int\limits_{0}^{a}\int\limits_{0}^{b}\int\frac{y}{\sin t}\,dt\,dy\,dx$

The limits of the innermost integral have been left out purposely. We have to decompose the innermost integral. Let's do it this way. Consider the point $(x,y)$. We'll call it $P$.

Now draw a perpendicular from this point to each of the four sides of the rectangle. Let the perpendicular meet the side $X$ at $P_X$. Also join this point to each of the four vertices of the rectangle. This splits the entire rectangle into eight regions.

Consider the integral $I(a,b)$ (ignoring constant factors for time being) for the 'random lines' that end up in region $PAP_{AB}$

$I(a, b)=\displaystyle\int\limits_{0}^{a}\int\limits_{0}^{b}\int\limits_{\tan^{-1}(y/x)}^{\pi/2}\frac{y}{\sin t}\,dt\,dy\,dx$

But reflecting the 'random lines' about the $y$-axis, this integral also represents the $PP_{AB}B$, reflecting about the $x$-axis, this integral represents region $PP_{CD}D$, reflecting w.r.t both the axes it represents region $PCP_{CD}$. Solving this one integral covers four of the eight regions.

This is integral is pretty simple to solve with standard tables (or atmost with Mathematica). We get,

$I(a,b)=\displaystyle\frac{1}{6}\left(2b^3-a^3+d^3-3b^2d+3ab^2\ln{\frac{a+d}{b}}\right)$

where $d$ is the length of the diagonal of the rectangle.

Now for the other regions. We don't have to solve anything separately. Just interchange the values of $a$ and $b$. This amounts to rotating the rectangle by $90$ degrees and reasoning as before for the four other regions.

Note the nice thing that in going over the eight regions, we have made the full $2\pi$ radians possible for the 'random line'. So finally we have,

$\mathbb{E}(L)=\displaystyle\frac{4I(a,b)+4I(b,a)}{2\pi ab}$

Simplifying things we finally we end up with,

$\mathbb{E}(L)=\displaystyle\frac{a^3+b^3-d^3}{3\pi ab}+\frac{a}{\pi}\ln{\frac{b+d}{a}} + \frac{b}{\pi}\ln{\frac{a+d}{b}}$

(or)

$\mathbb{E}(L)=\displaystyle\frac{a^3+b^3-d^3}{3\pi ab} +\frac{a}{\pi}\text{csch}^{-1}\left(\frac{a}{b}\right)+ \frac{b}{\pi}\text{csch}^{-1}\left(\frac{b}{a}\right)$

The rectangle had a lot of symmetry that we were able to exploit. I'm trying to do the same for a given arbitrary triangle but it seems so very difficult with complicated integrals cropping at all places. I'll update if end up with something.

Until then,
Yours aye
Me