更新时间:2021-09-06 23:43:15
如果要使用读取文件的同一脚本来解决系统(因此systemOfEquations
可作为全局变量使用),并且systemOfEquations中使用的仅em 变量是x
,y
以及可能的t
,您可以像这样在同一文件中定义dX_dt
:
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
可以在odeint
中使用.在下面的ipython会话中,我已经运行了创建systemOfEquations
并定义dX_dt
的脚本:
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]]