# Average Distance Between Two Points on a Line

I know this question has been answered many times, but I wanted to verify another method to solve this that I couldn’t find elsewhere. So I did the following:

I fixed a point P distant $$d$$ from one end of the line(of length $$L$$). Now, we’re free to choose the second point anywhere on the line. The first point divides the line into two parts of length $$d$$ and $$L-d$$.

$$\mathbf{Case \space 1: Second\space point \space lies \space in\space the \space first \space part}$$

By symmetry, the ‘average’ point will be exactly in the middle of the part, that is, at a distance $$d/2$$.

$$\therefore$$ Average distance between the $$2$$ points = $$d/2$$

$$\mathbf{Case\space 2: \space It \space lies \space in\space the\space latter\space part}$$

Using a similar argument,

Average distance in this case = $$\frac{L-d}{2}$$

Combining the two cases,

Effective Average distance $$=P(Case 1)\cdot \frac{d}{2} + P(Case 2)\cdot \frac{L-d}{2}$$

$$=\frac{d}{L}\cdot \frac{d}{2} + \frac{L-d}{L}\cdot \frac{L-d}{2}$$

$$=\frac{d^2+(L-d)^2}{2L}$$

Now, I tried to account for the fact that the initial first point could be situated anywhere on the line, by making $$d$$ a variable.

Let $$f(d)=\frac{d^2 + (L-d)^2}{2L}$$ , $$0\le d\le L$$

And then I found the average value of $$f(d)$$ in the interval $$[0,L]$$.

$$\bar{f(d)} = \frac{1}{L} \int_0^L \frac{d^2+(L-d)^2}{2L}dd$$

$$= {\frac{L}{3}}$$ Is what I did a valid way to do averages (i.e. taking care of one parameter at a time) or did I just get lucky? I want to know how averages really work.

Yes it's valid if you assume the points are uniformly and indepedently distributed along the line $$f_{P_1}(p_1) = \frac{1}{L}, \quad p_1 \in [0, L] \\ f_{P_2}(p_2) = \frac{1}{L}, \quad p_2 \in [0, L] \\ f_{P_1, P_2}(p_1, p_2) = \frac{1}{L^2}, \quad (p_1, p_2) \in [0, L]^2$$ The average distance is denoted $$E[\lvert P_2 - P_1 \rvert]$$ and can also be computed as the double integral \begin{align} E[\lvert p_2 - p_1 \lvert] &= \int_0^L\int_0^L \lvert p_2 - p_1\rvert f(p_1, p_2) dp_2 dp_1 \\ &= \int_0^L \int_0^L \frac{1}{L^2} \lvert p_2 - p_1\rvert dp_2 dp_1 \\ &= \frac{1}{L^2}\int_0^L \left[ \int_0^{p_1} -(p_2 - p_1)dp_2 + \int_{p_1}^L (p_2 - p_1)dp_2 \right]dp_1 \\ &= \frac{1}{L^2}\int_0^L \left[ \frac{1}{2} p_1^2 + \frac{1}{2}L^2 - L p_1 - \frac{1}{2} p_1^2 + p_1^2 \right]dp_1 \\ &= \frac{1}{L^2} \left[ \frac{1}{6}L^3 + \frac{1}{2}L^3 - \frac{1}{2}L^3 + \frac{1}{6}L^3 \right] \\ &= L / 3 \end{align}