繁体   English   中英

如何使用scipy.integrate的odeint积分常微分方程?

[英]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使用odeintscipy

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM