Cleve的角落:数学和计算上的Clyver

Scientific computing, math & more

一个广场上的两个随机点分开有多远?

您可以预期在单位广场随机选择的两点可以达到多远?我在Prehh Talwalkar维护的YouTube频道上发现了这个问题,介意你的决定。他正确地称之为a very hard puzzle。起初,我猜到了答案可能是1美元/ 2美元。但正确的答案比这更有趣。

Contents

模拟

Let's do a Monte Carlo simulation to get a numerical estimate. Sampling one million pairs of points doesn't take much time.

n = 1000000; sum = 0; rng(0)fork = 1:n x = rand(1,2); y = rand(1,2); delta = norm(x-y); sum = sum + delta;end格式shortdelta = sum / n
delta = 0.5214

It turns out that this run of the simulation generates a result that is accurate to the four digit precision of格式short。但我们可以找到确切的价值吗?

Quadruple Integral

预期的距离$ \ delta $,可以表达为此四倍积分,但符号工具箱找不到封闭式表单。

$$\delta = \int_0^1 \int_0^1 \int_0^1 \int_0^1 \! \sqrt{(x_1-y_1)^2 + (x_2-y_2)^2} \ \mathrm{d}x_1 \mathrm{d}y_1 \mathrm{d}x_2 \mathrm{d}y_2$$

Double Integral

Make the substitutions $x = x_1 - y_1$ and $y = x_2 - y_2$ and consider the integral over the four regions where these variables are positive or negative. The four integrals are equal to each other and we obtain this double integral.

$$\delta = 4 \int_0^1 \int_0^1 \! \sqrt{x^2 + y^2} \ (1-x)(1-y) \ \mathrm{d}x \mathrm{d}y$$

Numerical Integration

让我们以数字方式解决这个双倍积分。

F = @(x,y) 4*sqrt(x.^2+y.^2).*(1-x).*(1-y); delta = integral2(F,0,1,0,1)
delta = 0.5214

极坐标

Switch to polar coordinates, $r$ and $\theta$. The $\sqrt{x^2+y^2}$ term is simply $r$ and the double integral has two equal halves about the $45^o$ line, $\theta = \pi/4$.

$$ \ delta / 8 = \ int_0 ^ {\ pi / pi / 4} \ int_0 ^ {\ sec {\ theta}} r(1-r \ cos {\ theta})(1-r \ sin {\ theta})\ r \ mathrm {d} r \ mathrm {d} \ theta $$

象征性集成

The integrand is a polynomial in $r$.

symsrtheta真实的F = expand(r^2*(1-r*cos(theta))*(1-r*sin(theta)))
f = r ^ 2  -  r ^ 3 * sin(theta) -  r ^ 3 * cos(θ)+ r ^ 4 * cos(θ)* sin(θ)

The Toolbox can integrate this polynomial easily.

inner = int(F,r,0,sec(theta))
inner = 1/(12*cos(theta)^3) - sin(theta)/(20*cos(theta)^4)

The Toolbox can also do the outer integral over $\theta$.

Suffer = int(内部,θ,0,pi / 4)
outer = log(2^(1/2) + 1)/24 + 2^(1/2)/120 + 1/60

Multiply by 8.

delta = 8 *外
delta = log(2^(1/2) + 1)/3 + 2^(1/2)/15 + 2/15

生成A.latexrepresentation for $\delta$ to cut and paste later into this post.

乳胶(三角洲);

Numerical value

格式longdelta = double(delta)
Delta = 0.521405433164721

This Is My Final Answer

Here is the result.

δ= $ $ \ \压裂{\ ln \left(\sqrt{2}+1\right)}{3}+\frac{\sqrt{2}}{15}+\frac{2}{15}$$

三维维度

What about three dimensions? How far apart can you expect two points chosen at random in the unit cube to be? I'll leave that as a challenge and invite anyone who thinks they know the answer to post a comment.

谢谢

谢谢to Presh Talwalkar for this little nugget.




发布与MATLAB®R2017A

|

评论

To leave a comment, please click这里to sign in to your MathWorks Account or create a new one.