Created
April 30, 2024 19:55
-
-
Save vuddameri/55e47e011191864372c136874ea25557 to your computer and use it in GitHub Desktop.
Assignment4-8-9.ipynb
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| { | |
| "cells": [ | |
| { | |
| "cell_type": "markdown", | |
| "metadata": { | |
| "id": "view-in-github", | |
| "colab_type": "text" | |
| }, | |
| "source": [ | |
| "<a href=\"https://colab.research.google.com/gist/vuddameri/55e47e011191864372c136874ea25557/assignment4-8-9.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>" | |
| ] | |
| }, | |
| { | |
| "cell_type": "markdown", | |
| "id": "d6fb5e38", | |
| "metadata": { | |
| "id": "d6fb5e38" | |
| }, | |
| "source": [ | |
| "<h4>Problem Statement - Assignment 4-8-9" | |
| ] | |
| }, | |
| { | |
| "cell_type": "markdown", | |
| "id": "6ae6aaae", | |
| "metadata": { | |
| "id": "6ae6aaae" | |
| }, | |
| "source": [ | |
| "Calculate the Wronksian (set up the equations) and solve for the particular solution of the ODE: y\" + 2y'+26y = 82cos(4t)" | |
| ] | |
| }, | |
| { | |
| "cell_type": "markdown", | |
| "id": "8c0c1c51", | |
| "metadata": { | |
| "id": "8c0c1c51" | |
| }, | |
| "source": [ | |
| "<h4> Solve the Complementary Solution" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 2, | |
| "id": "f8f08d60", | |
| "metadata": { | |
| "id": "f8f08d60", | |
| "outputId": "b43f0d6a-2449-466e-bfc5-bd86b884c1ab", | |
| "colab": { | |
| "base_uri": "https://localhost:8080/", | |
| "height": 39 | |
| } | |
| }, | |
| "outputs": [ | |
| { | |
| "output_type": "execute_result", | |
| "data": { | |
| "text/plain": [ | |
| "Eq(x(t), (C1*sin(5*t) + C2*cos(5*t))*exp(-t))" | |
| ], | |
| "text/latex": "$\\displaystyle x{\\left(t \\right)} = \\left(C_{1} \\sin{\\left(5 t \\right)} + C_{2} \\cos{\\left(5 t \\right)}\\right) e^{- t}$" | |
| }, | |
| "metadata": {}, | |
| "execution_count": 2 | |
| } | |
| ], | |
| "source": [ | |
| "# Import library\n", | |
| "from sympy import diff, dsolve, symbols, Function, sin, cos, integrate, simplify,exp\n", | |
| "\n", | |
| "# Define the function and variables\n", | |
| "t = symbols('t') # Independent Variable\n", | |
| "x = Function('x')(t) # Dependent Variable\n", | |
| "hode = x.diff(t,t) + 2*x.diff(t)+ 26*x # Homogeneous Equation for complementary function\n", | |
| "sol = dsolve(hode) #obtain the complementary function\n", | |
| "sol" | |
| ] | |
| }, | |
| { | |
| "cell_type": "markdown", | |
| "id": "b05bfcce", | |
| "metadata": { | |
| "id": "b05bfcce" | |
| }, | |
| "source": [ | |
| "<h4> Equations for the Wronksian" | |
| ] | |
| }, | |
| { | |
| "cell_type": "markdown", | |
| "id": "09e889f9", | |
| "metadata": { | |
| "id": "09e889f9" | |
| }, | |
| "source": [ | |
| "From the complementary solution $y_1 = sin(5t)e^{-t}$ and $y_1 = cos(5t)e^{-t}$\n", | |
| "Let u and v be two functions of t which satisfy the following equations:\n", | |
| "\n", | |
| "$ u'y_1 + v'y_2 = 0 $\n", | |
| "\n", | |
| "$ u' y'_1 + v'y'_2 =82cos(4t) $\n" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 5, | |
| "id": "baf47fef", | |
| "metadata": { | |
| "id": "baf47fef", | |
| "outputId": "4155edff-6330-40f9-b4b4-417a3b780d3d", | |
| "colab": { | |
| "base_uri": "https://localhost:8080/", | |
| "height": 39 | |
| } | |
| }, | |
| "outputs": [ | |
| { | |
| "output_type": "execute_result", | |
| "data": { | |
| "text/plain": [ | |
| "-5*exp(-2*t)" | |
| ], | |
| "text/latex": "$\\displaystyle - 5 e^{- 2 t}$" | |
| }, | |
| "metadata": {}, | |
| "execution_count": 5 | |
| } | |
| ], | |
| "source": [ | |
| "# Calculate the Wronksian\n", | |
| "y1 = sin(5*t)*exp(-t)\n", | |
| "y1p = y1.diff(t)\n", | |
| "y2 = cos(5*t)*exp(-t)\n", | |
| "y2p = y2.diff(t)\n", | |
| "W = y1*y2p - y2*y1p\n", | |
| "W = simplify(W)\n", | |
| "W" | |
| ] | |
| }, | |
| { | |
| "cell_type": "markdown", | |
| "id": "22e4e064", | |
| "metadata": { | |
| "id": "22e4e064" | |
| }, | |
| "source": [ | |
| "Obtain the particular solution using the formula\n", | |
| "\n", | |
| "$ y_p = -y1(x) \\int \\frac{y2(x) f(x)}{W(x)}dx + y2(x) \\int \\frac{y1(x) f(x)}{W(x)}dx $" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 6, | |
| "id": "7feca356", | |
| "metadata": { | |
| "id": "7feca356", | |
| "outputId": "e3bb47ff-99fb-46a2-f41e-7482ddda2312", | |
| "colab": { | |
| "base_uri": "https://localhost:8080/", | |
| "height": 39 | |
| } | |
| }, | |
| "outputs": [ | |
| { | |
| "output_type": "execute_result", | |
| "data": { | |
| "text/plain": [ | |
| "4*sin(4*t) + 10*cos(2*t)**2 - 5" | |
| ], | |
| "text/latex": "$\\displaystyle 4 \\sin{\\left(4 t \\right)} + 10 \\cos^{2}{\\left(2 t \\right)} - 5$" | |
| }, | |
| "metadata": {}, | |
| "execution_count": 6 | |
| } | |
| ], | |
| "source": [ | |
| "Fx = 82*cos(4*t)\n", | |
| "yp1 = -y1* integrate(y2*Fx/W)\n", | |
| "yp2 = y2* integrate(y1*Fx/W)\n", | |
| "yp = yp1 + yp2\n", | |
| "simplify(yp)" | |
| ] | |
| }, | |
| { | |
| "cell_type": "markdown", | |
| "id": "484b3598", | |
| "metadata": { | |
| "id": "484b3598" | |
| }, | |
| "source": [ | |
| "Note: The result can be simplified or rewritten either by rewriting sin(4t) or cos$^2$(2t)" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": null, | |
| "id": "e8f66f29", | |
| "metadata": { | |
| "id": "e8f66f29" | |
| }, | |
| "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.10.12" | |
| }, | |
| "colab": { | |
| "provenance": [], | |
| "include_colab_link": true | |
| } | |
| }, | |
| "nbformat": 4, | |
| "nbformat_minor": 5 | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment