Advertisement
Guest User

Untitled

a guest
Jul 16th, 2019
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.80 KB | None | 0 0
  1. # Sum of random jumps in the plane
  2. function rsum(n::Int)
  3. p = 1.0
  4. for j in 2:n
  5. p += exp(2pi * im * rand())
  6. end
  7. return p
  8. end
  9.  
  10. # Distance after n random jumps
  11. function rd(n::Int)
  12. abs(rsum(n))
  13. end
  14.  
  15. # Data array to build an histogram
  16. function sim(n::Int, m::Int = 22)
  17. datos = zeros(2^m) # Creamos la matriz de datos a rellenar
  18. for i in 1:2^m
  19. datos[i] = rd(n)
  20. end
  21. return datos
  22. end
  23.  
  24. # Plotting densities
  25. using StatsPlots, Statistics
  26. function dd(n::Int,m::Int=22)
  27. x = sim(n,m)
  28. density!(x, w = 2,
  29. xlabel = "Distance", #"Distancia recorrida",
  30. label = "Estimated density for $n jumps",
  31. fill = (0, 0.1, :orange))
  32. vline!([mean(x)],
  33. label = "Estimated mean for $n jumps: $(round(mean(x),digits=2))",
  34. line = :dash)
  35. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement