mercredi 23 juin 2021

Histogram of the 1D-random walk in Julia

This is a simulation of 100 1D-random "walkers" each taking 100 "steps" in either one direction or another by +1/-1.

using Plots
init = 0
walkers = 100
walk_length = 100
walks = cumsum(vcat(fill(init, 1, walkers),               # initial state
                    rand([-1, 1], walk_length, walkers)), # vertically append move direction
               dims=1)  # cumulative sum over the first dimension to get one walk per column
plot(walks, legend=nothing)

enter image description here

Since many walkers can end up at the same value at 100 steps, I would like to create a histogram at the end point, showing the amount of walkers there.
I think there might be a hist() function but I am not sure how to implement it.




Aucun commentaire:

Enregistrer un commentaire