Error in a simulation of Buffon's needle problem for lattice
11 views (last 30 days)
Heello, every one. I had a proble in a script which is for a simulation of Buffon's needle problem for lattice.
I am a beginner, so I tried to see what I could do.
When I run the script, I cannot get a correct output.
I basically created the code based on the attached link.
N = 1000;
L = 0.20;
xb = L + rand(1,N)*(1-2*L);
yb = L + rand(1,N)*(1-2*L);
angs = rand(1,N)*360;
xe = xb + L*cosd(angs);
ye = yb + L*sind(angs);
ax = axes;
glines = 0:L:1;
for i = 1:length(glines)
for p = 1:length(glines)
q = sum(floor(xb/L) ~= floor(xe/L));
r = sum(floor(yb/L) ~= floor(ye/L));
n = plus(q,r);
k = (n-q&r)/N;