这是100个一维随机“步行者”的模拟,每个人在一个方向或另一个方向上以+1/-1的速度走100步
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)
由于许多步行者可以在100步时以相同的值结束,因此我想在终点创建一个直方图,显示那里步行者的数量
我认为可能有一个hist()
函数,但我不确定如何实现它
相关问题 更多 >
编程相关推荐