如何求解 Python 中的微分方程组?

How to solve a system of differential equations in Python?

How do we solve a system of linear equations in Python and NumPy:

We have a system of equations and there is the right side of the values after the equal sign. We write all the coefficients into the matrix matrix = np.array(...),, and write the right side into the vector vector = np.array(...) and then use the command np.linalg.solve(matrix, vector) to find the variables.

但是如果我在等号后面有导数并且我想对微分方程组做同样的事情,我该如何实现呢?

lambda 已知值在哪里,我需要找到 A

P.S。我从库 scipy 中看到了这个命令 y = odeint(f, y0, t) 的用法,但我不明白如何设置我自己的函数 f 如果我在那里有一个矩阵,初始值是多少 y0 和什么 t?

你可以用紧凑的形式解决你的系统

t = arange(t0,tf,h)
solX = odeint(lambda X,t: M.dot(X), X0, t)

设置参数和初始条件后。

对于高级用途,还可以根据状态向量的规模和所需的精度设置绝对和相对误差阈值。