{ "cells": [ { "cell_type": "markdown", "id": "02ccc794", "metadata": {}, "source": [ "# Rabinovich-Fabrikant equations\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/Rabinovich_Fabrikant_eq.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/Rabinovich_Fabrikant_eq.ipynb)" ] }, { "cell_type": "markdown", "id": "9c7e187c", "metadata": {}, "source": [ "The Rabinovich–Fabrikant equations are a set of three coupled ordinary differential equations exhibiting chaotic behaviour for certain values of the parameters. They are named after Mikhail Rabinovich and Anatoly Fabrikant, who described them in 1979.\n", "\n", "$$\n", "\\begin{aligned}\n", "&\\dot{x}=y\\left(z-1+x^{2}\\right)+\\gamma x \\\\\n", "&\\dot{y}=x\\left(3 z+1-x^{2}\\right)+\\gamma y \\\\\n", "&\\dot{z}=-2 z(\\alpha+x y)\n", "\\end{aligned}\n", "$$\n", "\n", "where $\\alpha, \\gamma$ are constants that control the evolution of the system. \n", "\n", "- https://zh.wikipedia.org/wiki/拉比诺维奇-法布里康特方程\n", "- https://en.wikipedia.org/wiki/Rabinovich%E2%80%93Fabrikant_equations" ] }, { "cell_type": "code", "execution_count": 1, "id": "84f06912", "metadata": { "ExecuteTime": { "end_time": "2023-07-22T05:46:48.071060800Z", "start_time": "2023-07-22T05:46:47.135952600Z" } }, "outputs": [], "source": [ "import brainpy as bp\n", "import matplotlib.pyplot as plt" ] }, { "cell_type": "code", "execution_count": 2, "metadata": { "ExecuteTime": { "end_time": "2023-07-22T05:46:48.087008Z", "start_time": "2023-07-22T05:46:48.071060800Z" }, "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": "e5760679", "metadata": { "ExecuteTime": { "end_time": "2023-07-22T05:46:48.134446400Z", "start_time": "2023-07-22T05:46:48.087008Z" } }, "outputs": [], "source": [ "@bp.odeint(method='rk4')\n", "def rf_eqs(x, y, z, t, alpha=1.1, gamma=0.803):\n", " dx = y *(z-1+x*x) + gamma *x\n", " dy = x *(3*z+1-x*x) + gamma *y\n", " dz = -2*z*(alpha+x*y)\n", " return dx, dy, dz" ] }, { "cell_type": "code", "execution_count": 4, "id": "38ca0c9f", "metadata": { "ExecuteTime": { "end_time": "2023-07-22T05:46:48.134446400Z", "start_time": "2023-07-22T05:46:48.103766500Z" } }, "outputs": [], "source": [ "def run_and_visualize(runner, duration=100, dim=3, args=None):\n", " assert dim in [3, 2]\n", " if args is None:\n", " runner.run(duration)\n", " else:\n", " runner.run(duration, args=args)\n", "\n", " if dim == 3:\n", " fig = plt.figure()\n", " ax = fig.add_subplot(111, projection='3d')\n", " for i in range(runner.mon.x.shape[1]):\n", " plt.plot(runner.mon.x[100:, i], runner.mon.y[100:, i], runner.mon.z[100:, i])\n", " ax.set_xlabel('x')\n", " ax.set_ylabel('y')\n", " ax.set_zlabel('z')\n", " else:\n", " for i in range(runner.mon.x.shape[1]):\n", " plt.plot(runner.mon.x[100:, i], runner.mon.y[100:, i])\n", " plt.xlabel('x')\n", " plt.xlabel('y')\n", " plt.show()" ] }, { "cell_type": "code", "execution_count": 5, "id": "5b2ab80a", "metadata": { "ExecuteTime": { "end_time": "2023-07-22T05:46:49.131889600Z", "start_time": "2023-07-22T05:46:48.134446400Z" } }, "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" ] }, { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "0e499c82b9c8417d87f811dd17e85076", "version_major": 2, "version_minor": 0 }, "text/plain": [ " 0%| | 0/100000 [00:00" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "runner = bp.IntegratorRunner(\n", " rf_eqs,\n", " monitors=['x', 'y', 'z'],\n", " inits=dict(x=-1, y=0, z=0.5),\n", " dt=0.001\n", ")\n", "run_and_visualize(runner, 100, args=dict(alpha=1.1, gamma=0.87),)" ] }, { "cell_type": "code", "execution_count": 6, "id": "8b2a187c", "metadata": { "ExecuteTime": { "end_time": "2023-07-22T05:46:49.938685600Z", "start_time": "2023-07-22T05:46:49.131889600Z" } }, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "224616a57c6d4ac59a0a541213b3d133", "version_major": 2, "version_minor": 0 }, "text/plain": [ " 0%| | 0/100000 [00:00" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "runner = bp.IntegratorRunner(\n", " rf_eqs,\n", " monitors=['x', 'y', 'z'],\n", " inits=dict(x=-1, y=0, z=0.5),\n", " dt=0.001\n", ")\n", "run_and_visualize(runner, 100, args=dict(alpha=0.98, gamma=0.1),)" ] }, { "cell_type": "code", "execution_count": 7, "id": "452612b6", "metadata": { "ExecuteTime": { "end_time": "2023-07-22T05:46:52.000635300Z", "start_time": "2023-07-22T05:46:49.940659200Z" } }, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "00933749f40548bf92e5f0b50941b3e1", "version_major": 2, "version_minor": 0 }, "text/plain": [ " 0%| | 0/300000 [00:00" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "runner = bp.IntegratorRunner(\n", " rf_eqs,\n", " monitors=['x', 'y', 'z'],\n", " inits=dict(x=-1, y=0, z=0.5),\n", " dt=0.001\n", ")\n", "run_and_visualize(runner, 300, args=dict(alpha=0.14, gamma=0.1),)" ] }, { "cell_type": "code", "execution_count": 8, "id": "b48dc8fe", "metadata": { "ExecuteTime": { "end_time": "2023-07-22T05:46:52.568603Z", "start_time": "2023-07-22T05:46:52.000635300Z" } }, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "6583531296d8489fbc881ec2512e0049", "version_major": 2, "version_minor": 0 }, "text/plain": [ " 0%| | 0/50000 [00:00" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "runner = bp.IntegratorRunner(\n", " rf_eqs,\n", " monitors=['x', 'y', 'z'],\n", " inits=dict(x=-1, y=0, z=0.5),\n", " dt=0.001\n", ")\n", "run_and_visualize(runner, 50, dim=2, args=dict(alpha=0.05, gamma=0.1),)" ] }, { "cell_type": "code", "execution_count": 9, "id": "ad8e15e5", "metadata": { "ExecuteTime": { "end_time": "2023-07-22T05:46:53.431659300Z", "start_time": "2023-07-22T05:46:52.568603Z" } }, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "09284c7a5a2f4566bf2c779200da5439", "version_major": 2, "version_minor": 0 }, "text/plain": [ " 0%| | 0/100000 [00:00" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "runner = bp.IntegratorRunner(\n", " rf_eqs,\n", " monitors=['x', 'y', 'z'],\n", " inits=dict(x=-1, y=0, z=0.5),\n", " dt=0.001\n", ")\n", "run_and_visualize(runner, 100, dim=2, args=dict(alpha=0.25, gamma=0.1),)" ] }, { "cell_type": "code", "execution_count": 10, "id": "9abf0a9d", "metadata": { "ExecuteTime": { "end_time": "2023-07-22T05:46:54.949207800Z", "start_time": "2023-07-22T05:46:53.401519200Z" } }, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "9faf7bfe633748fab11c0101d1634bcd", "version_major": 2, "version_minor": 0 }, "text/plain": [ " 0%| | 0/100000 [00:00" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "a0c3bb5eea1f4f90a0028478e793f0b8", "version_major": 2, "version_minor": 0 }, "text/plain": [ " 0%| | 0/100000 [00:00" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "runner = bp.IntegratorRunner(\n", " rf_eqs,\n", " monitors=['x', 'y', 'z'],\n", " inits=dict(x=-1, y=0, z=0.5),\n", " dt=0.001\n", ")\n", "run_and_visualize(runner, 100, dim=2, args=dict(alpha=1.1, gamma=0.86666666666666666667),)\n", "\n", "runner = bp.IntegratorRunner(\n", " rf_eqs,\n", " monitors=['x', 'y', 'z'],\n", " inits=dict(x=-1, y=0, z=0.5),\n", " dt=0.001\n", ")\n", "run_and_visualize(runner, 100, dim=3, args=dict(alpha=1.1, gamma=0.86666666666666666667),)" ] }, { "cell_type": "code", "execution_count": 11, "id": "409eff85", "metadata": { "ExecuteTime": { "start_time": "2023-07-22T05:46:54.949207800Z" } }, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "7d5f5bdf71f94ad2bc2a725197982900", "version_major": 2, "version_minor": 0 }, "text/plain": [ " 0%| | 0/60000 [00:00" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "runner = bp.IntegratorRunner(\n", " rf_eqs,\n", " monitors=['x', 'y', 'z'],\n", " inits=dict(x=0.1, y=-0.1, z=0.1),\n", " dt=0.001\n", ")\n", "run_and_visualize(runner, 60, dim=3, args=dict(alpha=0.05, gamma=0.1),)" ] } ], "metadata": { "jupytext": { "cell_metadata_filter": "-all", "formats": "ipynb,auto:percent", "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 }