title: Sympy: solve a differential equation
body: <p>I want to find an elegant way of solving the following differential equation:</p>
  
  <pre><code>from sympy import *
  init_printing()
  
  M, phi, t, r = symbols('M phi t r')
  
  eq = Eq(-M * phi(t).diff(t), Rational(3, 2) * m * r**2 * phi(t).diff(t) * phi(t).diff(t,t))
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/0l4ID.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/0l4ID.png" alt="enter image description here"></a></p>
  
  <p>I assume that phi(t).diff(t) is not zero. Hence the left and right side are shortened. </p>
  
  <p>This is how I get to the solution:</p>
  
  <pre><code># I assume d/dt(phi(t)) != 0
  
  theta = symbols('theta')
  eq = eq.subs({phi(t).diff(t, 2): theta})  # remove the second derivative
  eq = eq.subs({phi(t).diff(t): 1})  # the first derivative is shortened
  eq = eq.subs({theta: phi(t).diff(t, 2)})  # get the second derivative back
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/vR9hi.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/vR9hi.png" alt="enter image description here"></a></p>
  
  <pre><code>dsolve(eq, phi(t))
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/WHGsj.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/WHGsj.png" alt="enter image description here"></a></p>
  
  <p>How do I solve this more elegantly?</p>