title: How do I solve a second order differential equation in R?
body: <p>I am learning <strong><em>R</em></strong> to solve a second order differential equation(probably using deSolve package). Which I have written in python by writing it as two first order differential equations and is given below</p>
  
  <pre><code>import  numpy  as np
  import  matplotlib.pyplot  as plt
  from  scipy.integrate  import  odeint
  
  def  fun(X, t):
      y , dy , z = X
      M = np.sqrt (1./3. * (1/2. * dy **2 + 1./2.  * y **2))
      dz = (M*z) # dz/dt
      ddy =  -3.* M * dy -  y # ddy/dt
  
      return [dy ,ddy ,dz]
  
  y0 = 1
  
  dy0 =  -0.1
  
  z0 = 1.
  
  X0 = [y0, dy0, z0]
  
  M0 = np.sqrt (1./3. * (1./2. *  dy0 **2. + 1./2.*  y0 **2)) 
  
  t = np.linspace(0., 100., 10001.) # time spacing
  
  sol = odeint(fun, X0, t)
  
  y = sol[:, 0]
  
  dy = sol[:, 1]
  
  z = sol[:, 2]
  
  M = np.sqrt (1./3. * (1./2. *  dy**2. + 1./2.*  y **2)) 
  
  #Graph plotting
  plt.figure()
  plt.plot(t, y)
  plt.plot(t, z)
  plt.plot(t, M)
  plt.grid()
  plt.show()
  </code></pre>
  
  <p><strong><em>Python</em></strong> solve this problem easily, however for another similar but complicated problem python shows error. I have also tried ode(vode/bdf) in python but the problem is still there. Now, I would like to check how <strong><em>R</em></strong> work with the problem. So, I will be much obliged if someone please provide me an example(basically a code translation!) of how to solve this problem in <strong><em>R</em></strong> so that I can try the other one in <strong><em>R</em></strong> and also learn some <strong><em>R</em></strong>(I know that this may not be the ideal way to learn a language).</p>
  
  <p>I understand that this question may have little constructive value, but I am just a novice in <strong><em>R</em></strong>, so please bear with me!</p>