Task:
Eric has a friend, Ernie. Suppose that two flies sit in independent places, evenly distributed on the surface of the globes. Let D denote the Euclidean distance between Eric and Ernie (i.e., On a straight line along the inside of the globe).
Make a hypothesis about the probability density function D and give an estimate of its expected value, E (D).
So far I have created a function to create two points on the surface of the globe, but I'm not sure what to do next:
sample3d <- function(2)
{
df <- data.frame()
while(n > 0){
x <- runif(1,-1,1)
y <- runif(1,-1,1)
z <- runif(1,-1,1)
r <- x^2 + y^2 + z^2
if (r < 1){
u <- sqrt(x^2+y^2+z^2)
vector = data.frame(x = x/u,y = y/u, z = z/u)
df <- rbind(vector,df)
n = n- 1
}
}
df
}
E <- sample3d(2)
user9519686
source
share