Python 求解矩阵的一阶微分方程

Python 求解矩阵的一阶微分方程,python,matrix,scipy,system,differential-equations,Python,Matrix,Scipy,System,Differential Equations,我想用python编写一个耦合微分方程组:dF/dt=a(F)其中F是矩阵,a(F)是矩阵的函数F 当F和A(F)是向量时,使用scipy.integrate.odeint求解方程 但是,scipy.integrate.odeint不适用于矩阵,我得到一个错误: tmin, tmax, tstep = (0., 200., 1) t_test=np.arange(tmin, tmax, tstep) #time vector dydt_testm=np.array([[0.,1.],[2.,3

我想用python编写一个耦合微分方程组:
dF/dt=a(F)
其中
F
是矩阵,
a(F)
是矩阵的函数
F

F
A(F)
是向量时,使用
scipy.integrate.odeint
求解方程

但是,
scipy.integrate.odeint
不适用于矩阵,我得到一个错误:

tmin, tmax, tstep = (0., 200., 1)
t_test=np.arange(tmin, tmax, tstep) #time vector

dydt_testm=np.array([[0.,1.],[2.,3.]])
Y0_test=np.array([[0,1],[0,1]])

def dydt_test(y,t):
    return dydt_testm

result = si.odeint(dydt_test, Y0_test,t_test)
ValueError:初始条件y0必须是一维的


正如Warren Weckesser在评论中所评论的那样,
odeintw
完成了这项工作

from odeintw import odeintw
import numpy as np

Y0_test=np.array([[0,1],[0,1]])
tmin, tmax, tstep = (0., 200., 1)
t_test=np.arange(tmin, tmax, tstep) #time vector

dydt_testm=np.array([[0.,1.],[2.,3.]])

def dydt_test(y,t):
    return dydt_testm

result = odeintw(dydt_test, #Computes the derivative of y at t 
                                     Y0_test,               #Initial condition on y (can be a vector).
                                     t_test)
plt.plot(t_test,result[:,0,1])
plt.show()


到目前为止你尝试了什么?看看。源代码位于github上,您可以使用
F=F.resforme(n,n)
返回dF.flatte()
@WarrenWeckesser在jupyter笔记本中使用IPython时,如何导入odeintw?它在Python 2上工作吗?
odeintw
处于启用状态,因此可以使用
pip
命令安装它。(如果您不熟悉
pip
,请搜索教程。)我已经有一段时间没有更新发布的版本了,因此它应该仍然适用于Python 2.7。