{ "cells": [ { "cell_type": "code", "execution_count": 17, "metadata": {}, "outputs": [], "source": [ "from lib import plot\n", "import IPython\n", "import numpy as np" ] }, { "cell_type": "code", "execution_count": 18, "metadata": {}, "outputs": [ { "data": { "image/svg+xml": "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n", "text/plain": [ "" ] }, "execution_count": 18, "metadata": {}, "output_type": "execute_result" } ], "source": [ "a = plot.A6_PORTRAIT\n", "p_svg = plot.SVGPlotter('plots/ode.svg', a)\n", "p_hpgl = plot.HPGLPlotter(a, 'plots/ode_{index}.hpgl')\n", "p = plot.MultiPlotter()\n", "p.register_plotter(p_svg)\n", "p.register_plotter(p_hpgl)\n", "\n", "p.move_to(a.bottom_left())\n", "p.line_to(a.bottom_right())\n", "p.line_to(a.top_right())\n", "p.line_to(a.top_left())\n", "p.line_to(a.bottom_left())\n", "\n", "A = np.array([[-0.4, -0.2], [0.1, -0.3]])\n", "A = np.random.normal(size=(2, 2))\n", "\n", "def plot_ode(A):\n", " dia = np.min(a.size()) * 0.75\n", " # step_size = 0.01 / np.max(np.abs(np.linalg.eig(A)[0]))\n", "\n", " states = np.linspace(0, 2 * np.pi, 24)\n", " states = np.vstack([np.cos(states), np.sin(states)])\n", " for s in states.T:\n", " p.move_to(s * dia / 2 + a.centre())\n", " for _ in range(100000):\n", " step = A @ s\n", " step *= (0.5 / dia) / np.linalg.norm(step)\n", " s = step + s\n", " n = s * dia / 2 + a.centre()\n", " if not a.is_within(n):\n", " break\n", " if np.linalg.norm(s * dia / 2) < 0.5:\n", " break\n", " p.line_to(n)\n", "\n", "p.add_layer([1, 0, 1, 0.5])\n", "plot_ode(A)\n", "p.add_layer([1, 0, 0, 0.5])\n", "plot_ode(-A)\n", "# A = np.linalg.inv(A)\n", "# plot_ode(A)\n", "# plot_ode(-A)\n", "\n", "p.finalise()\n", "\n", "IPython.display.SVG(filename=p_svg.file_name)" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3.9.15 64-bit", "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.9.15" }, "orig_nbformat": 4, "vscode": { "interpreter": { "hash": "1dc4d77b1edb83bef89f833b7ed5251134c6a4899ef5e2c90c44e9927b4ae63a" } } }, "nbformat": 4, "nbformat_minor": 2 }