Trouble solving the system of nonlinear differential equations in sage math

38 Views Asked by At

I am solving a 9x9 system of ordinary differential equations. In simple terms, I need to get the equilibrium expressions for the system. I am using the solve command in sage, but I get an error whose cause I don't know. Kindly help.

Declare variables

mu_h,beta,alpha,gamma_r,gamma_s,omega,mu_m,epsilon,theta,N_h,S_h,I_hr,I_hs,I_hsr,R_h,N_m,S_m,I_mr,I_ms,I_msr  = var('mu_h,beta,alpha,gamma_r,gamma_s,omega,mu_m,epsilon,theta,N_h,S_h,I_hr,I_hs,I_hsr,R_h,N_m,S_m,I_mr,I_ms,I_msr')

System of equations.

````dI_hrdt  = (beta*S_h*I_mr) - (mu_h*I_hr) - (gamma_r*I_hr) - (alpha*I_hr)*(I_ms +I_msr)
````dI_hsdt  = (beta*S_h*I_ms) - (mu_h*I_hs) - (gamma_s*I_hs) - (alpha*I_hs)*(I_mr +I_msr)
````dI_hsrdt = (beta*S_h*I_msr) - (mu_h*I_hsr) - (gamma_r*I_hsr) + (alpha*I_hr)*(I_ms +I_msr) + (alpha*I_hs)*(I_mr +I_msr)
````dR_hdt   = (gamma_r*I_hr) + (gamma_s*I_hs) + (gamma_r*I_hsr) -(mu_h*R_h)- (omega*R_h)
````dS_mdt   = (mu_m*N_m) - (epsilon*S_m)*(I_hr + I_hs +I_hsr) - (mu_m*S_m)
````dI_mrdt  = (epsilon*S_m*I_hr) - (mu_m*I_mr) - (theta*I_mr)*(I_hs +I_hsr)
````dI_msdt  = (epsilon*S_m*I_hs) - (mu_m*I_ms) - (theta*I_ms)*(I_hr +I_hsr)
````dI_msrdt = (epsilon*S_m*I_hsr) - (mu_m*I_msr)  - (theta*I_mr)*(I_hs +I_hsr) - (theta*I_ms)*(I_hr +I_hsr)

##finding the equilibria
````soln = solve([dS_hdt==0,dI_hrdt==0,dI_hsdt==0,dI_hsrdt==0,dR_hdt==0,dS_mdt==0,dI_mrdt==0,dI_msdt==0,dI_msrdt==0],[S_h,I_hr,I_hs,I_hsr,R_h,S_m,I_mr,I_ms,I_msr])
````show(soln)

That is my code, I expected expressions for my variables, [S_h,I_hr,I_hs,I_hsr,R_h,S_m,I_mr,I_ms,I_msr], but instead I get an error. the error is given below.

`RuntimeError                              Traceback (most recent call last)
/opt/sagemath-9.3/local/lib/python3.7/site-packages/sage/interfaces/interface.py in __init__(self, parent, value, is_name, name)
    717             try:
--> 718                 self._name = parent._create(value, name=name)
    719             except (TypeError, RuntimeError, ValueError) as x:

/opt/sagemath-9.3/local/lib/python3.7/site-packages/sage/interfaces/maxima_lib.py in _create(self, value, name)
    603             else:
--> 604                 self.set(name, value)
    605         except RuntimeError as error:

/opt/sagemath-9.3/local/lib/python3.7/site-packages/sage/interfaces/maxima_lib.py in set(self, var, value)
    511         cmd = '%s : %s$'%(var, value.rstrip(';'))
--> 512         self.eval(cmd)
    513 

/opt/sagemath-9.3/local/lib/python3.7/site-packages/sage/interfaces/maxima_lib.py in _eval_line(self, line, locals, reformat, **kwds)
    457                 if statement:
--> 458                     maxima_eval("#$%s$" % statement)
    459         if not reformat:

/opt/sagemath-9.3/local/lib/python3.7/site-packages/sage/libs/ecl.pyx in sage.libs.ecl.EclObject.__call__ (build/cythonized/sage/libs/ecl.c:8609)()
    852         """
--> 853         lispargs = EclObject(list(args))
    854         return ecl_wrap(ecl_safe_apply(self.obj,(<EclObject>lispargs).obj))

/opt/sagemath-9.3/local/lib/python3.7/site-packages/sage/libs/ecl.pyx in sage.libs.ecl.EclObject.__init__ (build/cythonized/sage/libs/ecl.c:8072)()
    713         elif len(args) == 1:
--> 714             self.set_obj(python_to_ecl(args[0], True))
    715         elif len(args) == 2:

/opt/sagemath-9.3/local/lib/python3.7/site-packages/sage/libs/ecl.pyx in sage.libs.ecl.python_to_ecl (build/cythonized/sage/libs/ecl.c:7058)()
    487         else:
--> 488             L = cl_cons(python_to_ecl(pyobj[0], read_strings),Cnil)
    489             ptr = L

/opt/sagemath-9.3/local/lib/python3.7/site-packages/sage/libs/ecl.pyx in sage.libs.ecl.python_to_ecl (build/cythonized/sage/libs/ecl.c:6695)()
    463         if read_strings:
--> 464             return ecl_safe_funcall(read_from_string_clobj, o)
    465         else:

/opt/sagemath-9.3/local/lib/python3.7/site-packages/sage/libs/ecl.pyx in sage.libs.ecl.ecl_safe_funcall (build/cythonized/sage/libs/ecl.c:5665)()
    346 
--> 347     ecl_sig_on()
    348     ret = safe_cl_funcall(&error,func,arg)

RuntimeError: Aborted

During handling of the above exception, another exception occurred:

TypeError                                 Traceback (most recent call last)
/opt/sagemath-9.3/local/lib/python3.7/site-packages/sage/interfaces/interface.py in __call__(self, x, name)
    308         try:
--> 309             result = self._coerce_impl(x, use_special=False)
    310             return result if name is None else result.name(new_name=name)

/opt/sagemath-9.3/local/lib/python3.7/site-packages/sage/interfaces/interface.py in _coerce_impl(self, x, use_special)
    357                 else:
--> 358                     w = self(v)
    359                     A.append(w.name())

/opt/sagemath-9.3/local/lib/python3.7/site-packages/sage/interfaces/interface.py in __call__(self, x, name)
    301             # new element.
--> 302             result = self._coerce_from_special_method(x)
    303             return result if name is None else result.name(new_name=name)

/opt/sagemath-9.3/local/lib/python3.7/site-packages/sage/interfaces/maxima_lib.py in _coerce_from_special_method(self, x)
    384         else:
--> 385             return MaximaAbstract._coerce_from_special_method(self,x)
    386 

/opt/sagemath-9.3/local/lib/python3.7/site-packages/sage/interfaces/interface.py in _coerce_from_special_method(self, x)
    329         try:
--> 330             return (x.__getattribute__(s))(self)
    331         except AttributeError:

/opt/sagemath-9.3/local/lib/python3.7/site-packages/sage/symbolic/expression.pyx in sage.symbolic.expression.Expression._maxima_ (build/cythonized/sage/symbolic/expression.cpp:8014)()
   1023         else:
-> 1024             return super(Expression, self)._interface_(session)
   1025 

/opt/sagemath-9.3/local/lib/python3.7/site-packages/sage/structure/sage_object.pyx in sage.structure.sage_object.SageObject._interface_ (build/cythonized/sage/structure/sage_object.c:5759)()
    691                 raise NotImplementedError("coercion of object %s to %s not implemented:\n%s\n%s" % (repr(self), I))
--> 692         X = I(s)
    693         if c:

/opt/sagemath-9.3/local/lib/python3.7/site-packages/sage/interfaces/interface.py in __call__(self, x, name)
    294         if isinstance(x, str):
--> 295             return cls(self, x, name=name)
    296         try:

/opt/sagemath-9.3/local/lib/python3.7/site-packages/sage/interfaces/interface.py in __init__(self, parent, value, is_name, name)
    719             except (TypeError, RuntimeError, ValueError) as x:
--> 720                 raise TypeError(x)
    721 

TypeError: Aborted

During handling of the above exception, another exception occurred:

RuntimeError                              Traceback (most recent call last)
/opt/sagemath-9.3/local/lib/python3.7/site-packages/sage/interfaces/interface.py in __init__(self, parent, value, is_name, name)
    717             try:
--> 718                 self._name = parent._create(value, name=name)
    719             except (TypeError, RuntimeError, ValueError) as x:

/opt/sagemath-9.3/local/lib/python3.7/site-packages/sage/interfaces/maxima_lib.py in _create(self, value, name)
    603             else:
--> 604                 self.set(name, value)
    605         except RuntimeError as error:

/opt/sagemath-9.3/local/lib/python3.7/site-packages/sage/interfaces/maxima_lib.py in set(self, var, value)
    511         cmd = '%s : %s$'%(var, value.rstrip(';'))
--> 512         self.eval(cmd)
    513 

/opt/sagemath-9.3/local/lib/python3.7/site-packages/sage/interfaces/maxima_lib.py in _eval_line(self, line, locals, reformat, **kwds)
    457                 if statement:
--> 458                     maxima_eval("#$%s$" % statement)
    459         if not reformat:

/opt/sagemath-9.3/local/lib/python3.7/site-packages/sage/libs/ecl.pyx in sage.libs.ecl.EclObject.__call__ (build/cythonized/sage/libs/ecl.c:8609)()
    852         """
--> 853         lispargs = EclObject(list(args))
    854         return ecl_wrap(ecl_safe_apply(self.obj,(<EclObject>lispargs).obj))

/opt/sagemath-9.3/local/lib/python3.7/site-packages/sage/libs/ecl.pyx in sage.libs.ecl.EclObject.__init__ (build/cythonized/sage/libs/ecl.c:8072)()
    713         elif len(args) == 1:
--> 714             self.set_obj(python_to_ecl(args[0], True))
    715         elif len(args) == 2:

/opt/sagemath-9.3/local/lib/python3.7/site-packages/sage/libs/ecl.pyx in sage.libs.ecl.python_to_ecl (build/cythonized/sage/libs/ecl.c:7058)()
    487         else:
--> 488             L = cl_cons(python_to_ecl(pyobj[0], read_strings),Cnil)
    489             ptr = L

/opt/sagemath-9.3/local/lib/python3.7/site-packages/sage/libs/ecl.pyx in sage.libs.ecl.python_to_ecl (build/cythonized/sage/libs/ecl.c:6695)()
    463         if read_strings:
--> 464             return ecl_safe_funcall(read_from_string_clobj, o)
    465         else:

/opt/sagemath-9.3/local/lib/python3.7/site-packages/sage/libs/ecl.pyx in sage.libs.ecl.ecl_safe_funcall (build/cythonized/sage/libs/ecl.c:5665)()
    346 
--> 347     ecl_sig_on()
    348     ret = safe_cl_funcall(&error,func,arg)

RuntimeError: Aborted

During handling of the above exception, another exception occurred:

TypeError                                 Traceback (most recent call last)
/opt/sagemath-9.3/local/lib/python3.7/site-packages/sage/interfaces/interface.py in __call__(self, x, name)
    312             try:
--> 313                 return cls(self, str(x), name=name)
    314             except TypeError:

/opt/sagemath-9.3/local/lib/python3.7/site-packages/sage/interfaces/interface.py in __init__(self, parent, value, is_name, name)
    719             except (TypeError, RuntimeError, ValueError) as x:
--> 720                 raise TypeError(x)
    721 

TypeError: Aborted

During handling of the above exception, another exception occurred:

TypeError                                 Traceback (most recent call last)
<ipython-input-10-5fd138375d76> in <module>
     17 
     18 ##finding the equilibria
---> 19 soln = solve([dS_hdt==Integer(0),dI_hrdt==Integer(0),dI_hsdt==Integer(0),dI_hsrdt==Integer(0),dR_hdt==Integer(0),dS_mdt==Integer(0),dI_mrdt==Integer(0),dI_msdt==Integer(0),dI_msrdt==Integer(0)],[S_h,I_hr,I_hs,I_hsr,R_h,S_m,I_mr,I_ms,I_msr])
     20 show(soln)
     21 

/opt/sagemath-9.3/local/lib/python3.7/site-packages/sage/symbolic/relation.py in solve(f, *args, **kwds)
   1104 
   1105     from sage.calculus.calculus import maxima
-> 1106     m = maxima(f)
   1107 
   1108     try:

/opt/sagemath-9.3/local/lib/python3.7/site-packages/sage/interfaces/interface.py in __call__(self, x, name)
    313                 return cls(self, str(x), name=name)
    314             except TypeError:
--> 315                 raise TypeError(msg)
    316 
    317     def _coerce_from_special_method(self, x):

TypeError: Aborted
`
0

There are 0 best solutions below