吃饭的时候突然想到蒲丰投针问题。
在许多地方都遇到过此针,高中概统,大学概统,随机过程的概率部分,今天读Shannon的传记,他女儿不小心把针洒地上了。
问题描述:
在平面中有一组间隔为a的平行线,随机往平面上投掷重量均匀的长为 l ( l < a ) l(l<a) l(l<a)的针,其与平行线相交的概率与 π \pi π有关。
证明:
一种常见的证明方法是设运用概率统计的知识。
设针的中点到最相邻的平行线的距离为 x x x,夹角为 θ \theta θ。
考虑的区域为 x ∈ ( 0 , a 2 ) x\in(0,\frac{a}{2}) x∈(0,2a),否则将针归入相邻区域。 θ ∈ ( 0 , π ) \theta\in(0,\pi) θ∈(0,π)。
当 x < l 2 s i n θ x<\frac{l}{2}sin\theta x<2lsinθ时,针与线相交。
故 x x x ~ U ( 0 , a 2 ) U(0,\frac{a}{2}) U(0,2a), θ \theta θ ~ U ( 0 , π ) U(0,\pi) U(0,π),且两随机变量相互独立。
联合概率密度 f X θ ( X , θ ) = f X ( x ) f θ ( θ ) = 1 a 2 − 0 1 π − 0 = 2 a π f_{X\theta}(X,\theta)=f_X(x)f_{\theta}(\theta)=\frac{1}{\frac{a}{2}-0}\frac{1}{\pi-0}=\frac{2}{a\pi} fXθ(X,θ)=fX(x)fθ(θ)=2a−01π−01=aπ2
故所求概率
P
=
∬
x
<
l
2
s
i
n
θ
f
X
θ
(
X
,
θ
)
d
x
d
θ
=
2
a
π
∫
0
π
d
θ
∫
0
l
2
s
i
n
θ
d
x
=
2
a
π
l
2
2
=
2
l
a
π
P=\iint_{x<\frac{l}{2}sin\theta}f_{X\theta}(X,\theta)dxd\theta=\frac{2}{a\pi}\int_0^\pi d\theta\int_0^{\frac{l}{2}sin\theta}dx=\frac{2}{a\pi}\frac{l}{2}2=\frac{2l}{a\pi}
P=∬x<2lsinθfXθ(X,θ)dxdθ=aπ2∫0πdθ∫02lsinθdx=aπ22l2=aπ2l
Q.E.D.
由上述结果,我们可以得到: π = 2 l a P \pi=\frac{2l}{aP} π=aP2l
明白了这个问题如何解决,编写程序简单列算式即可。
%code for testing Buffon's neddle.
%2022/12/4
clear,close all
%%%%%%%%%%%%%%%%%%%%%%%%parameters setting%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
a=1;%distance between parallel
l=.5;%length of Buffon's neddle
x=0;%distance of middle point of Buffon's neddle to line
th=0;%angle of neddle and line
cnt=0;%count number of crossing
test_time=10000000;
%%%%%%%%%%%%%%%%%%%%%%%%parameters setting%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
tic
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%main function%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
for i=1:test_time
x=rand(1)/2;
th=rand(1)*pi;
if x<l/2*sin(th)
cnt=cnt+1;
end
end
2*l/(a*cnt/test_time)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%main function%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
toc
运行结果如下
可以看到,结果确实是随机的,而且并不是越大就一定越接近
π
\pi
π
由此可见,L·巴杰质疑拉兹瑞尼不无道理(笑)