【发布时间】:2012-10-26 09:49:54
【问题描述】:
我正在尝试使用 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)
使用来自scipy 的odeint 集成函数f
y = odeint(f, theta, t, args=(K,))
print y
【问题讨论】:
-
@SilentGhost 在标题中
-
@gokcehan:如果你明白它的意思,你为什么不发表解释,而不是尖刻的评论?
-
@SilentGhost 我并不是想成为一个混蛋,只是我一开始也没有看到这个问题。我不知道这个问题的答案..
-
@gokcehan:但你明白吗?我看到一些使用相关函数的代码。我不知道 integrating using
odeintfromscipy是什么意思。 -
@SilentGhost 好吧,我只是在这里推测,但显然
scipy.integrate.odeint是一个集成(数学)函数的函数,他想知道如何在他的函数f上使用它。希望他能在某个时候加入对话..
标签: python python-2.7 scipy