Julia中随机游动的直方图

2024-05-16 10:58:23 发布

您现在位置:Python中文网/ 问答频道 /正文

这是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)

enter image description here

由于许多步行者可以在100步时以相同的值结束,因此我想在终点创建一个直方图,显示那里步行者的数量
我认为可能有一个hist()函数,但我不确定如何实现它


Tags: init方向filllength速度initialwalkusing