{ "cells": [ { "cell_type": "code", "execution_count": 1, "id": "d9b87334-514c-41fa-aab5-ecef29c4c94d", "metadata": {}, "outputs": [], "source": [ "import numpy as np\n", "import matplotlib.pyplot as plt\n", "from sympy import *" ] }, { "cell_type": "markdown", "id": "6b45c0a5-2069-4b11-b208-e2fa3dcc1820", "metadata": {}, "source": [ "**Dane Sabo**\n", "\n", "*September 18th, 2024*" ] }, { "cell_type": "markdown", "id": "0f1d7205-998f-4cbc-b3b3-df3afda5804c", "metadata": {}, "source": [ "# Instructions\n", "\n", "Please do a written solution for problems 1 and 2. We will review them on Monday, Sept 16 in class prior to the assignment being due.\n", "\n", "Please upload a Jupyter Notebook for problems 3 and 4.\n", "\n", "Problems 1 and 2 are worth 10 points each, problems 3 and 4 are worth 15 points each.\n", "\n", "# Written Problems\n", "## Problem 1\n", "Please find the general solution of \n", "$$\n", "\\bf{\\dot{X}} = \n", "\\begin{bmatrix} \n", "-1 & 5 & 2\\\\ \n", "4 & -1 & -2\\\\\n", "0 & 0 & 6\n", "\\end{bmatrix}\n", "\\bf{X}\n", "$$" ] }, { "cell_type": "code", "execution_count": 9, "id": "fc73f387-de90-4c25-b24c-ec91ea774ce8", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "⎡d ⎤ \n", "⎢──(x₁(t))⎥ \n", "⎢dt ⎥ \n", "⎢ ⎥ ⎡-x₁(t) + 5⋅x₂(t) + 2⋅x₃(t)⎤\n", "⎢d ⎥ ⎢ ⎥\n", "⎢──(x₂(t))⎥ = ⎢4⋅x₁(t) - x₂(t) - 2⋅x₃(t) ⎥\n", "⎢dt ⎥ ⎢ ⎥\n", "⎢ ⎥ ⎣ 6⋅x₃(t) ⎦\n", "⎢d ⎥ \n", "⎢──(x₃(t))⎥ \n", "⎣dt ⎦ \n" ] } ], "source": [ "t, s = symbols('t, s')\n", "x = Matrix([Function('x1')(t), Function('x2')(t), Function('x3')(t)])\n", "x_dot = x.diff(t) \n", "A = Matrix([[-1, 5, 2],[4, -1, -2], [0, 0, 6]])\n", "\n", "eq = Eq(x_dot,A*x)\n", "print(pretty(eq))" ] }, { "cell_type": "markdown", "id": "9203ea18-e9e6-424b-bb2e-c12ef880f40b", "metadata": {}, "source": [ "First we have to find the fundamental matrix $\\bf{\\Psi}(t) = e^{\\bf{A}t}$:\n", "$$e^{\\bf{A}t} = \\mathcal{L}^{-1} \\{ (sI-\\bf{A})^{-1} \\} $$" ] }, { "cell_type": "code", "execution_count": 10, "id": "bcfcdd55-34a5-4fb5-a91c-f1b540cef71f", "metadata": {}, "outputs": [ { "ename": "TypeError", "evalue": "inverse_laplace_transform() missing 2 required positional arguments: 's' and 't'", "output_type": "error", "traceback": [ "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", "\u001b[0;31mTypeError\u001b[0m Traceback (most recent call last)", "Cell \u001b[0;32mIn[10], line 1\u001b[0m\n\u001b[0;32m----> 1\u001b[0m psi_t \u001b[38;5;241m=\u001b[39m \u001b[43minverse_laplace_transform\u001b[49m\u001b[43m(\u001b[49m\u001b[43mMatPow\u001b[49m\u001b[43m(\u001b[49m\u001b[43ms\u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43meye\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;241;43m3\u001b[39;49m\u001b[43m)\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m-\u001b[39;49m\u001b[43m \u001b[49m\u001b[43mA\u001b[49m\u001b[43m,\u001b[49m\u001b[38;5;241;43m-\u001b[39;49m\u001b[38;5;241;43m1\u001b[39;49m\u001b[43m)\u001b[49m\u001b[43m)\u001b[49m\n", "\u001b[0;31mTypeError\u001b[0m: inverse_laplace_transform() missing 2 required positional arguments: 's' and 't'" ] } ], "source": [ "psi_t = inverse_laplace_transform(MatPow(s*eye(3) - A,-1))" ] }, { "cell_type": "markdown", "id": "14643f79-07ea-4d87-b81e-39244b1a3fa7", "metadata": {}, "source": [ "## Problem 2\n", "Please find the general solution of \n", "$$\n", "\\bf{\\dot{X}} = \n", "\\begin{bmatrix} \n", "-6 & 5 \\\\ \n", "-5 & 4 \\\\\n", "\\end{bmatrix}\n", "\\bf{X}\n", "$$" ] }, { "cell_type": "code", "execution_count": null, "id": "390b5ac8-c156-4606-8d69-1b86b80fcefd", "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "markdown", "id": "4c0f6f7a-d495-4f06-8d7c-a81f0f9ac2fc", "metadata": {}, "source": [ "# Python Problems\n", "## Problem 3\n", "The Archimedes Spiral can be plotted by taking all the positive whole numbers (e.g.j = 0, 1, 2, 3, 4, 5, ...) and putting them into the format $n = (j,j)$ , and plotting them in polar coordinates where the first term, $n_1$, is the radius, and the second term, $n_2$, is the angle in radians.\n", "### Part A\n", "You need to plot the first 1000 terms in a scatter plot. In addition, we would like to only look at the top right quadrant! What you're going for is shown in Figure 1." ] }, { "cell_type": "code", "execution_count": null, "id": "5e4b28fb-f18f-44ae-887e-9088446f2e5d", "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "markdown", "id": "fde7a33e-6eb1-47b0-8867-85792164a17c", "metadata": {}, "source": [ "### Part B\n", "You need to plot the first 25 terms, looking at th eentire polar plot (all quadrants, and then, put a *smooth* line through it. What you're going for is shown in Figure 2.)\n", "Hint: [This will be a useful reference](https://matplotlib.org/stable/gallery/pie_and_polar_charts/index.html)" ] }, { "cell_type": "code", "execution_count": null, "id": "d03285bf-09a6-4b79-b6e2-aaf35c56f96f", "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "markdown", "id": "607410b5-74aa-44fd-ad88-4ed702dad2bc", "metadata": {}, "source": [ "## Problem 4\n", "Consider the following system:\n", "$$\n", "\\bf{\\dot{X}} = \n", "\\begin{bmatrix} \n", "1 & 2 & 1\\\\ \n", "3 & 1+x & 1\\\\\n", "1 & 0 & 0\n", "\\end{bmatrix}\n", "\\bf{X}\n", "$$\n", "This linear differential equation system’s behavior is governed by its eigenvalues. In particular, the eigenvalues relate to stability and we may wish to see where they cross the 0 line (in terms of their real value). The constant x varies over the interval [−5, 5]. Using a Jupyter Notebook (local, or on Google Colab), Python, NumPy, and Matplotlib’s PyPlot, you should evaluate the eigenvalues for 50 evenly spaced values of x between −5 and 5, and produce a plot that visualizes the variation in the three eigenvalues as x varies. An example plot is shown in Figure 3 (for a different matrix!)" ] }, { "cell_type": "code", "execution_count": null, "id": "368c0e47-f034-47e0-845c-f894ef601afc", "metadata": {}, "outputs": [], "source": [] } ], "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 }