0

I am struggling to understand the behaviour of dsolve for this simple ODE:

Y''(t) = b*Y'(t) + f(t)

For some reason, dsolve throws an error if I use f(t)=exp(t-a), but for general f(t) or f(t)=exp(a*t) or if I put a value for a, dsolve succeeds. The complete error message:

File "~/.local/lib/python3.7/site-packages/sympy/solvers/ode.py", line 679, in dsolve return _helper_simplify(eq, hint, hints, simplify, ics=ics)

File "~/.local/lib/python3.7/site-packages/sympy/solvers/ode.py", line 704, in _helper_simplify sols = solvefunc(eq, func, order, match)

File "~/.local/lib/python3.7/site-packages/sympy/solvers/ode.py", line 5674, in ode_nth_linear_constant_coeff_undetermined_coefficients return _solve_undetermined_coefficients(eq, func, order, match)

File "~/.local/lib/python3.7/site-packages/sympy/solvers/ode.py", line 5766, in _solve_undetermined_coefficients coeffsdict[s[x]] += s['coeff']

KeyError: exp(t)

I am using this code:

from sympy import symbols, Function, dsolve, exp, Eq
a, b, t = symbols('a b t')
Y = Function('Y')(t)
#f = Function('f')(t) # works
#f = exp(a*t) # works
f = exp(t-a) # KeyError: exp(t)
#f = exp(t-2) # works
odeY = Eq( Y.diff(t,t), b*Y.diff(t) + f )
dsolve(odeY,Y)

I am using sympy version 1.5.1 with python3.7

Many thanks!

DNick
  • 3
  • 2
  • 1
    This is fixed in the latest version of sympy. You can install 1.6rc1 with `pip install --pre sympy` – Oscar Benjamin May 18 '20 at 18:43
  • Thanks @OscarBenjamin. I should have said I am using python3, so when I do `pip3 install --pre sympy` I get: _Requirement already satisfied: sympy in ./.local/lib/python3.7/site-packages (1.5.1) Requirement already satisfied: mpmath>=0.19 in ./.local/lib/python3.7/site-packages (from sympy) (1.1.0)_ Does this mean that 1.6rc1 is not available for python3 yet? – DNick May 19 '20 at 08:03
  • I followed the instructions [here](https://www.mail-archive.com/sympy@googlegroups.com/msg34562.html) and used `pip3 install -U --pre sympy` which successfully installed sympy-1.6rc1. I learned that this release in fact is not supported under python-2.7, it requires 3.5-3.8. In any case, dsolve now solves the ODE as it should, thanks for the hint @OscarBenjamin ! – DNick May 19 '20 at 08:23

0 Answers0