{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "0e643cc2-eca9-4b7f-b942-bd15d13b7f60",
   "metadata": {},
   "outputs": [],
   "source": [
    "from scipy.integrate import odeint\n",
    "import matplotlib.pyplot as plt\n",
    "import numpy as np\n",
    "import pylab as pl"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "d0b6f7fc-f2dd-4a25-a264-c72a8fb1b252",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<Figure size 1200x1200 with 0 Axes>"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "text/plain": [
       "<Figure size 1200x1200 with 0 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "plt.figure(figsize = (12,12))\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "ae79c57a-5d98-480f-a8ac-3fb7b066be4b",
   "metadata": {},
   "outputs": [],
   "source": [
    "omega = 2\n",
    "omegasq = omega**2\n",
    "a, b, c, d = 0, 1, omegasq, -0.5"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "cb8788a7-9f2c-4924-82ca-782807c45d2f",
   "metadata": {},
   "outputs": [],
   "source": [
    "def dx_dt(xx,t):\n",
    "    x = xx[0]\n",
    "    y = xx[1]\n",
    "    term1 = y\n",
    "    term2 = -y - x + x**2 + y**2\n",
    "    return [term1, term2]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "cb60b342-c69a-4f1f-821e-5dd0a2b998ed",
   "metadata": {},
   "outputs": [],
   "source": [
    "maxtime = .5\n",
    "xmin = -2\n",
    "xmax = 2\n",
    "ts = np.linspace(0, maxtime, 1000)\n",
    "ic = np.linspace(xmin, xmax, 8) +0.001"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "234edaa5-eec7-4663-9a31-a2d5428037c1",
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "/tmp/ipykernel_31511/3640988554.py:4: ODEintWarning: Excess work done on this call (perhaps wrong Dfun type). Run with full_output = 1 to get quantitative information.\n",
      "  xs = odeint(dx_dt,x0,ts)\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "(-2.0, 2.0)"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "[encoded data, 69820 characters]",
      "text/plain": [
       "<Figure size 640x480 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "for r in ic:\n",
    "    for s in ic:\n",
    "        x0 = [r,s]\n",
    "        xs = odeint(dx_dt,x0,ts)\n",
    "        plt.plot(xs[:,0],xs[:,1],\"b\")\n",
    "\n",
    "plt.xlabel('x')\n",
    "plt.ylabel('y')\n",
    "plt.xlim(xmin,xmax)\n",
    "plt.ylim(xmin,xmax)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "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.12.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
