如果我要定义坐标 和 哪里
我如何找到它们之间距离的期望值?
我在想,因为距离是由 期望值就是 ?
如果我要定义坐标 和 哪里
我如何找到它们之间距离的期望值?
我在想,因为距离是由 期望值就是 ?
Answers:
##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
如果我正确理解了您要寻找的内容,也许会有所帮助。您试图找出到随机点之间的距离,这些点的X值是根据unif(0,30)生成的,Y值是根据unif(0,40)生成的。我刚刚从每个分布创建了一百万个RV,然后将x和y绑定以为每个分布创建一个点。然后,我一直计算出点2和1之间的距离,直到点1,000,000和999,999之间的距离。平均距离是18.35855。让我知道这是否不是您想要的。
n <- 10^7; distance <- sqrt((runif(n,0,30)-runif(n,0,30))^2 + (runif(n,0,40)-runif(n,0,40))^2)
。通过计算标准误差,您可以在短时间内获得大约四个有效数字sd(distance) / sqrt(n)
。
从几何上看问题,很明显,凸集内两个独立,均匀,随机点之间的预期距离将略小于其直径的一半。(应该少一些,因为两个点很少位于拐角之类的极端区域内,并且更经常的情况是它们靠近中心且靠近中心。)因为此矩形的直径是,仅凭这种推理,我们就可以预期答案比 。
从期望的定义中获得准确的答案,即距离的概率加权值。通常,考虑边的矩形 和 ; 之后,我们将其放大到正确的尺寸(通过设置 并将期望值乘以 )。对于此矩形,使用坐标,均匀概率密度为 。然后,该矩形内的平均距离为
使用基本积分方法,这很简单,但是很痛苦。我使用计算机代数系统(Mathematica)来获得答案
The presence of in many of these terms is no surprise: it is the diameter of the rectangle (the maximum possible distance between any two points within it). The appearance of logarithms (which includes the arcsinh) is also unsurprising if you have ever investigated average distances within simple plane figures: somehow it always shows up (a hint of this appears in integral of the secant function). Incidentally, the presence of in the denominator has nothing to do with the specifics of the problem involving a rectangle of sides and : it's a universal constant.)
With and scaling up by a factor of , this evaluates to .
One way to understand the situation more deeply is to plot the mean distance relative to the diameter of for varying values of . For extreme values (near or much greater than ), the rectangle becomes essentially one-dimensional and a more elementary integration indicates the mean distance should reduce to one-third the diameter. Also, because the shapes of rectangles with and are the same, it is natural to plot the result on a logarithmic scale of , where it must be symmetric about (the square). Here it is:
With this we learn a rule of thumb: the mean distance within a rectangle is between and (approximately) of its diameter, with the larger values associated with squarish rectangles and the smaller values associated with long skinny (linear) rectangles. The midpoint between these extremes is achieved roughly for rectangles with aspect ratios of . With this rule in mind, you can just glance at a rectangle and estimate its mean distance to two significant figures.