I'm having a lot of problems trying to solve a system of linear differential
equations (which somehow looks like it should have an easy solution, but I might
be wrong):
#!/usr/bin/env python
import sympy
α, β = sympy.symbols(r'\alpha, \beta', cls=sympy.Function)
κ = sympy.symbols(r'\kappa', positive=True)
t = sympy.symbols(r't', positive=True)
c1 = κ / sympy.sqrt(2)
c2 = κ * sympy.sqrt(2)
DE1 = sympy.Eq(α(t).diff(t), c1 * β(t))
DE2 = sympy.Eq(β(t).diff(t), -κ * β(t) - c2 * α(t))
sympy.dsolve([DE1, DE2], [α(t), β(t)], hint='1st_linear')
sympy.dsolve([DE1, DE2])
The first attempt gives me a backtrace because it fails to determine the order
for each function when the function names are given explicitly
Traceback (most recent call last):
File "./test_sympy.py", line 14, in <module>
sympy.dsolve([DE1, DE2], [α(t), β(t)], hint='1st_linear')
File "/Users/goerz/anaconda/envs/python34/lib/python3.4/site-packages/sympy/solvers/ode.py", line 579, in dsolve
match = classify_sysode(eq, func)
File "/Users/goerz/anaconda/envs/python34/lib/python3.4/site-packages/sympy/solvers/ode.py", line 1366, in classify_sysode
if not order[func]:
KeyError: \alpha(t)
This looks like a bug to me.
The second attempt gives me the following:
Traceback (most recent call last):
File "./test_sympy.py", line 13, in <module>
sympy.dsolve([DE1, DE2])
File "/Users/goerz/anaconda/envs/python34/lib/python3.4/site-packages/sympy/solvers/ode.py", line 612, in dsolve
sols = solvefunc(match)
File "/Users/goerz/anaconda/envs/python34/lib/python3.4/site-packages/sympy/solvers/ode.py", line 6394, in sysode_linear_2eq_order1
sol = _linear_2eq_order1_type1(x, y, t, r)
File "/Users/goerz/anaconda/envs/python34/lib/python3.4/site-packages/sympy/solvers/ode.py", line 6485, in _linear_2eq_order1_type1
l1 = RootOf(l**2 - (r['a']+r['d'])*l + r['a']*r['d'] - r['b']*r['c'], 0)
File "/Users/goerz/anaconda/envs/python34/lib/python3.4/site-packages/sympy/polys/rootoftools.py", line 70, in __new__
raise PolynomialError("only univariate polynomials are allowed")
sympy.polys.polyerrors.PolynomialError: only univariate polynomials are allowed
Not sure what to do with that.
I'm a little surprised this is so difficult. I was somehow assuming that this
would be a core feature (trying to replace Mathematica with SymPy).
The current documentation on systems of differential equations isn't overly
helpful :-/
Best,
Michael