Perhaps it would help to set a variable for the initial condition and
solve for that. Unfortunately, dsolve() doesn't presently handle the
case where the initial condition splits into two solutions.
>>> var('t0')
t0
>>> dsolve(ode, f(t), ics={f(0): t0})
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "./sympy/solvers/ode/ode.py", line 639, in dsolve
return _helper_simplify(eq, hint, hints, simplify, ics=ics)
File "./sympy/solvers/ode/ode.py", line 694, in _helper_simplify
solved_constants = solve_ics([rv], [r['func']], cons(rv), ics)
File "./sympy/solvers/ode/ode.py", line 808, in solve_ics
raise NotImplementedError("Initial conditions produced too many
solutions for constants")
NotImplementedError: Initial conditions produced too many solutions
for constants
I think it would be useful if it just returned both solutions here.
Internally, it is producing these two solutions
>>> sol.subs(solved_constants[0])
Eq(f(t), -1/tanh(-t + log(-sqrt((t0 - 1)/(t0 + 1)))))
>>> sol.subs(solved_constants[1])
Eq(f(t), -1/tanh(-t + log((t0 - 1)/(t0 + 1))/2))
It would then take some work to simplify this to your desired forms
(SymPy's own simplification algorithms could be improved here), but at
least in this form you can see how one solution produces a real
function for t0 > 1 and one for t0 < 1. I believe the critical
identities for the simplification are
>>> tanh(x + I*pi/2)
coth(x)
>>> coth(x + I*pi/2)
tanh(x)
>>> log(I)
I*pi/2
and of course 1/tanh(x) = coth(x).
Aaron Meurer
> --
> You received this message because you are subscribed to the Google Groups "sympy" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to
sympy+un...@googlegroups.com.
> To view this discussion on the web visit
https://groups.google.com/d/msgid/sympy/CAHVvXxR2GB86zb07TNLvS%3DQz3CRogyGW9S6Vv%3DxrZ%2BEJ2nAkcQ%40mail.gmail.com.