CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
AllenDowney

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.

GitHub Repository: AllenDowney/ModSimPy
Path: blob/master/chap18.py
Views: 531
1
from modsim import *
2
3
def make_system(params, data):
4
G0, k1, k2, k3 = params
5
6
t_0 = data.index[0]
7
t_end = data.index[-1]
8
9
Gb = data.glucose[t_0]
10
Ib = data.insulin[t_0]
11
I = interpolate(data.insulin)
12
13
init = State(G=G0, X=0)
14
15
return System(init=init, params=params,
16
Gb=Gb, Ib=Ib, I=I,
17
t_0=t_0, t_end=t_end, dt=2)
18
19
from modsim import *
20
21
def slope_func(t, state, system):
22
G, X = state
23
G0, k1, k2, k3 = system.params
24
I, Ib, Gb = system.I, system.Ib, system.Gb
25
26
dGdt = -k1 * (G - Gb) - X*G
27
dXdt = k3 * (I(t) - Ib) - k2 * X
28
29
return dGdt, dXdt
30
31
32