{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "## Visualisation of many initial condition for 3d ODE" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [ "import k3d\n", "import numpy as np\n", "\n", "points_number = 11200\n", "positions = 50 * np.random.random_sample((points_number,3)) - 25\n", "colors = np.random.randint(0, 0x777777, points_number)\n", "\n", "plot = k3d.plot()\n", "\n", "p = k3d.points(positions, colors, point_size=1)\n", "plot += p\n", "\n", "\n", "sigma=10.0\n", "beta=8./3\n", "rho=28.0\n", "def lorenz_deriv(X, sigma=sigma, beta=beta, rho=rho):\n", " \"\"\"Compute the time-derivative of a Lorenz system.\"\"\"\n", " x, y, z = X.T\n", " return np.vstack([sigma * (y - x), x * (rho - z) - y, x * y - beta * z]).T\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [ "X = p.positions\n", "colors = p.colors\n", "m = (X[:,0]-.5*X[:,1])>0\n", "colors = np.random.randint(0, 0x777777, points_number)\n", "\n", "colors[m]=1\n", "colors[~m]=0xff0000\n", "\n", "p.colors = colors\n", "\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "plot.display()" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [ "plot.camera_auto_fit = False\n", "plot.grid_auto_fit = False\n", "\n", "X = p.positions\n", "for i in range(100):\n", " X = X + lorenz_deriv(X, sigma=sigma, beta=beta, rho=rho)*0.005\n", " if i%1==0 and i>0:\n", " p.positions = X[::1,:]\n", "p.positions = X" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "%time X = X + lorenz_deriv(X, sigma=sigma, beta=beta, rho=rho)*0.005\n", "%time p.positions = X" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "%time p.positions = X[::10,:]" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [ "p.point_size =1" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [] } ], "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.6.1" } }, "nbformat": 4, "nbformat_minor": 1 }