I am new to SymPy and Python in general, and I am currently working with Python 2.7 and SymPy 0.7.5 with the objective to: a) read a system of differential equations from a
If you are going to solve the system in the same script that reads the file (so systemOfEquations
is available as a global variable), and if the only variables used in systemOfEquations
are x
, y
and possibly t
, you could define dX_dt
in the same file like this:
def dX_dt(X, t):
vals = dict(x=X[0], y=X[1], t=t)
return [eq.evalf(subs=vals) for eq in systemOfEquations]
dX_dt
can be used in odeint
. In the following ipython session, I have already run the script that creates systemOfEquations
and defines dX_dt
:
In [31]: odeint(dX_dt, [1,2], np.linspace(0, 1, 5))
Out[31]:
array([[ 1. , 2. ],
[ 1.00947534, 1.90904183],
[ 1.01905178, 1.82223595],
[ 1.02872997, 1.73939226],
[ 1.03851059, 1.66032942]]