Error in a simulation of Buffon's needle problem for lattice
6 views (last 30 days)
Show older comments
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;
plot(ax,[xb;xe],[yb;ye])
axis square
hold on
glines = 0:L:1;
for i = 1:length(glines)
xline(ax, glines(i));
end
for p = 1:length(glines)
yline(ax,glines(p));
end
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;
disp(k);
2 Comments
Walter Roberson
on 10 Aug 2022
k = (n-q&r)/N;
That line is suspicious. It is calculating
((n~=q) and (r~=0))/N
Answers (0)
See Also
Categories
Find more on View and Analyze Simulation Results in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!