Created
September 20, 2011 14:59
-
-
Save fbrosser/1229329 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