Ask Your Question

Revision history [back]

How about trying dsolve function from SymPy?

# expected behaviour as in 'plain' SymPy (optional)
preparser(False)

# import some libraries
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 its time, but it works! (nicely separating the cases $a=0$, $a\neq 0$).


Comment:

  • 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.

How about trying dsolve function from SymPy?

# expected behaviour as in 'plain' SymPy (optional)
preparser(False)

# import some libraries
sympy 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 its time, but it works! (nicely separating the cases $a=0$, $a\neq 0$).


Comment:

  • 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. names.

How about trying dsolve function from SymPy?

# expected behaviour as in 'plain' SymPy (optional)
preparser(False)

# import sympy 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 its time, but it works! (nicely separating the cases $a=0$, $a\neq 0$).


Comment:

  • 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.

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 its time, but it works! (nicely separating the cases $a=0$, $a\neq 0$).


Comment:

  • 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.

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 its time, but it works!


Comment:

  • 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 the first piece at $a=0$, which gives a constant as expected.

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 its time, but it works!


Comment:

  • 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?) strangely doesn't evaluate to a constant the first piece at $a=0$, which gives a constant as expected.for $a=0$.

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 its time, but it works!


Comment:

  • 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 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$.

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 its time, but it works!


Comment:

  • 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$.

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!


Comment: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$.