# File gillespie2.ode # Gillespie stochastic simulation for short reaction chain (-> s1 -> s2 ->) # # set kinetic parameters # par v0=20, k1=1, k2=2 # # initialize concentrations and time # init S1=0, S2=0, tr=0 # # set reaction propensities # a0=v0 a1=k1*s1 a2=k2*s2 # # determine the total of all propensities # a_total=a0+a1+a2 # # set the update rule for tr tr'=tr+log(1/ran(1))/a_total # # determine cumulative reaction probabilities (note, p2=1) p0=a0/a_total p1=(a0+a1)/a_total p2=(a0+a1+a2)/a_total # select next reaction to occur: # first generate a random number between 0 and 1 s=ran(1) #next, compares this number with the cumulative distribution: z0=(0<=s)&(s