/** Carry out the Runge-Kutta 2nd order algorithm. **/
public class RungeKutta2nd
{
  /** Calculate as step in the Runge-Kutta 2nd order. **/
  public static void step (double t, double dt,
                    double [] var,
                    double [] vel,
                    Derivable func )  {

     double k1_var, k1_vel;
     double k2_var, k2_vel;

     for (int i=0; i < var.length; i++) {
       k1_var = vel[i] * dt;
       k1_vel = func.deriv (i,var[i],vel[i],t)*dt;

       k2_var =  (vel[i] + 0.5*k1_vel)*dt;
       k2_vel = func.deriv (i,
                            var[i] + 0.5*k1_var,
                            vel[i] + 0.5 * k1_vel,
                            t+0.5 * dt) * dt;

       var[i] = var[i] + k2_var;
       vel[i] = vel[i] + k2_vel;
    }

    t += dt;
  } // step

} // RungeKutta2nd
