簡體   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