code: def rk4(derivs, y0, t):
      """
      Integrate 1-D or N-D system of ODEs using 4-th order Runge-Kutta.
  
      Example for 2D system:
  
          >>> def derivs(x):
          ...     d1 =  x[0] + 2*x[1]
          ...     d2 =  -3*x[0] + 4*x[1]
          ...     return d1, d2
  
          >>> dt = 0.0005
          >>> t = np.arange(0.0, 2.0, dt)
          >>> y0 = (1,2)
          >>> yout = rk4(derivs, y0, t)
  
      Args:
          derivs: the derivative of the system and has the signature ``dy = derivs(yi)``
          y0: initial state vector
          t: sample times
  
      Returns:
          yout: Runge-Kutta approximation of the ODE
      """
  
      try:
          Ny = len(y0)
      except TypeError:
          yout = np.zeros((len(t),), np.float_)
      else:
          yout = np.zeros((len(t), Ny), np.float_)
  
      yout[0] = y0
  
      for i in np.arange(len(t) - 1):
          this = t[i]
          dt = t[i + 1] - this
          dt2 = dt / 2.0
          y0 = yout[i]
  
          k1 = np.asarray(derivs(y0))
          k2 = np.asarray(derivs(y0 + dt2 * k1))
          k3 = np.asarray(derivs(y0 + dt2 * k2))
          k4 = np.asarray(derivs(y0 + dt * k3))
          yout[i + 1] = y0 + dt / 6.0 * (k1 + 2 * k2 + 2 * k3 + k4)
      # We only care about the final timestep and we cleave off action value which will be zero
      return yout[-1][:4]
  
file_path: gym/gym/envs/classic_control/acrobot.py
imports: from typing import Optional
  import numpy
  from numpy import cos, pi, sin
  from gym import core, logger, spaces
  from gym.error import DependencyNotInstalled
  from gym.envs.classic_control import utils
label_desc: Use image node_id 3 for calling a global function with example usage: rk4(derivs, y0, t) and returns: yout