我正在尝试编写一个函数来计算两个腔室具有相同数量的粒子所需的迭代次数。系统的演变被认为是一系列时间步长,从t = 1开始。每个时间步骤完全 一个粒子将通过这个洞,我们假设粒子不会相互作用。概率 粒子将从左侧移动到右侧室是pLR = NL / N,并且粒子的概率将是 从右到左移动的房间是pRL = 1 - pLR =(N - NL)/ N.
模拟将按以下方式迭代进行:
到目前为止,这是我的代码。
function t = thermoEquilibrium(N, r) %N = number of particles, r = random numbers from 0-1
h = []; %right side of the chamber
v = []; %left side of the chamber
rr = r;
k = false
NL=N-length(h) %This is especially where i suspect i make a mistake.
%How can the probability change with every iteration?
pLR = NL/N;
pRL = 1 - pLR;
count = 1
while k==false
for i = r
if i<=pLR
h(end+1)=i
rr = rr(rr~=i)
end
end
for l = h
if pRL>l
v(end+1) = l
h = h(h~=l)
end
end
if length(h)==N/2 && length(v)==N/2
k=true
end
count = count + 1
end
t = count
有人能指出我的方向,所以我可以更接近一些有用的东西吗?