Ask Your Question
2

Any way to solve this differential equation?

asked 2016-12-29 20:15:36 +0200

omoplata gravatar image
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.

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2016-12-30 22:46:58 +0200

mforets gravatar image

updated 2016-12-30 23:24:29 +0200

How about trying 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$.
edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2016-12-29 20:15:36 +0200

Seen: 1,772 times

Last updated: Dec 30 '16