Skip to content

Instantly share code, notes, and snippets.

@Davidnet
Created February 16, 2016 06:27
Show Gist options
  • Save Davidnet/91741f92c04e2bee9e1e to your computer and use it in GitHub Desktop.
Save Davidnet/91741f92c04e2bee9e1e to your computer and use it in GitHub Desktop.
Montecarlo Integral
using Distributions
e = 10.0^(-3);
p = 0.85;
variance = 4;
N = floor(Int, variance / ((1-p)*((e/2)^2))) + 1
u = Uniform(0,2);
x = rand(N);
y = rand(N);
z = rand(u, N);
result = sum((x.^2 + y.^2 .<= 1) & (z .<= x.^4 + y.^2))*2.0 / N
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment