13
$\begingroup$

How can I calculate average distance from center of a square to points inside the square?

4 Answers 4

1

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)$

  • 0
    Didn't you notice that this question has already been answered (and nearly three years ago)?2014-11-22
12

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 &\text{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}$$

  • 0
    I don't pretend to understand your last step, but it agrees with Wolfram Alpha to 30 decimal places...2012-01-20
  • 1
    I admit that for the last step I just plugged into Maple. This integral can also be found in standard reference books.2012-01-20
  • 0
    In fact, I've just converted it to an equally hard problem: what's the average distance from the origin to a point randomly selected on the perimeter of a square? I'll try to think of a better explanation...2012-01-20
  • 2
    @TonyK: I think if you let $w=\tan\theta$ so that $dw=\sec^2\theta d\theta$, the integral becomes $$\int\sqrt{1+w^2}\,dw=\int\sec^3\theta d\theta.$$ That integral can be done by using integration by parts, the identity $\tan^2x+1=\sec^2x$, and solving for $\int\sec^3\theta d\theta$.2012-01-20
  • 0
    @Isaac Thanks for that. It is much better than the solution I came up with.2012-01-20
  • 1
    @ByronSchmuland: Integrands with $\sqrt{1+x^2}$, $\sqrt{1-x^2}$, or $\sqrt{x^2-1}$ are prime candidates for this sort of trigonometric substitution ($x=\tan\theta$, $x=\sin\theta$, and $x=\sec\theta$, respectively, so that the square root expression becomes a single trig function of $\theta$).2012-01-20
  • 0
    I was worried when I saw the update (just now) because it only agrees with the original when $L=3$. The inner integral in the original should also go up to $\frac L2$, and it is hard to define the upper limit when you go to $w=\frac yx$. Then when you pull the $x^2$ out of the square root it should become $x$.2015-06-19
  • 0
    @RossMillikan The update shows the calculation of a sub-problem, not the original problem. Also, there is no problem with $x^2$ in my integral: One factor of the $x$'s comes from being pulled out of the square root, the other one comes from the substitution $w=y/x$. That is, $dy=x \,dw$.2016-11-21
9

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$.

  • 3
    In other words this is $E\left[\sqrt{X^2+Y^2} \right]$.2010-12-26
  • 0
    @Trevor: I edited the first sentence to try to better cover the jump I'd made.2010-12-26
  • 0
    Can I just assume that average x is 1/4 and average y is 1/4, so the average distance is square(1/16+1/16)? (as a square is symmetric)2010-12-26
  • 0
    @Newcommer: because the relationship between the distance to a point in the square and the horizontal (x-direction) distance is non-linear, and similarly for the vertical, it won't work.2010-12-26
  • 0
    And one can possibly use [Green's Theorem](http://en.wikipedia.org/wiki/Green%27s_theorem) to simplify the calculation of the double integral.2010-12-27
  • 0
    That's the easy part! Evaluating the integral is the tricky part.2012-01-20
  • 0
    @TonyK: Mathematica tells me it's $\frac{1}{6}\left(\sqrt{2}+\sinh^{-1}1\right)$.2012-01-20
  • 0
    And Wolfram Alpha tells me that $\sinh^{-1} 1 = \log(1+\sqrt{2})$. So it was easy after all!2012-01-20
1

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$.

  • 0
    Simon, your intuition is correct. I've added a calculation in my answer.2012-01-20
  • 2
    Simon, I am curious to know how your *intuition and some empirical data* can yield a formula such as $(\sqrt2+\log(1+\sqrt2))/6$.2012-01-21
  • 2
    I used the numeric integration on my calculator to find the approximations for squares of side lengths 1 and 3. I saw that the ratio was linear with length L, so assumed that the integral was a constant. I then used google to search for the first six digits of the constant and found the reference. I wish I could claim something more impressive.2012-01-21