Data commit

This commit is contained in:
Ingy döt Net 2023-07-01 11:58:00 -04:00
parent 7387c8f97b
commit cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions

View file

@ -0,0 +1,16 @@
function piEstimate = monteCarloPi(numDarts)
%The square has a sides of length 2, which means the circle has radius
%1.
%Generate a table of random x-y value pairs in the range [0,1] sampled
%from the uniform distribution for each axis.
darts = rand(numDarts,2);
%Any darts that are in the circle will have position vector whose
%length is less than or equal to 1 squared.
dartsInside = ( sum(darts.^2,2) <= 1 );
piEstimate = 4*sum(dartsInside)/numDarts;
end

View file

@ -0,0 +1,5 @@
function piEstimate = monteCarloPi(numDarts)
piEstimate = 4*sum( sum(rand(numDarts,2).^2,2) <= 1 )/numDarts;
end

View file

@ -0,0 +1,5 @@
>> monteCarloPi(7000000)
ans =
3.141512000000000