Processing math: 100%
Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

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, a0).


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.
click to hide/show revision 2
No.2 Revision

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, a0).


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.
click to hide/show revision 3
No.3 Revision

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, a0).


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.
click to hide/show revision 4
No.4 Revision

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, a0).


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.
click to hide/show revision 5
No.5 Revision

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 a0 but (strangely?) doesn't evaluate the first piece at a=0, which gives a constant as expected.
click to hide/show revision 6
No.6 Revision

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 a0 but (strangely?) strangely doesn't evaluate to a constant the first piece at a=0, which gives a constant as expected.for a=0.
click to hide/show revision 7
No.7 Revision

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 a0 but strangely doesn't evaluate to a constant the first piece for a=0.
click to hide/show revision 8
No.8 Revision

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 a0 but strangely doesn't evaluate to a constant the first piece for a=0.
click to hide/show revision 9
No.9 Revision

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 a0 but strangely doesn't evaluate to a constant the first piece for a=0.