Jörg Neulist
Jörg Neulist

Reputation: 143

Solving ODEs with SymPy

I've just started trying out SymPy. Unfortunately, I am already stumped. Behold this:

from sympy import *
t, G, M = symbols('t G M', real = True)
x = Function('x')
y = Function('y')
print(Eq(Derivative(x, t, 2),  G * M * x(t) / (x(t) * x(t) + y(t) * y(t))**1.5))

...it simply prints False. The documentation says that this means the relationship can be proven to be false. I know that I can prevent evaluation by using evaluation = False, but eventually I want to solve my system of differential equations, and then this assumption will come into play again.

So, can anyone see what I did wrong here?

Addendum:

What I am trying to do is play around with the two-body-problem and orbital mechanics. With the gravitational constant G and the mass of the primary M at the origin, this and the symmetric equation for y(t) describe the gravitational acceleration on the secondary.

The solution, Kepler tells us, should be an ellipse for reasonable starting conditions.

Upvotes: 2

Views: 155

Answers (1)

Jörg Neulist
Jörg Neulist

Reputation: 143

I found it now, the solution is rather simple: SymPy needs to be told the x is a function of t, so

print(Eq(Derivative(x(t), t, 2),  G * M * x(t) / (x(t) * x(t) + y(t) * y(t))**1.5))

does the trick.

Upvotes: 2

Related Questions