.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "api/gallery/ode_dynamics/logistic_map/plot_02_cobweb_animation.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 or to run this example in your browser via JupyterLite. .. rst-class:: sphx-glr-example-title .. _sphx_glr_api_gallery_ode_dynamics_logistic_map_plot_02_cobweb_animation.py: Animated: the logistic map's cobweb as r grows ============================================== A cobweb diagram iterates :math:`x_{k+1} = rx_k(1 - x_k)` graphically: go up to the parabola, across to the diagonal, repeat. Sweeping :math:`r` from 2.8 to 4 shows the period-doubling route to chaos as the red web settles onto a fixed point, then a square (a period-2 cycle), then nested squares (period 4, 8, ...), and from :math:`r_\infty \approx 3.5699` a web that never closes. The bifurcation diagram on the right marks where each frame sits. .. GENERATED FROM PYTHON SOURCE LINES 15-24 .. code-block:: Python import matplotlib.pyplot as plt import numpy as np from mathematicskit.ode_dynamics.visualizers import animate_logistic_cobweb # In Jupyter or JupyterLite, show animations as an HTML/JavaScript player # (no ffmpeg needed). plt.rcParams["animation.html"] = "jshtml" .. GENERATED FROM PYTHON SOURCE LINES 25-29 From a fixed point to chaos --------------------------- The sweep slows down through the period-doubling cascade, where the action is. .. GENERATED FROM PYTHON SOURCE LINES 29-34 .. code-block:: Python r_values = np.concatenate([np.linspace(2.8, 3.4, 12), np.linspace(3.4, 3.6, 24), np.linspace(3.6, 4.0, 14)[1:]]) anim = animate_logistic_cobweb(r_values, x0=0.2, n_transient=60, n_keep=60) anim .. container:: sphx-glr-animation .. raw:: html
.. GENERATED FROM PYTHON SOURCE LINES 35-36 .. code-block:: Python plt.show() .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 5.889 seconds) .. _sphx_glr_download_api_gallery_ode_dynamics_logistic_map_plot_02_cobweb_animation.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: lite-badge .. image:: images/jupyterlite_badge_logo.svg :target: ../../../../lite/lab/index.html?path=api/gallery/ode_dynamics/logistic_map/plot_02_cobweb_animation.ipynb :alt: Launch JupyterLite :width: 150 px .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_02_cobweb_animation.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_02_cobweb_animation.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_02_cobweb_animation.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_