我正在尝试使用 scipy 中的 odeint 在代码中集成定义为 f 的函数。函数 f 将 theta、t 和 K 作为参数,这些参数在函数 f 下方定义。y 是结果,我得到了错误。错误的原因是 2 维的 theta。我无法执行整合。有人可以帮我吗?
import numpy as np
import random
from scipy.integrate import odeint
f
是要集成的功能
def f(theta, t, K):
global N
tau = 1.5
dtheta = np.zeros([T,N], float)
for i in range(N):
s = 0.
for j in range(i+1,N):
s = s + np.sin(theta[t-tau,j] - theta[t,i])
dtheta[t,i] = K*s
return dtheta
# Number of nodes
N = 10
# Constant
K = 1.0
# Number of time steps
T = 100
t = np.linspace(0, T, 100, endpoint=False)
theta = np.zeros([T,N], float)
统一生成随机数
for i in range(N):
theta[0,i] = random.uniform(-180, 180)
f
使用odeint
from集成函数scipy
y = odeint(f, theta, t, args=(K,))
print y