Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- clc
- clear
- n = 100000000; %number of MC trials to run
- pts = bsxfun(@plus,rand(n,2), [-0.5,-0.5]); % generate n,2 points, centered at 0
- pts_in = sqrt(pts(:,1).^2 + pts(:,2).^2) <= 0.5; % determine which points are in
- pi = 4*sum(pts_in)/n % pi = ratio(area circle/area square)/r^2
Advertisement
Add Comment
Please, Sign In to add comment