{ "cells": [ { "cell_type": "markdown", "metadata": { "deletable": true, "editable": true }, "source": [ "

## Let's look at the Lorenz attractor!

\n", "

We'll look at the vector field for the Lorenz attractor:

\n", "

(That is, hopefully we'll look at the vector field for the Lorenz attractor.  You might need to install some image software for this to work, including Java.)

" ] }, { "cell_type": "code", "execution_count": 2, "metadata": { "collapsed": false, "deletable": true, "editable": true }, "outputs": [ { "data": { "text/plain": [] }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "var('x y z')\n", "VF_plot = plot_vector_field3d((-3*x + 3*y, -x*z + 30*x - y, \n", " x*y - z), (x, -15, 15), (y, -25, 25), (z, -5, 65) )\n", "VF_plot.show()" ] }, { "cell_type": "markdown", "metadata": { "deletable": true, "editable": true }, "source": [ "

How's about we generate the data for the trajectory shown in the book?

" ] }, { "cell_type": "code", "execution_count": 5, "metadata": { "collapsed": false, "deletable": true, "editable": true }, "outputs": [ { "data": { "text/plain": [] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "starttime = 0\n", "stoptime = 100\n", "nsteps = 10000\n", "deltat = float((stoptime-starttime)/nsteps)\n", "x_sol = [0]\n", "y_sol = [1]\n", "z_sol = [0]\n", "tvals = [0]\n", "for step in range(nsteps):\n", " x_prime = -3.*x_sol[-1] + 3.*y_sol[-1]\n", " y_prime = -1.*x_sol[-1]*z_sol[-1] + 30.*x_sol[-1] - y_sol[-1]\n", " z_prime = 1.*x_sol[-1]*y_sol[-1] - z_sol[-1]\n", " x_sol.append(x_sol[-1] + deltat*x_prime)\n", " y_sol.append(y_sol[-1] + deltat*y_prime)\n", " z_sol.append(z_sol[-1] + deltat*z_prime)\n", " tvals.append(tvals[-1] + deltat)" ] }, { "cell_type": "markdown", "metadata": { "deletable": true, "editable": true }, "source": [ "

Let's look at that trajectory.

" ] }, { "cell_type": "code", "execution_count": 14, "metadata": { "collapsed": false, "deletable": true, "editable": true }, "outputs": [ { "data": { "text/plain": [] }, "execution_count": 14, "metadata": {}, "output_type": "execute_result" } ], "source": [ "Lor_traj = line(zip(x_sol,y_sol,z_sol))\n", "Lor_traj.show()" ] }, { "cell_type": "markdown", "metadata": { "deletable": true, "editable": true }, "source": [ "

And, we'll look at that trajectory together with the vector field.  Feel free to live-rotate this puppy.

" ] }, { "cell_type": "code", "execution_count": 7, "metadata": { "collapsed": false, "deletable": true, "editable": true }, "outputs": [ { "data": { "text/plain": [] }, "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ "MasterPlot = VFPlot + LorPlot\n", "MasterPlot.show()" ] }, { "cell_type": "markdown", "metadata": { "deletable": true, "editable": true }, "source": [ "

Here we have the trajectory projected onto the x-y plane...

" ] }, { "cell_type": "code", "execution_count": 9, "metadata": { "collapsed": false, "deletable": true, "editable": true }, "outputs": [ { "data": { "text/plain": [] }, "execution_count": 9, "metadata": {}, "output_type": "execute_result" } ], "source": [ "list_plot(zip(x_sol,y_sol),plotjoined=True)" ] }, { "cell_type": "markdown", "metadata": { "deletable": true, "editable": true }, "source": [ "

...and the trajectory projected onto the x-z plane...

" ] }, { "cell_type": "code", "execution_count": 10, "metadata": { "collapsed": false, "deletable": true, "editable": true }, "outputs": [ { "data": { "text/plain": [] }, "execution_count": 10, "metadata": {}, "output_type": "execute_result" } ], "source": [ "list_plot(zip(x_sol,z_sol),plotjoined=True)" ] }, { "cell_type": "markdown", "metadata": { "deletable": true, "editable": true }, "source": [ "

...and the trajectory projected onto the y-z plane.

" ] }, { "cell_type": "code", "execution_count": 13, "metadata": { "collapsed": false, "deletable": true, "editable": true }, "outputs": [ { "data": { "text/plain": [] }, "execution_count": 13, "metadata": {}, "output_type": "execute_result" } ], "source": [ "list_plot(zip(y_sol,z_sol),plotjoined=True)" ] } ], "metadata": { "kernelspec": { "display_name": "SageMath 8.0", "language": "", "name": "sagemath" }, "language": "python", "language_info": { "codemirror_mode": { "name": "ipython", "version": 2 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython2", "version": "2.7.13" } }, "nbformat": 4, "nbformat_minor": 2 }