# The average distance from a square's center to its edges

The question is self explanatory.

Let me quickly explain my approach, and one of you smart fellows point out where I'm going wrong.

(I want to do this in polar on purpose. I feel I could probably do it in rectangular (since I did many similar problems in calc 3 class), but my polar is really weak and I want to improve it)

I called the distance from origin to edge at some angle theta: $$d(\theta)$$.

I imagined a circle within the square whose radius $$r$$ is a constant, and is equal to $$d(0)$$.

Since I'm looking for the average distance, I can integrate $$d(\theta)$$ from $$\theta=0$$ to $$\theta=2\pi$$, and then multiply the result by $$1 / (2\pi)$$.

Before I attempt to define our $$d(\theta)$$, I make another observation. Because of symmetry, I can just work with a $$\pi / 4$$ radian section, and generalize on that, since the average over the $$\pi / 4$$ section will be equal to the average over the entire square.

Now, to define $$d(\theta)$$.

My definition was: $$d(\theta) = \sqrt{r^2 + (r\tan(\theta))^2}$$

And plug the $$d(\theta)$$ into below integral:

$$(1/(0.25\pi)) (0.5) \int(d(\theta))^2d\theta$$ on the interval $$[0, 0.25\pi]$$

(Note that the first multiplier is because I am calculating the average over that interval. The second multiplier comes from the polar integral formula $$\int((1/2)r^2)d\theta$$.)

Now, I will spare you my subsequent computations, as they were a bit messy and I don't want to include them. My result is way too large and obviously incorrect.

Have you spotted an error in how I set this up? If not, I must be making a mistake in the computation.

I'd also greatly appreciate any additional wisdom. Thank you very much.

Why are you squaring $$r$$? That "polar integral formula" is the integral for the area. That's fine if what you're trying to do is to calculate the area of a square with side $$2r$$, but that's not the problem you claim to be trying to solve.

Now, one thing to watch for - the average depends on the probability distribution. Your setup here looks like a uniform distribution with respect to angle, while the rectangular coordinate setup you alluded to implies a uniform distribution with respect to length. Those are not the same thing; the latter should result in a slightly larger average distance. Make sure to be clear exactly what you're trying to find - the question is not as self-explanatory as you think.

In better news, your distance formula is correct for a square of side $$2r$$, and the reduction to an interval of length $$\frac{\pi}{4}$$ is good. Those parts won't cause problems.

• Thank you, you've blown my mind. I fully understand what you mean by the difference between the rectangular form I've mentioned (which would assume equal likelihood of landing on a unit length along the edges), versus what I've attempted (which assumes an equal likelihood of us starting from each unit angle). And I understand why the former would yield a slightly greater result. I had never thought of this, thank you. My question assumes a uniform probability distribution for angles. Given a random starting orientation, how long should an ant travel to get out of the square. – cheekybanana Feb 19 '19 at 14:57
• About squaring the r... The little rules like why we include an additional R in double polar integrals and why polar area integral does a "one half r squared" has never been explained to me, so it remains as black magic. That's probably why I use it where I shouldn't, because I simply don't understand it. Thanks for pointing it out, I will read on this particular topic and try to get a deeper understanding. Again, thanks for the amazing response. – cheekybanana Feb 19 '19 at 14:59

I may be wrong but wanted to propose my approach. Given a square whose verteces have coordiantes $$A(r,r)$$, $$B(-r,r)$$, $$C(-r,-r)$$, and $$D(r,-r)$$, we want to determine the average distance from the origin of the points on its perimeter. Of course, by symmerty, as you pointed out, we can just work between $$(r,0)$$ and $$A(r,r)$$. The distance of point $$P(r,y)$$ is $$d(y)= \sqrt{r^2+y^2}.$$ So in cartesian coordinates the integral would be $$\overline d = \frac{1}{r}\int_0^r \sqrt{r^2+y^2}dy.$$ If you want to work with the angle $$\theta$$ then the change of variable would be $$y = r\tan\theta.$$ Which means $$\theta = \arctan\frac{y}{r}.$$ Differentiating yields $$d\theta = \frac{r}{r^2+y^2}dy.$$ Therefore the integral becomes $$\overline d=\frac{1}{r^2}\int_0^{\frac{\pi}{4}}\left(r^2+r^2\tan^2\theta\right)^{\frac{3}{2}}d\theta.$$ EDITED thanks to jmerry. Hope now it's fine...

• There's a mistake there - you've got units of $\text{length}^{-1}$ for your average distance, because you multiplied when you should have divided. – jmerry Feb 19 '19 at 13:05
• right!! I'll correct it right away. Thanks! – dfnu Feb 19 '19 at 13:07
• @jmerry do you think it is correct now? – dfnu Feb 19 '19 at 13:13
• It is now a properly set up integral (for the average over the length-uniform distribution). – jmerry Feb 19 '19 at 13:14
• Hey, thank you. However, I can't select this as the answer because I was going for a uniform prob distribution with respect to angle. I do appreciate it though. And soz for not being clear enough. – cheekybanana Feb 19 '19 at 15:05