Solving Matrix Differential Equation in Python using Scipy/Numpy- NDSolve equivalent?

江枫思渺然 提交于 2019-12-04 14:38:32

In the call to odeint, try changing tuple(array[Ab]) to (array(Ab),), or even just (Ab,). That is, use

MA = odeint(deriv, A0, time, (Ab,))

Without seeing how you defined A0 and Ab, I can't be sure that this will fix the problem, but the following variation of your code will work. I used a 3x3 array instead of 9x9.

import numpy as np
from scipy.integrate import odeint


def deriv(A, t, Ab):
    return np.dot(Ab, A)


Ab = np.array([[-0.25,    0,    0],
               [ 0.25, -0.2,    0],
               [    0,  0.2, -0.1]])

time = np.linspace(0, 25, 101)
A0 = np.array([10, 20, 30])

MA = odeint(deriv, A0, time, args=(Ab,))
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!