dx/dt = Ax
其中A
,x
属于n x n
数组。我曾尝试在solve_ivp
中使用odeint
和scipy.integrate
功能,但是这两个功能仅适用于n x 1
数组。
集成商希望ODE函数使用平面的一维数组作为状态变量,并返回同样平面的导数向量。该输入数组包含矩阵的条目。要对其执行矩阵运算,您需要从平面输入数组构建矩阵,最后将其与导数函数的输出相反。
x0 = x0.reshape(-1); # make data 1-dimensional
def odefun(t,x):
x=x.reshape([n,n]); # restore to matrix form
dx=A.dot(x); # perform matrix operations
return dx.reshape(-1); # return 1-dimensional vector
sol = solve_ivp(odefun, [t0, tf], x0)