Skip to main content
. Author manuscript; available in PMC: 2014 Dec 7.
Published in final edited form as: J Theor Biol. 2013 Aug 30;338:10.1016/j.jtbi.2013.08.019. doi: 10.1016/j.jtbi.2013.08.019
 {S = 1,2, …, Nstates}
 {rates(j,k) = rate constant for jk, 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