# Average distance between two random points on a square with sides of length $1$

"What's the average distance between two random points on a square with sides of length $1$?"

Here is an attempt which is wrong but I can't see how exactly.

Fix $(x, y) \in [0, 1]^2$

The average distance from $x$ to some $x' \in [0,1]$ is $\triangle x = 0.5x^2 + 0.5(1-x)^2$

Likewise $\triangle y = 0.5y^2 + 0.5(1-y)^2$

One could argue that the average distance between fixed $(x, y)$ and some $(x', y') \in [0,1]^2$ is then $\triangle r = \sqrt{\triangle y^2 + \triangle x^2}$

Then just take the average of $\triangle r(x,y)$. Double integrating $\triangle r$ in terms of x and y over the boundaries gives around 0.47. Close but not correct. Why doesn't this work?

• This might be interesting: youtube.com/watch?v=i4VqXRRXi68 – Thomas Jul 7 '16 at 16:03
• @Thomas That one explains a correct method but i'd like to know what is wrong with the reasoning in this one – saldukoo Jul 7 '16 at 16:07
• Ok, I didn't know if you had seen the video. Just a comment. – Thomas Jul 7 '16 at 16:07
• In general, the average of $f(X,Y)$ is not $f$ of the averages of $X$ and $Y$. – André Nicolas Jul 7 '16 at 16:13
• Did you divide by the size of the region you integrated over to get the average? – Will Fisher Jul 7 '16 at 16:13


Lets $\ds{\vec{r} \equiv \pars{x,y}}$ and $\ds{\vec{R} \equiv \pars{X,Y}}$.

\begin{align} \color{#f00}{?} & = \iint_{\pars{0,1}^{\,\, 4}}\ \verts{\vec{r} -\vec{R}}\,\dd^{2}\vec{r} \,\dd^{2}\vec{R} = \int_{\pars{0,1}^{\,\, 2}}\bracks{\int_{\pars{0,1}^{\,\, 2}}\ \verts{\vec{R} -\vec{r}}\,\dd^{2}\vec{R}}\dd^{2}\vec{r}\tag{2} \end{align}

With the identity $\ds{\pars{1}}$: \begin{align} &\!\!\!\!\!\int_{\pars{0,1}^{\,\, 2}}\verts{\vec{R} -\vec{r}}\,\dd^{2}\vec{R} = -\,{1 \over 3}\oint_{\pars{0,1}^{\,\, 2}} \root{\pars{X - x}^{2} + \pars{Y - y}^{2}} \bracks{\pars{Y - y}\,\dd X - \pars{X - x}\,\dd Y} \\[8mm]= &\ \!\!-\,{1 \over 3}\int_{0}^{1} \root{\pars{X - x}^{2} + y^{2}}\pars{-y}\,\dd X - {1 \over 3}\int_{0}^{1} \root{\pars{1 - x}^{2} + \pars{Y - y}^{2}}\bracks{-\pars{1 - x}}\,\dd Y \\[3mm] &\ \!\!-\,{1 \over 3}\int_{1}^{0} \root{\pars{X - x}^{2} + \pars{1 - y}^{2}}\pars{1 - y}\,\dd X - {1 \over 3}\int_{1}^{0} \root{x^{2} + \pars{Y - y}^{2}}\bracks{-\pars{-x}}\,\dd Y \\[8mm] = &\ {2 \over 3}\,y\,\mathrm{f}\pars{x,y^{2}} + {2 \over 3}\,x\,\mathrm{f}\pars{y,x^{2}}\tag{3} \\[3mm] &\ \qquad\qquad\mbox{where}\quad \mathrm{f}\pars{a,b} \equiv \int_{0}^{1}\root{\pars{\xi - a}^{2} + b}\,\dd\xi\tag{4} \end{align}
With $\ds{\pars{3}}$ and $\ds{\pars{4}}$, the expression $\ds{\pars{2}}$ is reduced to: \begin{align} \color{#f00}{?} & = \int_{0}^{1}\int_{0}^{1}\bracks{% {2 \over 3}\,y\,\mathrm{f}\pars{x,y^{2}} + {2 \over 3}\,x\,\mathrm{f}\pars{y,x^{2}}}\,\dd x\,\dd y \\[3mm] & = {2 \over 3}\int_{0}^{1}\int_{0}^{1}\mathrm{f}\pars{x,y}\,\dd y\,\dd x = {2 \over 3}\int_{0}^{1}\int_{0}^{1}\int_{0}^{1}\root{\pars{\xi - x}^{2} + y} \,\dd\xi\,\dd x\,\dd y \\[3mm] & = {4 \over 9}\int_{0}^{1}\int_{0}^{1} \left.\vphantom{\huge A^{a}} \bracks{\pars{\xi - x}^{2} + y}^{3/2}\,\,\right\vert_{\ y\ =\ 0}^{\ y\ =\ 1} \,\,\,\,\,\dd\xi\,\dd x \\[3mm] & = {4 \over 9}\int_{0}^{1}\int_{0}^{1} \braces{\bracks{\pars{\xi - x}^{2} + 1}^{3/2} - \verts{\xi - x}^{3}} \,\dd\xi\,\dd x \\[3mm] & = {4 \over 9}\int_{0}^{1}\int_{-x}^{1 - x} \pars{\bracks{\xi^{2} + 1}^{3/2} - \verts{\xi}^{3}} \,\dd\xi\,\dd x \\[3mm] & = {4 \over 9}\int_{0}^{1} \pars{\bracks{\xi^{2} + 1}^{3/2} - \verts{\xi}^{3}} \pars{\int_{0}^{1 - \xi} - \int_{\xi}^{1}\,\dd x}\,\dd\xi \\[3mm] & = {8 \over 9}\int_{0}^{1}\pars{\xi^{2} + 1}^{3/2}\,\dd\xi\ -\ \overbrace{{8 \over 9}\int_{0}^{1}\xi\pars{\xi^{2} + 1}^{3/2}\,\dd\xi} ^{\ds{{8 \over 45}\pars{4\root{2} - 1}}}\ +\ \overbrace{{8 \over 9}\int_{0}^{1}\pars{\xi^{4} - \xi^3}\,\dd\xi} ^{\ds{-\,{2 \over 45}}} \end{align} The remaining integration can be straightforward evaluated with the sub$\ds{\ldots\xi = \sinh\pars{\theta}}$. The final result becomes: $$\color{#f00}{?} = \color{#f00}{{1 \over 15}\bracks{2 + \root{2} + 5\ln\pars{1 + \root{2}}}} \approx 0.5214$$

You don't need a double integration to test your equation $$\triangle r = \sqrt{\triangle y^2 + \triangle x^2}\;.$$

Just try it with the two points $(0,1)$ and $(1,0)$. Then $\triangle x=\triangle y=\frac12$, but $\triangle r=1\ne\sqrt{\frac12}$.

Expectation is linear and thus distributes over sums and linear combinations, but it doesn't commute with arbitrary functions like squares and square roots.