{ "cells": [ { "cell_type": "markdown", "id": "12f8ea9f", "metadata": {}, "source": [ "# Logistic map\n", "\n", "[![Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/brainpy/examples/blob/main/classical_dynamical_systems/logistic_map.ipynb)\n", "[![Open in Kaggle](https://kaggle.com/static/images/open-in-kaggle.svg)](https://kaggle.com/kernels/welcome?src=https://github.com/brainpy/examples/blob/main/classical_dynamical_systems/logistic_map.ipynb)" ] }, { "cell_type": "markdown", "id": "1940064f", "metadata": {}, "source": [ "The logistic map is a one-dimensional discrete time dynamical system that is defined by the equation\n", "\n", "$$\n", "x_{n+1} =\\lambda x_{n}(1-x_{n})\n", "$$\n", "\n", "For an initial value $0\\leq x_{0}\\leq1$ this map generates a sequence of values $x_{0},x_{1},...x_{n},x_{n+1},...$ The growth parameter is chosen to be\n", "\n", "$$\n", "0<\\lambda\\leq4\n", "$$\n", "\n", "which implies that for all $n$ the state variable will remain bounded in the unit interval. Despite its simplicity this famous dynamical system can exhibit an unbelievable dynamic richness." ] }, { "cell_type": "code", "execution_count": 1, "id": "e5348ae1", "metadata": { "ExecuteTime": { "end_time": "2023-07-22T05:43:35.737903200Z", "start_time": "2023-07-22T05:43:34.849895Z" } }, "outputs": [], "source": [ "import brainpy as bp\n", "import brainpy.math as bm\n", "import matplotlib.pyplot as plt" ] }, { "cell_type": "code", "execution_count": 2, "id": "daa333c7f4ff062", "metadata": { "ExecuteTime": { "end_time": "2023-07-22T05:43:35.757945400Z", "start_time": "2023-07-22T05:43:35.737903200Z" }, "collapsed": false }, "outputs": [ { "data": { "text/plain": [ "'2.4.3'" ] }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "bp.__version__" ] }, { "cell_type": "code", "execution_count": 3, "id": "848d7dc4", "metadata": { "ExecuteTime": { "end_time": "2023-07-22T05:43:35.821471100Z", "start_time": "2023-07-22T05:43:35.757945400Z" } }, "outputs": [], "source": [ "class LogisticMap(bp.Dynamic):\n", " def __init__(self, num, mu0=2., mu1=4.):\n", " super(LogisticMap, self).__init__(num)\n", "\n", " self.mu = bm.linspace(mu0, mu1, num)\n", " self.x = bm.Variable(bm.ones(num) * 0.2)\n", "\n", " def update(self):\n", " self.x.value = self.mu * self.x * ( 1- self.x)" ] }, { "cell_type": "code", "execution_count": 4, "id": "a4565a0c", "metadata": { "ExecuteTime": { "end_time": "2023-07-22T05:43:35.883400400Z", "start_time": "2023-07-22T05:43:35.821471100Z" } }, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "No GPU/TPU found, falling back to CPU. (Set TF_CPP_MIN_LOG_LEVEL=0 and rerun for more info.)\n" ] } ], "source": [ "map = LogisticMap(10000, 2, 4)" ] }, { "cell_type": "code", "execution_count": 5, "id": "2b8987d0", "metadata": { "ExecuteTime": { "end_time": "2023-07-22T05:43:35.971699700Z", "start_time": "2023-07-22T05:43:35.883400400Z" } }, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "95352c1257444d92a83b21a5554e6343", "version_major": 2, "version_minor": 0 }, "text/plain": [ " 0%| | 0/1100 [00:00" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "plt.plot(map.mu, runner.mon.x[1000:].T, ',k', alpha=0.25)\n", "plt.xlabel('mu')\n", "plt.ylabel('x')\n", "plt.show()" ] } ], "metadata": { "jupytext": { "cell_metadata_filter": "-all", "encoding": "# -*- coding: utf-8 -*-", "formats": "auto:light,ipynb", "notebook_metadata_filter": "-all" }, "kernelspec": { "display_name": "brainpy", "language": "python", "name": "brainpy" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.9.12" }, "latex_envs": { "LaTeX_envs_menu_present": true, "autoclose": false, "autocomplete": true, "bibliofile": "biblio.bib", "cite_by": "apalike", "current_citInitial": 1, "eqLabelWithNumbers": true, "eqNumInitial": 1, "hotkeys": { "equation": "Ctrl-E", "itemize": "Ctrl-I" }, "labels_anchors": false, "latex_user_defs": false, "report_style_numbering": false, "user_envs_cfg": false }, "toc": { "base_numbering": 1, "nav_menu": {}, "number_sections": true, "sideBar": true, "skip_h1_title": false, "title_cell": "Table of Contents", "title_sidebar": "Contents", "toc_cell": false, "toc_position": {}, "toc_section_display": true, "toc_window_display": false } }, "nbformat": 4, "nbformat_minor": 5 }