{
  "cells": [
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "%matplotlib inline"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "\nAn animation of the logistic function\n=============================================\n"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "The logistic map and... rabbits?\n----------------------------------\nA commun example to understand the logistic map is to think of a pattern to simulate a population of rabbits\nwith the most simple conditions in a multiplicativ model.\nLet's consider a group made of $x_n$ rabbits, where $x_n$ is a percentage of the maximum number of rabbits we can have.\nLet's observe them every six months (time they need to be able to produce offsprings).\nThen at the next observation, if we note $r$ the growth rate of the population, there will be $rx_n$ rabbits.\nHowever, this modelisation is wrong because it assumes that none of the rabbits died or escaped its cage to go back to the wilderness.\nSo, a way to control this pattern is to multiply $rx_n$ by $(1-x_n)$, a factor that, when $x_n$ approaches it's maximum, tends to $0$.\n\n\nThus the equation of the logistic map is :\n\n\\begin{align}x_{n+1}=rx_n(1-x_n),\\ \\forall\\, (x_0,r)\\in [0,1]\\times [0,4].\\end{align}\n\nLet's see how the population evolves over time depending on the growth ratio. Let's begin with a growth ratio of $2.5$.\n\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "import chaoseverywhere as chaos\nimport matplotlib.pyplot as plt\n\nplt.style.use('ggplot')\nchaos.logistic_draw(0.01, 2.5, 100, 100)\nhline = plt.axhline(y=1.5/2.5, color='black', ls=':', label=r'$y=\\dfrac{2.5-1}{2.5}=0.6$')\nplt.legend(handles=[hline])\nplt.show()"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "Evolution in term of r values\n--------------------------------\n* For $r\\leq 1$, our bunnies die. The sequence tends to $0$.\n* For $r\\in [1,3]$, the population oscillates and then stabilizes to the value $\\frac{r-1}{r}$.\n* For $r\\in [3,3.57]$ the population oscillates between several values, there is no longer one attractor.\n* For $r\\geq 3.57$ there is almost surely a chaotic design.\n\n\n.. raw:: html\n\n    <iframe width=\"356\" height=\"200\" src=\"https://www.youtube.com/embed/YiqpSf13kzI\" frameborder=\"0\" allowfullscreen></iframe>\n\n\n"
      ]
    }
  ],
  "metadata": {
    "kernelspec": {
      "display_name": "Python 3",
      "language": "python",
      "name": "python3"
    },
    "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.7.3"
    }
  },
  "nbformat": 4,
  "nbformat_minor": 0
}