# 352 - Topic 09 - Solving 1st order systems

## 2976 days ago by Professor352

John Travis

Mississippi College

Solving symbolically a system of first-order differential equations.

# adapted directly from the sage documentation t = var('t') x = function('x', t) y = function('y', t) de1 = diff(x,t) - y == 0 de2 = diff(y,t) + x == 0 soln = desolve_system([de1, de2], [x,y]) for sol in soln: sol.show()
 \newcommand{\Bold}{\mathbf{#1}}x\left(t\right) = \sin\left(t\right) y\left(0\right) + \cos\left(t\right) x\left(0\right)\newcommand{\Bold}{\mathbf{#1}}y\left(t\right) = -\sin\left(t\right) x\left(0\right) + \cos\left(t\right) y\left(0\right) \newcommand{\Bold}{\mathbf{#1}}x\left(t\right) = \sin\left(t\right) y\left(0\right) + \cos\left(t\right) x\left(0\right)\newcommand{\Bold}{\mathbf{#1}}y\left(t\right) = -\sin\left(t\right) x\left(0\right) + \cos\left(t\right) y\left(0\right)
# now how about a linear predator-prey model with (x_0,y_0) given t = var('t') x = function('x', t) y = function('y', t) de1 = diff(x,t) + y - x == 0 de2 = diff(y,t) - x + y == 0 soln = desolve_system([de1, de2], [x,y], ics=[0,2,3]) for sol in soln: sol.show()
 \newcommand{\Bold}{\mathbf{#1}}x\left(t\right) = -t + 2\newcommand{\Bold}{\mathbf{#1}}y\left(t\right) = -t + 3 \newcommand{\Bold}{\mathbf{#1}}x\left(t\right) = -t + 2\newcommand{\Bold}{\mathbf{#1}}y\left(t\right) = -t + 3
# now how about a non-linear predator-prey model with (x_0,y_0) given t = var('t') x = function('x', t) y = function('y', t) de1 = diff(x,t) + y*x - x == 0 de2 = diff(y,t) - x*y + y == 0 soln = desolve_system([de1, de2], [x,y], ics=[0,2,3],ivar=t) for sol in soln: sol.show()
 Traceback (click to the left of this block for traceback) ... TypeError: unable to make sense of Maxima expression 'x(t)=ilt(-(laplace(x(t)*y(t),t,?g2441)-2)/(?g2441-1),?g2441,t)' in Sage Traceback (most recent call last): soln = desolve_system([de1, de2], [x,y], ics=[0,2,3],ivar=t) File "", line 1, in File "/tmp/tmp2crObb/___code___.py", line 8, in soln = desolve_system([de1, de2], [x,y], ics=[_sage_const_0 ,_sage_const_2 ,_sage_const_3 ],ivar=t) File "/home/sageserver/sage/local/lib/python2.6/site-packages/sage/calculus/desolvers.py", line 743, in desolve_system soln[i] = sol.sage() File "/home/sageserver/sage/local/lib/python2.6/site-packages/sage/interfaces/expect.py", line 1788, in sage return self._sage_() File "/home/sageserver/sage/local/lib/python2.6/site-packages/sage/interfaces/maxima.py", line 1824, in _sage_ maxima=self.parent()) File "/home/sageserver/sage/local/lib/python2.6/site-packages/sage/calculus/calculus.py", line 1654, in symbolic_expression_from_maxima_string raise TypeError, "unable to make sense of Maxima expression '%s' in Sage"%s TypeError: unable to make sense of Maxima expression 'x(t)=ilt(-(laplace(x(t)*y(t),t,?g2441)-2)/(?g2441-1),?g2441,t)' in Sage
# now how about a non-linear predator-prey model # with (x_0,y_0) given. # Notice, you can rotate the graph to see # the phase plane x vs y as well as t vs x and t vs y reset() t,x,y = var('t,x,y') de1 = -y*x + 3*x de2 = x*y - y soln = desolve_system_rk4([de1, de2], [x,y], ics=[0,0.6,0.7],ivar=t,end_points=20) points(soln,size=20)
# Here is a problem that is partially decoupled and # which you can solve by hand analytically. But, Sage # (through the package Maxima) can't do it. var('t') x = function('x',t) y = function('y',t) de1 = diff(y,t)+3*y == 0 de2 = diff(x,t)-x/y == 0 soln =desolve_system([de1,de2],[y,x],ivar=t)
 Traceback (click to the left of this block for traceback) ... TypeError: unable to make sense of Maxima expression 'x(t)=ilt((laplace(x(t)/y(t),t,?g3057)+2)/?g3057,?g3057,t)' in Sage Traceback (most recent call last): File "", line 1, in File "_sage_input_17.py", line 10, in exec compile(u'open("___code___.py","w").write("# -*- coding: utf-8 -*-\\n" + _support_.preparse_worksheet_cell(base64.b64decode("dmFyKCd0JykKeCA9IGZ1bmN0aW9uKCd4Jyx0KQp5ID0gZnVuY3Rpb24oJ3knLHQpCmRlMSA9IGRpZmYoeSx0KSszKnkgPT0gMApkZTIgPSBkaWZmKHgsdCkteC95ID09IDAKc29sbiA9ZGVzb2x2ZV9zeXN0ZW0oW2RlMSxkZTJdLFt5LHhdLGl2YXI9dCk="),globals())+"\\n"); execfile(os.path.abspath("___code___.py")) File "", line 1, in File "/tmp/tmpqRgnEa/___code___.py", line 8, in exec compile(u'soln =desolve_system([de1,de2],[y,x],ivar=t) File "", line 1, in File "/home/sageserver/sage/local/lib/python2.6/site-packages/sage/calculus/desolvers.py", line 743, in desolve_system soln[i] = sol.sage() File "/home/sageserver/sage/local/lib/python2.6/site-packages/sage/interfaces/expect.py", line 1788, in sage return self._sage_() File "/home/sageserver/sage/local/lib/python2.6/site-packages/sage/interfaces/maxima.py", line 1824, in _sage_ maxima=self.parent()) File "/home/sageserver/sage/local/lib/python2.6/site-packages/sage/calculus/calculus.py", line 1654, in symbolic_expression_from_maxima_string raise TypeError, "unable to make sense of Maxima expression '%s' in Sage"%s TypeError: unable to make sense of Maxima expression 'x(t)=ilt((laplace(x(t)/y(t),t,?g3057)+2)/?g3057,?g3057,t)' in Sage