Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
16
Task/Monte-Carlo-methods/MATLAB/monte-carlo-methods-1.m
Normal file
16
Task/Monte-Carlo-methods/MATLAB/monte-carlo-methods-1.m
Normal 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
|
||||
5
Task/Monte-Carlo-methods/MATLAB/monte-carlo-methods-2.m
Normal file
5
Task/Monte-Carlo-methods/MATLAB/monte-carlo-methods-2.m
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
function piEstimate = monteCarloPi(numDarts)
|
||||
|
||||
piEstimate = 4*sum( sum(rand(numDarts,2).^2,2) <= 1 )/numDarts;
|
||||
|
||||
end
|
||||
5
Task/Monte-Carlo-methods/MATLAB/monte-carlo-methods-3.m
Normal file
5
Task/Monte-Carlo-methods/MATLAB/monte-carlo-methods-3.m
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
>> monteCarloPi(7000000)
|
||||
|
||||
ans =
|
||||
|
||||
3.141512000000000
|
||||
Loading…
Add table
Add a link
Reference in a new issue