[英]Solution for differential equation is completly different in boost::odeint and scipy.integrate
[英]How can I integrate the Ordinary differential equation using odeint from scipy.integrate?
我正在尝试使用来自scipy的odeint将定义为f的函数集成到代码中。 函数f以theta,t和K作为参数,它们在函数f下定义。 y是结果,我为此报错。 产生错误的原因是二维的θ。 我无法执行整合。 有人可以帮我吗?
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
从scipy
y = odeint(f, theta, t, args=(K,))
print y
写
y = odeint(f, theta.ravel(), t, args=(K,))
和
def f(theta, t, K):
global N
theta = theta.reshape(T, N)
...
return dtheta.ravel()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.