lpnguyen commited on
Commit
d3707c4
1 Parent(s): 3ce6a98

Create tools.py

Browse files
Files changed (1) hide show
  1. tools.py +24 -0
tools.py ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ def integrate(model, init, tmax, cg=None):
2
+ """
3
+ Iterate discrete time model
4
+
5
+ Args
6
+ ====
7
+ model (func) function that describes the discrete time model with input as follow (n, t, pars)
8
+ init (list) initial values
9
+ tmax (int) maximum time
10
+ cg (Config) parameters
11
+
12
+ Return
13
+ ======
14
+ list of the time and population values
15
+ """
16
+ population = [init]
17
+ t = 0
18
+ t_series = [t]
19
+ while t < tmax:
20
+ pop_t = model(population[-1], cg) if cg is not None else model(population[-1])
21
+ population.append(pop_t)
22
+ t += 1
23
+ t_series.append(t)
24
+ return (t_series, population)