On Sun, 3 Apr 2022 at 23:39, kang li <kang.mat...@gmail.com> wrote:

> There is an issue in the sympy.dsolve module. When I was trying to solve
> the ode: -B(t)^2 - B'(t) +1 =0. The proper result should be tanh(C_1 - t),
> while the given result is the 1/tanh(C_1 - t).
>
> On Tue, 5 Apr 2022 at 03:31, kang li <kang.maths.oxf...@gmail.com> wrote:

> Sorry for the typo, the equation is  -B(t)^2 + B'(t) +1 =0. And the
> picture is right. The problem still remains.
>

Both answers tanh(C1-t) and 1/tanh(C1-t) are equivalent for different
values of the constant. It's important to understand that the constants can
be non-real:

In [48]: C1, C2 = symbols('C1, C2')

In [49]: sol1 = 1/tanh(C1 - t)

In [50]: sol2 = tanh(C2 - t)

In [51]: sol1.subs(C1, C2 - I*pi/2).rewrite(tanh) == sol2
Out[51]: True

Of course ideally the answer should be given in a form such that for real
initial conditions the constants are real-valued. In this particular case
it isn't possible to do that for all possible choices of real initial
conditions:

If the initial condition is in the range (-1, 1) then the tanh(C - t) form
can satisfy them with real C. However if the initial condition is greater
than 1 or less than -1 then only the 1/tanh(C-t) form will satisfy the
initial condition with real C. Neither form of the solution is preferable
for all possible choices of initial conditions.

What is an issue is the fact that if you give initial conditions then
dsolve errors out:

In [59]: dsolve(eq, B(t), ics={B(0):0})
...
NotImplementedError: Initial conditions produced too many solutions for
constants

This happens because solving for the constants gives:
[{C1: -I*pi/2}, {C1: I*pi/2}]

Either choice of value for the constant gives the correct solution though:

In [11]: sol = dsolve(eq, B(t))

In [12]: print(sol)
Eq(B(t), 1/tanh(C1 - t))

In [13]: print(sol.subs(C1, -I*pi/2))
Eq(B(t), -1/coth(t))

In [14]: print(sol.subs(C1, I*pi/2))
Eq(B(t), -1/coth(t))

The initial condition handling code in dsolve should be fixed to handle
cases like this.

Oscar

-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sympy/CAHVvXxTaJY1ocxN2VRmrh23Sk0T%3DXRHHnyCjTHVhT2nQh%2BTh%3Dw%40mail.gmail.com.

Reply via email to