How to Find Expected Distance Between Two Uniformly Distributed Points?

distanceexpected valueuniform distribution

If I were to define the coordinates $(X_{1},Y_{1})$ and $(X_{2},Y_{2})$ where

$$X_{1},X_{2} \sim \text{Unif}(0,30)\text{ and }Y_{1},Y_{2} \sim \text{Unif}(0,40).$$

How would I find the expected value of the distance between them?

I was thinking, since the distance is calculated by $\sqrt{(X_{1}-X_{2})^{2} + (Y_{1}-Y_{2})^{2}})$ would the expected value just be $(1/30 + 1/30)^2 + (1/40+1/40)^2$?

Best Answer

##problem
x <- runif(1000000,0,30)
y <- runif(1000000,0,40)
Uniform <- as.data.frame(cbind(x,y))
n <- nrow(Uniform)
catch <- rep(NA,n)
for (i in 2:n) {
      catch[i] <-((x[i+1]-x[i])^2 + (y[i+1]-y[i])^2)^.5
}
mean(catch, na.rm=TRUE)
18.35855

If I understand correctly what you're looking for, maybe this helps. You're trying to figure out the distance between to random points, who's X values are generated from unif(0,30) and Y values are generated from a unif (0,40). I just created a million RV's from each of those to distributions and then bound the x and the y to create a point for each of them. Then I calculated the distance between point 2 and 1 all the way to the distance between points 1,000,000 and 999,999. The average distance was 18.35855. Let me know if this isn't what you were looking for.

Related Question