.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "api/gallery/ode_dynamics/synchronization/plot_01_kuramoto.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code. .. rst-class:: sphx-glr-example-title .. _sphx_glr_api_gallery_ode_dynamics_synchronization_plot_01_kuramoto.py: The Kuramoto synchronization transition ============================================= A thousand oscillators with Lorentzian-distributed natural frequencies stay incoherent for weak coupling. Above the critical coupling :math:`K_c = 2\gamma` a synchronized cluster forms, and the steady coherence follows Kuramoto's exact result :math:`r = \sqrt{1 - K_c/K}`. .. GENERATED FROM PYTHON SOURCE LINES 12-21 .. code-block:: Python import matplotlib.pyplot as plt import numpy as np from mathematicskit.ode_dynamics.systems.synchronization import KuramotoModel, kuramoto_lorentzian_order_parameter, kuramoto_order_parameter n, gamma = 1000, 0.5 omegas = gamma * np.tan(np.pi * (np.arange(n) + 0.5) / n - np.pi / 2) theta0 = np.random.default_rng(0).uniform(0.0, 2.0 * np.pi, n) .. GENERATED FROM PYTHON SOURCE LINES 22-24 Coherence versus coupling strength ---------------------------------------- .. GENERATED FROM PYTHON SOURCE LINES 24-41 .. code-block:: Python Ks = np.linspace(0.25, 4.0, 16) r_sim = [] for K in Ks: traj = KuramotoModel(theta0, omegas, K=K).integrate((0.0, 60.0), dt=0.02, method="rk4") r_sim.append(kuramoto_order_parameter(traj.y[-500:])[0].mean()) K_fine = np.linspace(0.25, 4.0, 300) fig, axes = plt.subplots(1, 2, figsize=(11, 4.5)) axes[0].plot(K_fine, kuramoto_lorentzian_order_parameter(K_fine, gamma), "k", label="theory sqrt(1 - Kc/K)") axes[0].plot(Ks, r_sim, "o", label=f"simulation, N={n}") axes[0].axvline(2 * gamma, color="gray", ls="--") axes[0].set_xlabel("coupling K") axes[0].set_ylabel("order parameter r") axes[0].set_title("Onset of synchrony at Kc = 2 gamma") axes[0].legend() .. image-sg:: /api/gallery/ode_dynamics/synchronization/images/sphx_glr_plot_01_kuramoto_001.png :alt: Onset of synchrony at Kc = 2 gamma :srcset: /api/gallery/ode_dynamics/synchronization/images/sphx_glr_plot_01_kuramoto_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none .. GENERATED FROM PYTHON SOURCE LINES 42-44 Growth of coherence over time ----------------------------------- .. GENERATED FROM PYTHON SOURCE LINES 44-55 .. code-block:: Python for K in (0.5, 1.5, 3.0): traj = KuramotoModel(theta0, omegas, K=K).integrate((0.0, 30.0), dt=0.02, method="rk4") axes[1].plot(traj.t, kuramoto_order_parameter(traj.y)[0], label=f"K={K}") axes[1].set_xlabel("t") axes[1].set_ylabel("r(t)") axes[1].set_title("Coherence r(t)") axes[1].legend() fig.tight_layout() plt.show() .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 6.937 seconds) .. _sphx_glr_download_api_gallery_ode_dynamics_synchronization_plot_01_kuramoto.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_01_kuramoto.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_01_kuramoto.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_01_kuramoto.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_