Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Sum of random jumps in the plane
- function rsum(n::Int)
- p = 1.0
- for j in 2:n
- p += exp(2pi * im * rand())
- end
- return p
- end
- # Distance after n random jumps
- function rd(n::Int)
- abs(rsum(n))
- end
- # Data array to build an histogram
- function sim(n::Int, m::Int = 22)
- datos = zeros(2^m) # Creamos la matriz de datos a rellenar
- for i in 1:2^m
- datos[i] = rd(n)
- end
- return datos
- end
- # Plotting densities
- using StatsPlots, Statistics
- function dd(n::Int,m::Int=22)
- x = sim(n,m)
- density!(x, w = 2,
- xlabel = "Distance", #"Distancia recorrida",
- label = "Estimated density for $n jumps",
- fill = (0, 0.1, :orange))
- vline!([mean(x)],
- label = "Estimated mean for $n jumps: $(round(mean(x),digits=2))",
- line = :dash)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement