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/Octave/monte-carlo-methods-1.octave
Normal file
16
Task/Monte-Carlo-methods/Octave/monte-carlo-methods-1.octave
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
function p = montepi(samples)
|
||||
in_circle = 0;
|
||||
for samp = 1:samples
|
||||
v = [ unifrnd(-1,1), unifrnd(-1,1) ];
|
||||
if ( v*v.' <= 1.0 )
|
||||
in_circle++;
|
||||
endif
|
||||
endfor
|
||||
p = 4*in_circle/samples;
|
||||
endfunction
|
||||
|
||||
l = 1e4;
|
||||
while (l < 1e7)
|
||||
disp(montepi(l));
|
||||
l *= 10;
|
||||
endwhile
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
function result = montepi(n)
|
||||
result = sum(rand(1,n).^2+rand(1,n).^2<1)/n*4;
|
||||
endfunction
|
||||
Loading…
Add table
Add a link
Reference in a new issue