I am trying to solve a large system of differential equations using solve_ivp
.
from scipy import integrate
def dXdt(X,t):
return np.array([dadt(X,t), dbdt(X,t), dcdt(X,t), dddt(X,t])
sol = integrate.solve_ivp(dXdt, (0,100), initial_value_array, t_eval)
The dadt(X,t)
, dbdt(X,t)
, dcdt(X,t)
, dddt(X,t]
is a system of differential equations that I need to obtain from the following dictionaries:
da_dict = {'a': -1.0, 'b': 2.0, 'c': 4.0}
db_dict = {'b': -10.0, 'a': 1.0}
dc_dict = {'c': -4.0, 'b': 3.0}
dd_dict = {'b': 5.0}
as follows:
def dadt(X,t):
return -1.0*X[0] + 2*X[1] + 3*X[2]
where, X[0]
, X[1]
, X[2]
, x[3]
are represented by 'a'
, 'b'
, 'c'
, 'd'
in the dictionaries. Similarly,
def dbdt(X,t):
return -10*X[1] + 1*X[0]
def dcdt(X,t):
return -4*X[2] + 3*X[1]
def dddt(X,t):
return 5*X[1]
I have more than 100 differential equations I need to solve using solve_ivp. How do I write dadt(X,t)
, dbdt(X,t)
....from the dictionaries without actually writing them?