【发布时间】:2021-01-23 11:15:47
【问题描述】:
您好,我是 python 新手,我正在尝试对微分方程 d/dt(θi) =ωi + j(Kij sin(θj -θi)) 的总和进行数值积分,i=1,...,N .
仓本模特:
import numpy as np
import matplotlib.pyplot as plt
from scipy.integrate import odeint
def kuramoto(theta,t):
N = len(t)
w = np.array([0.1,0.2,0.3,0.4])
K = np.random.rand(N,N)
for i in range (0,N-1):
sum = K[i][i+1]*np.sin(theta[i+1]-theta[i])
sum = sum + K[i][i-1]*np.sin(theta[i-1]-theta[i])
theta_dot = w[i] + (1/N)*sum
return theta_dot
t = np.linspace(0,40,40)
theta0 = [(0.2,0.4,0.3,1.2)]
for theta0 in [(0.2,0.4,0.3,1.2)]:
y_true = odeint(kuramoto,theta0,t)
plt.plot(t,y_true,'r-')
但是,我不断收到错误 TypeError: object of type 'float' has no len()。有人可以帮我纠正这个错误吗?
【问题讨论】:
-
嘿!你能提供一个Minimal Reproducible Example吗?您的代码在当前状态下无法运行,缺少一些缩进。
-
哦,好吧,我已经编辑了它并在这里粘贴了来自 spyder 的代码