i currently have two different scripts one with the while loop that says this:
close all; clear all; clc; format compact;experiments = 1;x = 0;while x~=3.14159 PRoject; experiments = experiments^10;end
and a for loop script that says this:
%counter for how many of the needles crossed a line
crosses=0;%number to trials being performed
x=0;%loop that continues for desired amount of trials
for t=1:experiments%center of a needle
mx=20*rand(1,experiments);my=20*rand(1,experiments);%random angle
a=rand(1,experiments)*pi*2;%start of needle
sx=(mx+cos(a))/2;sy=(my+sin(a))/2;%end of needle
ex=(mx-cos(a))/2;ey=(my-sin(a))/2;%see if needle crosses line
crossed=(ceil(min(sx,ex))==floor(max(sx,ex)));crosses=crossed+crosses;prob=crosses/experiments;p=mean(prob);endx=2/p
The output is this repeated until stopped:
x = Infx = 2x = Inf
Best Answer