Figure 4.9:

Batch reactor with nth-order kinetics, r=kc_A^n, k_0=kc_{A0}^{n-1}=1, n<1.

Figure 4.9

Code for Figure 4.9

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
# Converted from order.m
import numpy as np
from misc import save_ascii

npts = 100
tfin = 10
K = 1.0
orders = np.array([-2, -1, -0.5, 0, 0.5, 1, 2], dtype=float)
norders = len(orders)
store = np.empty((npts, 0))

for i, n in enumerate(orders):
    t = np.linspace(0, tfin, npts)
    if n == 1:
        c = np.exp(-K*t)
    else:
        if n < 1:
            tstop = 1/((-n+1)*K)
            t = np.linspace(0, tstop, npts)
        arg = 1 - (-n+1)*K*t
        c = arg**(1/(-n+1))
    store = np.column_stack([store, t, c]) if store.size > 0 else np.column_stack([t, c])

save_ascii('order.dat', store)