{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Chaos, Lyapunov, and entropy increase

\n",
"\n",
"(Sethna, \"Entropy, Order Parameters, and Complexity\", ex. 5.9)\n",
"\n",
"© 2017, James Sethna, all rights reserved. This exercise was developed in collaboration with Christopher Myers."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Chaotic dynamical systems have *sensitive dependence on initial\n",
"conditions*. This is commonly described as the `butterfly effect' (due\n",
"to Lorenz of the Lorenz attractor): the effects\n",
"of the flap of a butterfly's wings in Brazil build up with time until\n",
"months later a tornado in Texas could be launched. In this exercise, we will see\n",
"this sensitive dependence for a particular system (the logistic map)\n",
"and measure the sensitivity by defining the *Lyapunov exponents*.\n",
"\n",
"Import packages"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"%pylab inline\n",
"from scipy import *"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"The logistic map takes the interval $(0,1)$ into itself:\n",
"\\begin{equation}\n",
"f(x) = 4 \\mu x (1-x),\n",
"\\end{equation}\n",
"where the time evolution is given by iterating the map:\n",
"\\begin{equation}\n",
"x_0, x_1, x_2, \\ldots = x_0, f(x_0), f(f(x_0)), \\ldots .\n",
"\\end{equation}\n",
"In particular, for $\\mu=1$ it precisely folds the unit interval in half,\n",
"and stretches it (non-uniformly) to cover the original domain."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"def f(x,mu):\n",
" \"\"\"\n",
" Logistic map f(x) = 4 mu x (1-x), which folds the unit interval (0,1)\n",
" into itself.\n",
" \"\"\"\n",
" return 4*..."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"The mathematics community lumps together continuous dynamical evolution\n",
"laws and discrete mappings as both being dynamical systems.\n",
" (The Poincar\\'e section, as described in the exercise 'Jupiter', takes a\n",
" continuous, recirculating dynamical system and replaces it with a\n",
" once-return map, providing the standard motivation for treating\n",
" maps and continuous evolution laws together. This motivation does not\n",
" directly apply here,\n",
" because the logistic map is not invertible, so it\n",
" is not directly given by a Poincar\\'e section of a smooth differential\n",
" equation. (Remember the existence and uniqueness theorems from math class?\n",
" The invertibility follows from uniqueness.)\n",
" )\n",
"The general stretching and folding exhibited by our map is often seen in\n",
"driven physical systems without conservation laws.\n",
"\n",
"In this exercise, we will focus on values of $\\mu$ near one, where the\n",
"motion is mostly *chaotic*.\n",
"Chaos is sometimes defined as motion where the final position depends\n",
"sensitively on the initial conditions. Two trajectories, starting a distance\n",
"$\\epsilon$ apart, will typically drift apart in time as\n",
"$\\epsilon e^{\\lambda t}$, where $\\lambda$ is the Lyapunov exponent for the\n",
"chaotic dynamics.\n",
"\n",
"*\n",
"Start with $\\mu = 0.9$ and two nearby points $x_0$ and\n",
"$y_0=x_0+\\epsilon$ somewhere between zero and one.\n",
"Investigate the two trajectories\n",
"$x_0, f(x_0), f(f(x_0)), ..., f^{[n]}(x_0)$ and\n",
"$y_0, f(y_0), \\dots$. How fast do they separate? Why do they stop separating?\n",
"Estimate the Lyapunov exponent.\n",
"*\n",
"(Hint: $\\epsilon$ can be a few times the precision of the machine\n",
"(around $10^{-17}$ for double-precision arithmetic), so long as you are not\n",
"near the maximum value of $f$ at $x_0 = 0.5$.)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"mu = 0.9\n",
"x = 0.4\n",
"eps = 3.e-17\n",
"y = x + eps\n",
"fiter1 = [x]\n",
"fiter2 = [y]\n",
"for i in range(200):\n",
" x = ..\n",
" fiter1.append(x)\n",
" y = ...\n",
" ...\n",
"fiter1 = array(fiter1)\n",
"fiter2 = array(fiter2)\n",
"diff = fiter1-fiter2\n",
"diffPlot = semilogy(fabs(...))"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"ts = arange(200)\n",
"lyapunov = ... # Vary to give good fit\n",
"diffPlot = semilogy(fabs(diff))\n",
"semilogy(ts, eps*exp(...), 'r-');"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Many Hamiltonian systems are also chaotic. Two configurations of classical\n",
"atoms or billiard balls, with initial positions and velocities that are\n",
"almost identical, will rapidly diverge as the collisions magnify small\n",
"initial deviations in angle and velocity into large ones. It is this chaotic\n",
"stretching, folding, and kneading of phase space that\n",
"is at the root of our explanation that entropy increases."
]
}
],
"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.5.1"
}
},
"nbformat": 4,
"nbformat_minor": 0
}