Figure 10.14:

Tracking 10 particles undergoing different growth-rate dispersion mechanisms; intrinsic growth-rate dispersion (left), and growth-dependent dispersion (right).

Figure 10.14

Code for Figure 10.14

Text of the GNU GPL.

main.py


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# Converted from dispmodel.m - particle size dispersion model simulation
import numpy as np
from misc import octave_save

nhalf = 5; npart = 2*nhalf
k = 10
np.random.seed(0)

# deterministic growth with random rates
g0 = 1.0; std = 0.1; size0 = 10.0
ntime = 15
time = np.arange(ntime)
x    = np.zeros((npart, ntime)); x[:, 0] = size0
g    = std * np.random.randn(npart) + g0

for i in range(ntime - 1):
    x[:, i+1] = x[:, i] + g

# stochastic growth
delta = 0.1; nsim = 1500
ipart = (np.random.rand(nsim) * npart).astype(int)
xran  = np.zeros((npart, nsim)); xran[:, 0] = size0
tau   = np.zeros(nsim)

for i in range(nsim - 1):
    tau[i+1] = tau[i] - np.log(np.random.rand()) / (k * npart)
    p = ipart[i]
    xran[:, i+1] = xran[:, i]
    xran[p, i+1] = xran[p, i] + delta

table1 = np.column_stack([time, x.T])
table2 = np.column_stack([tau,  xran.T])
octave_save('dispmodel.dat', ('table1', table1), ('table2', table2))