ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Wed, 02 Nov 2022 10:52:48 +0100Why desolve() can not solve an ODE while SymPy can?https://ask.sagemath.org/question/64722/why-desolve-can-not-solve-an-ode-while-sympy-can/ For example, in sage, when I call:
x=var('x')
f=function('f')(x)
desolve(f.diff(x)^2+1,f)
It will return:
NotImplementedError: Maxima was unable to solve this ODE. Consider to set option contrib_ode to True.
However, with SymPy, when I call:
x=symbols('x')
f=symbols('f',cls=Function)
dsolve(f(x).diff(x)**2+1,f(x))
It will return the exact result:
[Eq(f(x), C1 - I*x), Eq(f(x), C1 + I*x)]
I know maybe it because sage use Maxima in desolve but not SymPy, however, I consider using both of them and merge the result is a better choice. Or if there already exists a method to use SymPy in sgae?Tue, 01 Nov 2022 05:22:49 +0100https://ask.sagemath.org/question/64722/why-desolve-can-not-solve-an-ode-while-sympy-can/Comment by Emmanuel Charpentier for <p>For example, in sage, when I call:</p>
<pre><code>x=var('x')
f=function('f')(x)
desolve(f.diff(x)^2+1,f)
</code></pre>
<p>It will return:</p>
<pre><code>NotImplementedError: Maxima was unable to solve this ODE. Consider to set option contrib_ode to True.
</code></pre>
<p>However, with SymPy, when I call:</p>
<pre><code>x=symbols('x')
f=symbols('f',cls=Function)
dsolve(f(x).diff(x)**2+1,f(x))
</code></pre>
<p>It will return the exact result:</p>
<pre><code>[Eq(f(x), C1 - I*x), Eq(f(x), C1 + I*x)]
</code></pre>
<p>I know maybe it because sage use Maxima in desolve but not SymPy, however, I consider using both of them and merge the result is a better choice. Or if there already exists a method to use SymPy in sgae?</p>
https://ask.sagemath.org/question/64722/why-desolve-can-not-solve-an-ode-while-sympy-can/?comment=64743#post-id-64743"Merge the results" may be algorithmically hard. Choosing the "best" result even more so.Wed, 02 Nov 2022 10:52:48 +0100https://ask.sagemath.org/question/64722/why-desolve-can-not-solve-an-ode-while-sympy-can/?comment=64743#post-id-64743Comment by tolga for <p>For example, in sage, when I call:</p>
<pre><code>x=var('x')
f=function('f')(x)
desolve(f.diff(x)^2+1,f)
</code></pre>
<p>It will return:</p>
<pre><code>NotImplementedError: Maxima was unable to solve this ODE. Consider to set option contrib_ode to True.
</code></pre>
<p>However, with SymPy, when I call:</p>
<pre><code>x=symbols('x')
f=symbols('f',cls=Function)
dsolve(f(x).diff(x)**2+1,f(x))
</code></pre>
<p>It will return the exact result:</p>
<pre><code>[Eq(f(x), C1 - I*x), Eq(f(x), C1 + I*x)]
</code></pre>
<p>I know maybe it because sage use Maxima in desolve but not SymPy, however, I consider using both of them and merge the result is a better choice. Or if there already exists a method to use SymPy in sgae?</p>
https://ask.sagemath.org/question/64722/why-desolve-can-not-solve-an-ode-while-sympy-can/?comment=64726#post-id-64726`desolve(f.diff(x)^2+1,f,contrib_ode=True)` finds `[-I*x - f(x) == _C]`Tue, 01 Nov 2022 17:31:09 +0100https://ask.sagemath.org/question/64722/why-desolve-can-not-solve-an-ode-while-sympy-can/?comment=64726#post-id-64726Answer by Emmanuel Charpentier for <p>For example, in sage, when I call:</p>
<pre><code>x=var('x')
f=function('f')(x)
desolve(f.diff(x)^2+1,f)
</code></pre>
<p>It will return:</p>
<pre><code>NotImplementedError: Maxima was unable to solve this ODE. Consider to set option contrib_ode to True.
</code></pre>
<p>However, with SymPy, when I call:</p>
<pre><code>x=symbols('x')
f=symbols('f',cls=Function)
dsolve(f(x).diff(x)**2+1,f(x))
</code></pre>
<p>It will return the exact result:</p>
<pre><code>[Eq(f(x), C1 - I*x), Eq(f(x), C1 + I*x)]
</code></pre>
<p>I know maybe it because sage use Maxima in desolve but not SymPy, however, I consider using both of them and merge the result is a better choice. Or if there already exists a method to use SymPy in sgae?</p>
https://ask.sagemath.org/question/64722/why-desolve-can-not-solve-an-ode-while-sympy-can/?answer=64742#post-id-64742Try :
sage: f=function("f")
sage: import sympy
sage: Res = [u._sage_() for u in sympy.dsolve(*map(sympy.sympify, (f(x).diff(x)^2+1, f(x))))] ; Res
[f(x) == C1 - I*x, f(x) == C1 + I*x]
HTH,Wed, 02 Nov 2022 10:50:45 +0100https://ask.sagemath.org/question/64722/why-desolve-can-not-solve-an-ode-while-sympy-can/?answer=64742#post-id-64742