Skip to content

Instantly share code, notes, and snippets.

@caiorss
Forked from fbrosser/gist:1229329
Created December 25, 2016 21:21
Show Gist options
  • Save caiorss/ec93dfe0c03f7c45d7cf929dc57c13d0 to your computer and use it in GitHub Desktop.
Save caiorss/ec93dfe0c03f7c45d7cf929dc57c13d0 to your computer and use it in GitHub Desktop.
Monte Carlo method MATLAB
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