-
-
Save caiorss/ec93dfe0c03f7c45d7cf929dc57c13d0 to your computer and use it in GitHub Desktop.
Monte Carlo method MATLAB
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function [answer] = montecarlo() | |
N = 100000; | |
M = 0; | |
for i = 1:N | |
x = rand-0.5; | |
y = rand-0.5; | |
M = M + (sqrt((x^2+y^2)) < 0.5); | |
end | |
answer = M/N; | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment