Skip to content

Instantly share code, notes, and snippets.

@fbrosser
Created September 20, 2011 14:59
Show Gist options
  • Save fbrosser/1229329 to your computer and use it in GitHub Desktop.
Save fbrosser/1229329 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