我有一个二维理想气体的分区箱模拟。所有的气体粒子最初都在盒子的左侧。然后随着时间的推移,它们开始不断地在两侧之间移动。
这是我的代码。
N=20; %total number of particles
nstep = 100;
n = randi(nstep,1);
n(1) = N; % initial conditions- number of particles on left side
for i = 2:nstep_5
r = rand(1,1);
if (r<n(i-1)/N)
n(i) = n(i-1) - 1; % Move atom from left to right
else
n(i) = n(i-1) + 1; % Move atom from right to left
end
end
time=(1:nstep)
我需要它们表现为有60%的概率从左向右移动 40%的概率从右向左移动。
我很难在这段代码中插入概率函数。有什么好办法吗?