.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "api/gallery/chaos/synchronization/plot_pecora_carroll_synchronization.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_chaos_synchronization_plot_pecora_carroll_synchronization.py: Pecora and Carroll: synchronizing two chaotic Lorenz systems ============================================================ Two chaotic systems started apart diverge exponentially, so it seems they could never run in step. Pecora and Carroll showed that they can if one drives the other. The transmitter is a Lorenz system; the receiver is a copy of the Lorenz equations for :math:`(y', z')` with the transmitted :math:`x(t)` in place of its own :math:`x`, .. math:: \dot y' = x(\rho - z') - y', \qquad \dot z' = x y' - \beta z'. The receiver locks onto the transmitter, :math:`(y', z') \to (y, z)`, from any initial state when both of its *conditional* Lyapunov exponents (its exponents along the driven trajectory) are negative. For :math:`\sigma = 10,\ \rho = 28,\ \beta = 8/3` they are about :math:`(-1.8, -1.9)` for the :math:`x` drive and exactly :math:`(-\beta, -\sigma)` for the :math:`y` drive, while the :math:`z` drive has a zero exponent and does not synchronize. .. GENERATED FROM PYTHON SOURCE LINES 23-29 .. code-block:: Python import matplotlib.pyplot as plt import numpy as np from physicskit.chaos.systems.synchronization import PecoraCarrollLorenz .. GENERATED FROM PYTHON SOURCE LINES 30-34 The receiver locks onto the transmitter --------------------------------------- The receiver starts at :math:`(y', z') = (-10, 30)`, far from the transmitter's :math:`(1, 1)`. .. GENERATED FROM PYTHON SOURCE LINES 34-47 .. code-block:: Python x_drive = PecoraCarrollLorenz("x") t, states = x_drive.trajectory(n_steps=3000) err_x = x_drive.synchronization_error(states) fig, axes = plt.subplots(1, 3, figsize=(14, 4.2)) ax = axes[0] ax.plot(t, states[:, 1], "k-", lw=1, label="transmitter y") ax.plot(t, states[:, 3], "C3--", lw=1, label="receiver y'") ax.set_xlim(0, 8) ax.set_xlabel("t") ax.set_title("x drive: y' joins y") ax.legend(loc="lower right") .. image-sg:: /api/gallery/chaos/synchronization/images/sphx_glr_plot_pecora_carroll_synchronization_001.png :alt: x drive: y' joins y :srcset: /api/gallery/chaos/synchronization/images/sphx_glr_plot_pecora_carroll_synchronization_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none .. GENERATED FROM PYTHON SOURCE LINES 48-50 Conditional Lyapunov exponents decide which drive works ------------------------------------------------------- .. GENERATED FROM PYTHON SOURCE LINES 50-69 .. code-block:: Python lam = {d: PecoraCarrollLorenz(d).conditional_lyapunov_exponents() for d in "xyz"} for d, (l1, l2) in lam.items(): print(f"{d} drive: conditional exponents {l1:+.3f}, {l2:+.3f}") ax = axes[1] for d, colour in zip("xyz", ["C0", "C1", "C2"]): system = PecoraCarrollLorenz(d) _, s = system.trajectory(n_steps=3000) e = system.synchronization_error(s) ax.semilogy(t, np.maximum(e, 1e-16), color=colour, label=rf"{d} drive, $\lambda_1 = {lam[d][0]:+.2f}$") window = (t > 2) & (t < 12) slope = np.polyfit(t[window], np.log(err_x[window]), 1)[0] ax.semilogy(t, 30 * np.exp(lam["x"][0] * t), "k:", lw=1, label=r"$e^{\lambda_1 t}$, x drive") ax.set_ylim(1e-16, 1e3) ax.set_xlabel("t") ax.set_ylabel("synchronization error") ax.legend(fontsize=8) print(f"x-drive error decays at rate {slope:.3f}") .. rst-class:: sphx-glr-script-out .. code-block:: none x drive: conditional exponents -1.800, -1.866 y drive: conditional exponents -2.667, -10.000 z drive: conditional exponents -0.003, -10.997 x-drive error decays at rate -1.832 .. GENERATED FROM PYTHON SOURCE LINES 70-74 Synchronized and unsynchronized receivers ----------------------------------------- Plotting the receiver against the transmitter, a synchronized receiver collapses onto the diagonal; the :math:`z`-driven one wanders off it. .. GENERATED FROM PYTHON SOURCE LINES 74-86 .. code-block:: Python z_drive = PecoraCarrollLorenz("z") _, sz = z_drive.trajectory(n_steps=3000) ax = axes[2] ax.plot(sz[1000:, 0], sz[1000:, 3], ".", ms=1, color="C2", label="z drive: x' vs x") ax.plot(states[1000:, 1], states[1000:, 3], ".", ms=1, color="C0", label="x drive: y' vs y") ax.set_xlabel("transmitter") ax.set_ylabel("receiver") ax.set_aspect("equal") ax.legend(markerscale=8, fontsize=8) plt.tight_layout() plt.show() .. image-sg:: /api/gallery/chaos/synchronization/images/sphx_glr_plot_pecora_carroll_synchronization_002.png :alt: plot pecora carroll synchronization :srcset: /api/gallery/chaos/synchronization/images/sphx_glr_plot_pecora_carroll_synchronization_002.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 87-93 Check ----- The x-driven receiver synchronizes at the rate of its largest conditional exponent; the y drive's exponents are exactly :math:`-\beta` and :math:`-\sigma`; the z drive's largest is zero, and its receiver does not synchronize. .. GENERATED FROM PYTHON SOURCE LINES 93-99 .. code-block:: Python assert err_x[0] > 10 and err_x[-1] < 1e-8 assert np.all(lam["x"] < 0) assert abs(slope - lam["x"][0]) < 0.3 assert np.allclose(lam["y"], [-8 / 3, -10], atol=1e-4) assert abs(lam["z"][0]) < 0.05 assert z_drive.synchronization_error(sz)[-1] > 1 .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.879 seconds) .. _sphx_glr_download_api_gallery_chaos_synchronization_plot_pecora_carroll_synchronization.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_pecora_carroll_synchronization.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_pecora_carroll_synchronization.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_pecora_carroll_synchronization.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_