矩阵形式的 ODE 系统

system of ODEs in matrix form

我正在尝试找出如何求解和绘制系统 dx/dt = Ax 的 2x2 矩阵 A。我真的不知道该怎么做。我目前的代码如下:

import numpy as np
import matplotlib.pyplot as plt
from scipy.integrate import odeint

def sys(x, t, A):
    x1, x2 = x    
    return [A @ x]

A = np.array([[1, 2], [3, 4]])


x0 = np.array([[1], [2]])

t = np.linspace(0, 100, 10000)

sol = odeint(sys, x0, t, A)

ax = plt.axes()
ax.plot(t, sol)
plt.show()

错误信息是:

output = _odepack.odeint(func, y0, t, args, Dfun, col_deriv, ml, mu,
odepack.error: Extra arguments must be in a tuple.

如果能提供有关如何使此代码正常工作的帮助,我们将不胜感激。请注意,我对编码非常陌生,更不用说编码微分方程了。 谢谢堆。

您必须在元组中传递其他参数。像这样:

sol = odeint(sys, x0, t, args=(A,))

参见documentation on scipy.integrate.odeint