{S = 1,2, …, Nstates} |
{rates(j,k) = rate constant for j → k, rates(j,j) = 0} |
for clock=1:clockmax do |
t = clock * dt |
rates = updaterates(S, rates) |
{updaterates(S, rates) updates row S of the matrix rates, since that is the only row that will be used in the current time step} |
ratesum = sum(rates(S, :)) |
if rand < ratesum * dt then |
cp = cumsum(rates(S,:) / ratesum) |
{cumulative summation of the rates in the state S and its normalization} |
r = rand {random number between 0 and 1 with uniform distribution} |
forS = 1:Nstates do |
if r < cp(S) then |
break |
end if |
end for |
end if |
end for |