dsolve fails for system of equations

68 views
Skip to first unread message

G B

unread,
Apr 3, 2015, 6:40:59 PM4/3/15
to sy...@googlegroups.com
I'm having trouble getting dsolve to work with a system of equations.  If possible I'd like to find a work around so I can continue the work I'm doing...

I'm using IPython 3.4.  Here's a simple test case:

from sympy import *
t,c,d=symbols(r't,c,d')
A,B=symbols(r'A,B',cls=Function)
Eq1=Eq(A(t).diff(t),B(t)-B(t).diff(t)+c)
Eq2=Eq(A(t),B(t).diff(t)+A(t).diff(t)+d)


Now, I've tried this both with and without providing the functions to solve for, and get different exceptions each way.  If I try without:

dsolve([Eq1,Eq2])

I get traceback:
==============================================
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-16-5b402de4ba25> in <module>()
----> 1 dsolve([Eq1,Eq2])

//anaconda/lib/python3.4/site-packages/sympy/solvers/ode.py in dsolve(eq, func, hint, simplify, ics, xi, eta, x0, n, **kwargs)
    577     """
    578     if iterable(eq):
--> 579         match = classify_sysode(eq, func)
    580         eq = match['eq']
    581         order = match['order']

//anaconda/lib/python3.4/site-packages/sympy/solvers/ode.py in classify_sysode(eq, funcs, **kwargs)
   1445             if matching_hints['no_of_equation'] == 2:
   1446                 if order_eq == 1:
-> 1447                     type_of_equation = check_linear_2eq_order1(eq, funcs, func_coef)
   1448                 elif order_eq == 2:
   1449                     type_of_equation = check_linear_2eq_order2(eq, funcs, func_coef)

//anaconda/lib/python3.4/site-packages/sympy/solvers/ode.py in check_linear_2eq_order1(eq, func, func_coef)
   1485 
   1486 def check_linear_2eq_order1(eq, func, func_coef):
-> 1487     x = func[0].func
   1488     y = func[1].func
   1489     fc = func_coef

AttributeError: 'list' object has no attribute 'func'
==========================================


If I try with, I get:

dsolve([Eq1,Eq2],[A(t),B(t)])

=============================================
---------------------------------------------------------------------------
KeyError                                  Traceback (most recent call last)
<ipython-input-17-6cffcb27ff03> in <module>()
----> 1 dsolve([Eq1,Eq2],[A(t),B(t)])

//anaconda/lib/python3.4/site-packages/sympy/solvers/ode.py in dsolve(eq, func, hint, simplify, ics, xi, eta, x0, n, **kwargs)
    577     """
    578     if iterable(eq):
--> 579         match = classify_sysode(eq, func)
    580         eq = match['eq']
    581         order = match['order']

//anaconda/lib/python3.4/site-packages/sympy/solvers/ode.py in classify_sysode(eq, funcs, **kwargs)
   1364     func_dict = dict()
   1365     for func in funcs:
-> 1366         if not order[func]:
   1367             max_order = 0
   1368             for i, eqs_ in enumerate(eq):

KeyError: A(t)
==========================================================

Colin Macdonald

unread,
Apr 4, 2015, 6:05:01 AM4/4/15
to sy...@googlegroups.com
On 03/04/15 23:40, G B wrote:
> I'm having trouble getting dsolve to work with a system of equations. If
> possible I'd like to find a work around so I can continue the work I'm
> doing...
>
> I'm using IPython 3.4. Here's a simple test case:
>
> from sympy import *
> t,c,d=symbols(r't,c,d')
> A,B=symbols(r'A,B',cls=Function)
> Eq1=Eq(A(t).diff(t),B(t)-B(t).diff(t)+c)
> Eq2=Eq(A(t),B(t).diff(t)+A(t).diff(t)+d)

Maybe just file an issue? dsolve for systems is a real mess, see e.g.,

https://github.com/sympy/sympy/pull/9235

I'm also not sure that form is supported. You could rework it by hand
isolate `A(t).diff(t)` and `B(t).diff(t)` as the two left-hand sides and
try again...

Colin
Reply all
Reply to author
Forward
0 new messages