ASKSAGE: Sage Q&A Forum - Individual question feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Fri, 30 Dec 2016 15:46:58 -0600Any way to solve this differential equation?https://ask.sagemath.org/question/36122/any-way-to-solve-this-differential-equation/ sage: x(t)=function('x')(t)
sage: x
t |--> x(t)
sage: g(v,c)=1/sqrt(1-v^2/c^2)
sage: g
(v, c) |--> 1/sqrt(-v^2/c^2 + 1)
sage: var('a')
a
sage: ode = g(diff(x,t))*diff(x,t) == a*t
sage: ode
t |--> diff(x(t), t)/sqrt(-diff(x(t), t)^2/c^2 + 1) == a*t
sage: desolve(ode,x)
Traceback (most recent call last):
...
ValueError: Unable to determine independent variable, please specify.
sage: desolve(ode,[x,t])
Traceback (most recent call last):
...
NotImplementedError: Maxima was unable to solve this ODE. Consider to set option contrib_ode to True.
sage: desolve(ode,[x,t],contrib_ode=True)
Traceback (most recent call last):
...
NotImplementedError: Maxima was unable to solve this ODE.
I can solve it by hand.
Mathematica can solve it. But I would very much prefer to learn to use Sage because it's open source.
It looks like it is Maxima that cannot solve it. But is it possible to make Sage invoke any other open source program than Maxima? Or use some trick in defining the problem that would allow Maxima to solve it?
Thank you.Thu, 29 Dec 2016 13:15:36 -0600https://ask.sagemath.org/question/36122/any-way-to-solve-this-differential-equation/Answer by mforets for <pre><code>sage: x(t)=function('x')(t)
sage: x
t |--> x(t)
sage: g(v,c)=1/sqrt(1-v^2/c^2)
sage: g
(v, c) |--> 1/sqrt(-v^2/c^2 + 1)
sage: var('a')
a
sage: ode = g(diff(x,t))*diff(x,t) == a*t
sage: ode
t |--> diff(x(t), t)/sqrt(-diff(x(t), t)^2/c^2 + 1) == a*t
sage: desolve(ode,x)
Traceback (most recent call last):
...
ValueError: Unable to determine independent variable, please specify.
sage: desolve(ode,[x,t])
Traceback (most recent call last):
...
NotImplementedError: Maxima was unable to solve this ODE. Consider to set option contrib_ode to True.
sage: desolve(ode,[x,t],contrib_ode=True)
Traceback (most recent call last):
...
NotImplementedError: Maxima was unable to solve this ODE.
</code></pre>
<p>I can solve it by hand.</p>
<p>Mathematica can solve it. But I would very much prefer to learn to use Sage because it's open source.</p>
<p>It looks like it is Maxima that cannot solve it. But is it possible to make Sage invoke any other open source program than Maxima? Or use some trick in defining the problem that would allow Maxima to solve it?</p>
<p>Thank you.</p>
https://ask.sagemath.org/question/36122/any-way-to-solve-this-differential-equation/?answer=36128#post-id-36128How about trying [dsolve](http://docs.sympy.org/dev/_modules/sympy/solvers/ode.html#dsolve) function from SymPy?
# expected behaviour as in 'plain' SymPy (optional)
preparser(False)
# we need sympy's dsolve and other stuff
from sympy import Function, dsolve, Eq, Derivative, symbols, sqrt, sympify, pprint
# import some variable names
from sympy.abc import t, a, v, c
# instantiate abstract function
x = Function('x')
# define the ode
g = 1/sqrt(1-v**2/c**2)
ode = g.subs(v, Derivative(x(t), t))*Derivative(x(t), t) - a*t
In another cell,
%%time
dsolve(ode, x(t))
CPU times: user 1min 6s, sys: 226 ms, total: 1min 6s
Wall time: 1min 6s
Eq(x(t), Piecewise((C1 - a*c*t**2*sqrt(c**(-2))/2, Eq(a, 0)), (C1 - c*(a**2*t**2 + c**2)*sqrt(1/(a**2*t**2 + c**2))/a, True)))
Conclusion: it takes time, but it works!
---
*Notes:*
- `type(g)` should be a SymPy object (in this case, `<class 'sympy.core.power.Pow'>`). Unfortunately (in Sage v7.4), if we do something like `sympify(ode)`, it raises a `NotImplementedError: relation`. This is why I suggest to define the differential equation via `sympy.abc` variable names.
- the answer, given as a piecewise relational equation, separates the cases $a=0$ and $a\neq 0$ but strangely doesn't evaluate to a constant the first piece for $a=0$.Fri, 30 Dec 2016 15:46:58 -0600https://ask.sagemath.org/question/36122/any-way-to-solve-this-differential-equation/?answer=36128#post-id-36128