What is average distance from center of square to some point?

Without loss of generality we find the average distance to the origin of a randomly selected point in the region $R:=\{(x,y): 0\leq y\leq x\leq L/2\}$. The region $R$ is a triangle that is one-eighth of the original square. The uniform density on this region is $$f(x,y)=\cases{8/L^2 &if $(x,y) \in R$\cr 0&\text{otherwise.}}$$

Therefore $$\begin{eqnarray} \text{average distance} &=& \int_0^{L/2} \int_0^x \sqrt{x^2+y^2}\,dy\,dx \ {8\over L^2} \\ &=& \int_0^{L/2}\int_0^1 x^2\sqrt{1+w^2}\,dw \,dx\ {8\over L^2} \\ &=& \int_0^1 \sqrt{1+w^2}\,dw\quad \int_0^{L/2} x^2\,dx \quad\ {8\over L^2} \\ &=& \int_0^1 \sqrt{1+w^2}\,dw\quad {1\over 3}\left({L\over 2}\right)^3 {8\over L^2} \\ &=& {L\over 6} \left(\sqrt{2}+\log(1+\sqrt{2})\right). \end{eqnarray} $$


Update: In the comments below, Isaac outlined a nice trig substitution to evaluate $I:=\int_0^1\sqrt{1+w^2}\,dw$. For completeness, here is another way. First do a change of variables $w=x/\sqrt{1-x^2}$, then use partial fractions to obtain $$\begin{eqnarray} I &=& \int_0^{1/ \sqrt{2}} {dx\over(1-x^2)^2} \\ &=& {1\over 4} \int_0^{1/ \sqrt{2}}\left[{1\over(1+x)^2}+{1\over(1-x)^2} +{1\over 1+x}+{1\over 1-x} \right]\, dx \\ &=& {1\over 4} \left[{1\over \sqrt{2}+1}+ {1\over \sqrt{2}-1} +(-\log(2)+\log(\sqrt{2}+2))+ (\log(2)-\log(2-\sqrt{2})) \right]\\ &=&{1\over 2}\left[\sqrt{2}+ \log(1+\sqrt{2}) \right]. \end{eqnarray}$$


For the average distance, what you want is the expected value of the distance from the center over the set of all points in the square, which is the sum of the probability of each point times the distance to that point. The problem is (more or less) that there are a whole lot of points and each point has infinitesimal probability. One way to deal with this is to use calculus.

Consider the square with sides of length 1 parallel to the axes and centered at the origin. This square is the set of points $(x,y)$ with $-\frac{1}{2}\le x\le\frac{1}{2}$ and $-\frac{1}{2}\le y\le\frac{1}{2}$. The total area of the square is 1. The sum of the probabilities of each point (not dealing with distance yet) is $\int_{-\frac{1}{2}}^{\frac{1}{2}}\int_{-\frac{1}{2}}^{\frac{1}{2}}\;dx\;dy=1$. Now, at each point, multiply the probability by the distance to get the average distance: $\int_{-\frac{1}{2}}^{\frac{1}{2}}\int_{-\frac{1}{2}}^{\frac{1}{2}}\sqrt{x^2+y^2}\;dx\;dy$.


I am not an expert, but my intuition and some empirical data tell me this is incorrect. The [final] integral you are calculating is the first step, but this is to summed distance from each point in the square to the center. To get the average, you must divide by the number of points, $L^2$, where $L$ is the side length. What you will find using a numeric approximation is that the average is $L/6 \times (\sqrt2+ln(1+\sqrt2))$. I have not checked via formal proof, but you will find that this passes a "gut check" when comparing two squares with side lengths $1$ and $3$. Using your integral on a square of side length $3$, the average is calculated near $10.33$, though the greatest distance possible is but $2.12$.


I believe this can be easily generalized for squares of side L. Consider the square with sides of length L parallel to the axes and centered at the origin. This square is the set of points $(x,y)$ with $-\frac{L}{2}\le x\le\frac{L}{2}$ and $-\frac{L}{2}\le y\le\frac{L}{2}$. The total area of the square is L^2. The distance of a random point (x,y) from the center is $F(x,y)=\sqrt{x^2+y^2}$. The probability density function for the distance is $f(x,y)=f(x)f(y)=\frac{1}{L}*\frac{1}{L}=\frac{1}{L^2}$ as the random variables for each axis are independent.

The expected value for the distance is $E=\int_{-\frac{L}{2}}^{\frac{L}{2}}\int_{-\frac{L}{2}}^{\frac{L}{2}}f(x,y)*F(x,y)\;dx\;dy=\int_{-\frac{L}{2}}^{\frac{L}{2}}\int_{-\frac{L}{2}}^{\frac{L}{2}}\frac{1}{L^2}*\sqrt{x^2+y^2}\;dx\;dy$.

Substituting $x=uL$ and $y=vL$ we have $E=L\int_{-\frac{1}{2}}^{\frac{1}{2}}\int_{-\frac{1}{2}}^{\frac{1}{2}}\sqrt{u^2+v^2}\;du\;dv={L\over 6} \left(\sqrt{2}+\log(1+\sqrt{2})\right)$