Skip to content

Instantly share code, notes, and snippets.

@mdnestor
Created December 25, 2022 13:16
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Embed
What would you like to do?
Simulates the N-oscillator Kuramoto model
import numpy as np
import matplotlib.pyplot as plt
from scipy import integrate
N = 5
K = 12
ω = np.random.normal(0, 1, N)
θ_0 = np.random.uniform(0, 2*np.pi, N)
def f(t, θ):
return [ω[i] + K/N * sum(np.sin(θ[i] - θ[j]) for j in range(N)) for i in range(N)]
t_max = 10
dt = 0.1
sol = integrate.solve_ivp(f, t_span=[0,t_max], y0=θ_0, t_eval=np.arange(0,t_max,dt))
for i in range(N):
plt.plot(sol.t, sol.y[i] % 2*np.pi)
plt.xlabel("t")
plt.ylabel("θ")
plt.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment