One can approximate pi by looking at the relationship of randomly generated points on a sqaure with a circle inside.
function picircle(n)
n = n
N = 2n+1
x = range(-1, 1, length=N)
y = rand(N)
center = (0,0)
radius = 1
n_in_circle = 0
for i in 1:N
if norm((x[i], y[i]) .- center) < radius
n_in_circle += 1
end
end
println(4 * n_in_circle / N)
end
picircle(1000)
3.1424287856071964
However, I would like to use the Quasi-Monte Carlo method. Instead of using pseudo random numbers I want to use numbers from a Sobol-Sequence. I know how to generate them but I am not sure how to implement it in my code.
using Sobol
s = SobolSeq(2) # Creates a Sobol-Sequenz in 2 Dimensions
Aucun commentaire:
Enregistrer un commentaire