sagemath / sage

Main repository of SageMath
https://www.sagemath.org
Other
1.32k stars 451 forks source link

enhance desolve output from separable ODEs #17739

Open rwst opened 9 years ago

rwst commented 9 years ago

At the moment, desolve behaves like this even with trivial separable ODEs:

sage: t = var('t')
sage: y=function('y')(t)
sage: desolve(diff(y,t)-y^2,y)
-1/y(t) == _C + t
sage: desolve(diff(y,t)-y^2+y,y)
log(y(t) - 1) - log(y(t)) == _C + t
sage: desolve(diff(y,t)-y^2-1,y)
arctan(y(t)) == _C + t

They could be solved by substituting a variable for y(t) and calling solve. Only if there is no solution from solve the integrated equation should be given.

Upstream: Not yet reported upstream; Will do shortly.

Component: calculus

Issue created by migration from https://trac.sagemath.org/ticket/17739

rwst commented 9 years ago
comment:1

This would yield (doctest):

sage: t = var('t')
sage: y=function('y')(t)
sage: desolve(diff(y,t)-y^2,y)
-1/(_C + t)
sage: desolve(diff(y,t)-y^2+y,y)
-1/(e^(_C + t) - 1)
sage: desolve(diff(y,t)-y^2-1,y)
tan(_C + t)
rwst commented 9 years ago
comment:2

Do we resolve this in Sage, Maxima, or both?

kcrisman commented 9 years ago

Upstream: Not yet reported upstream; Will do shortly.

kcrisman commented 9 years ago
comment:3

You should report this upstream, but maybe first to the email list, not as a bug. Surely there must be a reason they report the solutions that way ... right? (For instance, maybe this is "more correct" than something with solve that might lose a solution or something. Though it's hard to see how that could happen in your first example!)

rwst commented 9 years ago
comment:4

Replying to @kcrisman:

You should report this upstream, but maybe first to the email list, not as a bug. Surely there must be a reason they report the solutions that way ... right?

It appears not, see http://sourceforge.net/p/maxima/mailman/message/33364512/

rwst commented 9 years ago
comment:5

So, the inconsistency is in Sage, which removes 'y==' from the results that have it, perhaps to facilitate further usage of the expression.

    if is_SymbolicEquation(soln) and soln.lhs() == dvar:
        # Remark: Here we do not check that the right hand side does not depend on dvar.
        # This probably will not hapen for soutions obtained via ode2, anyway.
        soln = soln.rhs()

We could now either remove the snippet, in order to always get an equation, or always try to solve for dvar and return an equation only when no solution is found.