# 352 - Topic 08 - Solving other first-order equations

## 3336 days ago by Professor352

John Travis

Mississippi College

Playing around with solutions of various first-order differential equations.

html('Solving the first order linear DE $\\frac{dy}{dt} = P(t)y+Q(t)$ using Sage symbolics only') var('t') y = function('y',t) P = function('P',t) Q = function('Q',t) DE = diff(y,t)==P*y+Q soln=desolve(DE,y,ivar=t) html('<p><font size=+1>Solution is $y(t) = %s'%str(latex(soln)))  Solving the first order linear DE \frac{dy}{dt} = P(t)y+Q(t) using Sage symbolics onlySolution is y(t) = {\left(c + \int e^{\left(-\int P\left(t\right)\,{d t}\right)} Q\left(t\right)\,{d t}\right)} e^{\left(\int P\left(t\right)\,{d t}\right)} Solving the first order linear DE \frac{dy}{dt} = P(t)y+Q(t) using Sage symbolics onlySolution is y(t) = {\left(c + \int e^{\left(-\int P\left(t\right)\,{d t}\right)} Q\left(t\right)\,{d t}\right)} e^{\left(\int P\left(t\right)\,{d t}\right)} # Solving a particular first order linear DE using Sage var('t') y = function('y',t) P = function('P',t) Q = function('Q',t) assume(t>2) P = 1/sqrt(t^3-3) Q = t html('<font size=+1>Solving$\\frac{dy}{dt} = %s$'%str(latex(P))+'$y + %s$</font>'%str(latex(Q))) DE = diff(y,t)==P*y+Q soln=desolve(DE,y,ivar=t,ics=[1,3]) html('<p><font size=+1>Solution is$y(t) = %s'%str(latex(soln.expand()))) G=points(desolve_rk4(DE, y, ics=[1,3], ivar=t, end_points=3, step=0.1)) G+=plot(soln,t,[1,4]) show(G)
 Solving \frac{dy}{dt} = \frac{1}{\sqrt{t^{3} - 3}}y + tTraceback (click to the left of this block for traceback) ... ValueError: The name "y(t)" is not a valid Python identifier. Solving \frac{dy}{dt} = \frac{1}{\sqrt{t^{3} - 3}}y + tTraceback (most recent call last): P = 1/sqrt(t^3-3) File "", line 1, in File "/tmp/tmpSF0IHV/___code___.py", line 13, in soln=desolve(DE,y,ivar=t,ics=[_sage_const_1 ,_sage_const_3 ]) File "/usr/local/sage-5.3/local/lib/python2.7/site-packages/sage/calculus/desolvers.py", line 501, in desolve soln=soln.sage() File "/usr/local/sage-5.3/local/lib/python2.7/site-packages/sage/interfaces/interface.py", line 865, in sage return self._sage_() File "/usr/local/sage-5.3/local/lib/python2.7/site-packages/sage/interfaces/maxima_abstract.py", line 1224, in _sage_ maxima=self.parent()) File "/usr/local/sage-5.3/local/lib/python2.7/site-packages/sage/calculus/calculus.py", line 1789, in symbolic_expression_from_maxima_string return symbolic_expression_from_string(s, syms, accept_sequence=True) File "/usr/local/sage-5.3/local/lib/python2.7/site-packages/sage/calculus/calculus.py", line 1961, in symbolic_expression_from_string return parse_func(s) File "parser.pyx", line 516, in sage.misc.parser.Parser.parse_sequence (sage/misc/parser.c:4109) File "parser.pyx", line 531, in sage.misc.parser.Parser.parse_sequence (sage/misc/parser.c:3990) File "parser.pyx", line 602, in sage.misc.parser.Parser.p_sequence (sage/misc/parser.c:4731) File "parser.pyx", line 692, in sage.misc.parser.Parser.p_eqn (sage/misc/parser.c:5513) File "parser.pyx", line 728, in sage.misc.parser.Parser.p_expr (sage/misc/parser.c:5816) File "parser.pyx", line 761, in sage.misc.parser.Parser.p_term (sage/misc/parser.c:6056) File "parser.pyx", line 800, in sage.misc.parser.Parser.p_factor (sage/misc/parser.c:6410) File "parser.pyx", line 803, in sage.misc.parser.Parser.p_factor (sage/misc/parser.c:6439) File "parser.pyx", line 833, in sage.misc.parser.Parser.p_power (sage/misc/parser.c:6599) File "parser.pyx", line 803, in sage.misc.parser.Parser.p_factor (sage/misc/parser.c:6439) File "parser.pyx", line 830, in sage.misc.parser.Parser.p_power (sage/misc/parser.c:6568) File "parser.pyx", line 893, in sage.misc.parser.Parser.p_atom (sage/misc/parser.c:7203) File "parser.pyx", line 731, in sage.misc.parser.Parser.p_expr (sage/misc/parser.c:5854) File "parser.pyx", line 761, in sage.misc.parser.Parser.p_term (sage/misc/parser.c:6056) File "parser.pyx", line 803, in sage.misc.parser.Parser.p_factor (sage/misc/parser.c:6439) File "parser.pyx", line 830, in sage.misc.parser.Parser.p_power (sage/misc/parser.c:6568) File "parser.pyx", line 888, in sage.misc.parser.Parser.p_atom (sage/misc/parser.c:7142) File "/usr/local/sage-5.3/local/lib/python2.7/site-packages/sage/calculus/calculus.py", line 1451, in at return ex.subs(**kwds) File "expression.pyx", line 3753, in sage.symbolic.expression.Expression.substitute (sage/symbolic/expression.cpp:18208) File "ring.pyx", line 520, in sage.symbolic.ring.SymbolicRing.var (sage/symbolic/ring.cpp:6956) File "ring.pyx", line 568, in sage.symbolic.ring.SymbolicRing.var (sage/symbolic/ring.cpp:6689) ValueError: The name "y(t)" is not a valid Python identifier.
html('Solving a Bernoulli DE $\\frac{dy}{dt} = P(t)y+Q(t)y^2$ using Sage symbolics only') var('t') y = function('y',t) P = function('P',t) Q = function('Q',t) DE = diff(y,t)==P*y+Q*y^2 soln=desolve(DE,y,ivar=t) html('<p><font size=+1>Solution is $y(t) = %s'%str(latex(soln)))  Solving a Bernoulli DE \frac{dy}{dt} = P(t)y+Q(t)y^2 using Sage symbolics onlySolution is y(t) = \frac{e^{\left(\int P\left(t\right)\,{d t}\right)}}{c - \int e^{\left(\int P\left(t\right)\,{d t}\right)} Q\left(t\right)\,{d t}} Solving a Bernoulli DE \frac{dy}{dt} = P(t)y+Q(t)y^2 using Sage symbolics onlySolution is y(t) = \frac{e^{\left(\int P\left(t\right)\,{d t}\right)}}{c - \int e^{\left(\int P\left(t\right)\,{d t}\right)} Q\left(t\right)\,{d t}} # Solving a particular Bernoulli DE using Sage var('t') y = function('y',t) P = function('P',t) Q = function('Q',t) P = 2/t Q = -t^2 html('<font size=+1>Solving$\\frac{dy}{dt} = %s$'%str(latex(P))+'$y + %sy^2$</font>'%str(latex(Q))) DE = diff(y,t)==P*y+Q*y^2 soln=desolve(DE,y,ivar=t,ics=[1,3]) html('<font size=+1>Solution is$y(t) = %s'%str(latex(soln.expand()))) G=plot(soln,t,[1,4]) #G+=points(desolve_rk4(DE, y, ics=[1,3], ivar=t, end_points=3, step=0.1)) show(G)
 Solving \frac{dy}{dt} = \frac{2}{t}y + -t^{2}y^2Solution is y(t) = \frac{15 \, t^{2}}{3 \, t^{5} + 2} Solving \frac{dy}{dt} = \frac{2}{t}y + -t^{2}y^2Solution is y(t) = \frac{15 \, t^{2}}{3 \, t^{5} + 2}
# what about a DE with an arbitrary power on the last y... # notice, n=0 is first order linear...does solution fit? Yes # notice, n=1 is separable...does solution fit? No html('Solving $\\frac{dy}{dt} = P(t)y+Q(t)y^n$ using Sage symbolics only') var('t,n') y = function('y',t) P = function('P',t) Q = function('Q',t) DE = diff(y,t)==P*y+Q*y^n soln=desolve(DE,y,ivar=t) html('<p><font size=+1>Solution is $y(t) = %s'%str(latex(soln)))  Solving \frac{dy}{dt} = P(t)y+Q(t)y^n using Sage symbolics onlySolution is y(t) = {\left(-{\left(n - 1\right)} \int e^{\left({\left(n - 1\right)} \int P\left(t\right)\,{d t}\right)} Q\left(t\right)\,{d t} + c\right)}^{{\left(-\frac{1}{n - 1}\right)}} e^{\left(\int P\left(t\right)\,{d t}\right)} Solving \frac{dy}{dt} = P(t)y+Q(t)y^n using Sage symbolics onlySolution is y(t) = {\left(-{\left(n - 1\right)} \int e^{\left({\left(n - 1\right)} \int P\left(t\right)\,{d t}\right)} Q\left(t\right)\,{d t} + c\right)}^{{\left(-\frac{1}{n - 1}\right)}} e^{\left(\int P\left(t\right)\,{d t}\right)} # Solving a particular wierd DE using Sage var('t') y = function('y',t) P = function('P',t) Q = function('Q',t) P = 1/t^2 Q = 4 n=5 html('<font size=+1>Solving$\\frac{dy}{dt} = %s$'%str(latex(P))+'$y + %sy^n$</font>'%str(latex(Q))) DE = diff(y,t)==P*y+Q*y^n soln=desolve(DE,y,ivar=t,ics=[1,3]) html('<font size=+1>Solution is$y(t) = %s'%str(latex(soln.expand()))) G=plot(soln,t,[1,4]) #G+=points(desolve_rk4(DE, y, ics=[1,3], ivar=t, end_points=3, step=0.1)) show(G)
 Solving \frac{dy}{dt} = \frac{1}{t^{2}}y + 4y^nSolution is y(t) = \frac{3 \, e^{\left(-\frac{1}{t} + 1\right)}}{{\left(-5184 \, e^{4} \Gamma\left(-1, \frac{4}{t}\right) + 5184 \, e^{4} \Gamma\left(-1, 4\right) + 1\right)}^{\frac{1}{4}}}verbose 0 (4075: plot.py, generate_plot_points) WARNING: When plotting, failed to evaluate function at 199 points. verbose 0 (4075: plot.py, generate_plot_points) Last error message: 'negative number to a fractional power not real'  Solving \frac{dy}{dt} = \frac{1}{t^{2}}y + 4y^nSolution is y(t) = \frac{3 \, e^{\left(-\frac{1}{t} + 1\right)}}{{\left(-5184 \, e^{4} \Gamma\left(-1, \frac{4}{t}\right) + 5184 \, e^{4} \Gamma\left(-1, 4\right) + 1\right)}^{\frac{1}{4}}}verbose 0 (4075: plot.py, generate_plot_points) WARNING: When plotting, failed to evaluate function at 199 points. verbose 0 (4075: plot.py, generate_plot_points) Last error message: 'negative number to a fractional power not real'