- /
-
Buffon's needle problem
on 17 Oct 2021
- 2
- 131
- 0
- 0
- 269
a=1;l=0.6;
axis([0,pi,0,a/2]);set(gca,'nextplot','add');
counter=0;n=1500;
x=rand(1,n)*a/2;phi=rand(1,n)*pi;
for i=1:n
if x(i)<l*sin(phi(i))/2
plot(phi(i),x(i),'r.');
frame(i)=getframe;counter=counter+1;
end
end
fren=counter/n;pihat=2*l/(a*fren);
text(1.5,0.4,['phihat=',num2str(pihat)]);