{ "cells": [ { "cell_type": "code", "execution_count": 28, "metadata": {}, "outputs": [], "source": [ "from sympy import *" ] }, { "cell_type": "code", "execution_count": 29, "metadata": {}, "outputs": [], "source": [ "f = symbols('f', cls=Function)\n", "R, freq, t,L,C = symbols('R f t L C')" ] }, { "cell_type": "code", "execution_count": 30, "metadata": {}, "outputs": [ { "data": { "text/latex": [ "$\\displaystyle f{\\left(t \\right)}$" ], "text/plain": [ "f(t)" ] }, "execution_count": 30, "metadata": {}, "output_type": "execute_result" } ], "source": [ "f(t)" ] }, { "cell_type": "code", "execution_count": 31, "metadata": {}, "outputs": [ { "data": { "text/latex": [ "$\\displaystyle \\frac{d^{2}}{d t^{2}} f{\\left(t \\right)} + \\frac{f{\\left(t \\right)}}{C L} = 0$" ], "text/plain": [ "Eq(Derivative(f(t), (t, 2)) + f(t)/(C*L), 0)" ] }, "execution_count": 31, "metadata": {}, "output_type": "execute_result" } ], "source": [ "diffeq = Eq(f(t).diff(t,t)+f(t)/(L*C),0)\n", "diffeq" ] }, { "cell_type": "code", "execution_count": 32, "metadata": {}, "outputs": [ { "data": { "text/latex": [ "$\\displaystyle f{\\left(t \\right)} = C_{1} e^{- t \\sqrt{- \\frac{1}{C L}}} + C_{2} e^{t \\sqrt{- \\frac{1}{C L}}}$" ], "text/plain": [ "Eq(f(t), C1*exp(-t*sqrt(-1/(C*L))) + C2*exp(t*sqrt(-1/(C*L))))" ] }, "execution_count": 32, "metadata": {}, "output_type": "execute_result" } ], "source": [ "dsolve(diffeq, f(t))" ] }, { "cell_type": "code", "execution_count": 33, "metadata": {}, "outputs": [ { "data": { "text/latex": [ "$\\displaystyle \\frac{d^{2}}{d t^{2}} f{\\left(t \\right)} + \\frac{f{\\left(t \\right)}}{C L} = \\sin{\\left(2 \\pi f t \\right)}$" ], "text/plain": [ "Eq(Derivative(f(t), (t, 2)) + f(t)/(C*L), sin(2*pi*f*t))" ] }, "execution_count": 33, "metadata": {}, "output_type": "execute_result" } ], "source": [ "diffeq2 = Eq(f(t).diff(t,t)+f(t)/(L*C), sin(2*pi*freq*t))\n", "diffeq2" ] }, { "cell_type": "code", "execution_count": 34, "metadata": {}, "outputs": [ { "data": { "text/latex": [ "$\\displaystyle f{\\left(t \\right)} = - \\frac{C L \\sin{\\left(2 \\pi f t \\right)}}{4 \\pi^{2} C L f^{2} - 1} + C_{1} e^{- t \\sqrt{- \\frac{1}{C L}}} + C_{2} e^{t \\sqrt{- \\frac{1}{C L}}}$" ], "text/plain": [ "Eq(f(t), -C*L*sin(2*pi*f*t)/(4*pi**2*C*L*f**2 - 1) + C1*exp(-t*sqrt(-1/(C*L))) + C2*exp(t*sqrt(-1/(C*L))))" ] }, "execution_count": 34, "metadata": {}, "output_type": "execute_result" } ], "source": [ "dsolve(diffeq2, f(t))" ] }, { "cell_type": "code", "execution_count": 35, "metadata": {}, "outputs": [ { "data": { "text/latex": [ "$\\displaystyle L \\frac{d^{2}}{d t^{2}} f{\\left(t \\right)} + R \\frac{d}{d t} f{\\left(t \\right)} + \\frac{f{\\left(t \\right)}}{C} = 0$" ], "text/plain": [ "Eq(L*Derivative(f(t), (t, 2)) + R*Derivative(f(t), t) + f(t)/C, 0)" ] }, "execution_count": 35, "metadata": {}, "output_type": "execute_result" } ], "source": [ "diffeq3 = Eq(L*f(t).diff(t,t)+R*f(t).diff(t)+f(t)/C, 0)\n", "diffeq3" ] }, { "cell_type": "code", "execution_count": 36, "metadata": {}, "outputs": [ { "data": { "text/latex": [ "$\\displaystyle f{\\left(t \\right)} = C_{1} e^{\\frac{t \\left(- R - \\frac{\\sqrt{C \\left(C R^{2} - 4 L\\right)}}{C}\\right)}{2 L}} + C_{2} e^{\\frac{t \\left(- R + \\frac{\\sqrt{C \\left(C R^{2} - 4 L\\right)}}{C}\\right)}{2 L}}$" ], "text/plain": [ "Eq(f(t), C1*exp(t*(-R - sqrt(C*(C*R**2 - 4*L))/C)/(2*L)) + C2*exp(t*(-R + sqrt(C*(C*R**2 - 4*L))/C)/(2*L)))" ] }, "execution_count": 36, "metadata": {}, "output_type": "execute_result" } ], "source": [ "dsolve(diffeq3, f(t))" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "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.8.6" } }, "nbformat": 4, "nbformat_minor": 2 }