Program: 57398
Project: 57398
Buggy source:
/** 
 * Integrate the differential equations and the variational equations up to the given time. <p>This method solves an Initial Value Problem (IVP) and also computes the derivatives of the solution with respect to initial state and parameters. This can be used as a basis to solve Boundary Value Problems (BVP).</p> <p>Since this method stores some internal state variables made available in its public interface during integration (  {@link #getCurrentSignedStepsize()}), it is <em>not</em> thread-safe.</p>
 * @param equations differential equations to integrate
 * @param t0 initial time
 * @param y0 initial value of the state vector at t0
 * @param dY0dP initial value of the state vector derivative with respect to theparameters at t0
 * @param t target time for the integration(can be set to a value smaller than <code>t0</code> for backward integration)
 * @param y placeholder where to put the state vector at each successfulstep (and hence at the end of integration), can be the same object as y0
 * @param dYdY0 placeholder where to put the state vector derivative with respectto the initial state (dy[i]/dy0[j] is in element array dYdY0[i][j]) at each successful step (and hence at the end of integration)
 * @param dYdP placeholder where to put the state vector derivative with respectto the parameters (dy[i]/dp[j] is in element array dYdP[i][j]) at each successful step (and hence at the end of integration)
 * @return stop time, will be the same as target time if integration reached itstarget, but may be different if some event handler stops it at some point.
 * @throws IntegratorException if the integrator cannot perform integration
 * @throws DerivativeException this exception is propagated to the caller ifthe underlying user function triggers one
 */
public double integrate(final double t0,final double[] y0,final double[][] dY0dP,final double t,final double[] y,final double[][] dYdY0,final double[][] dYdP) throws DerivativeException, IntegratorException {
  final int n=ode.getDimension();
  final int k=ode.getParametersDimension();
  checkDimension(n,y0);
  checkDimension(n,y);
  checkDimension(n,dYdY0);
  checkDimension(n,dYdY0[0]);
  if (k != 0) {
    checkDimension(n,dY0dP);
    checkDimension(k,dY0dP[0]);
    checkDimension(n,dYdP);
    checkDimension(k,dYdP[0]);
  }
  final double[] z=new double[n * (1 + n + k)];
  System.arraycopy(y0,0,z,0,n);
  for (int i=0; i < n; ++i) {
    z[i * (1 + n) + n]=1.0;
    System.arraycopy(dY0dP[i],0,z,n * (n + 1) + i * k,k);
  }
  evaluations=0;
  final double stopTime=integrator.integrate(new MappingWrapper(),t0,z,t,z);
  dispatchCompoundState(z,y,dYdY0,dYdP);
  return stopTime;
}

Fixed version (ground truth):
/** 
 * Integrate the differential equations and the variational equations up to the given time. <p>This method solves an Initial Value Problem (IVP) and also computes the derivatives of the solution with respect to initial state and parameters. This can be used as a basis to solve Boundary Value Problems (BVP).</p> <p>Since this method stores some internal state variables made available in its public interface during integration (  {@link #getCurrentSignedStepsize()}), it is <em>not</em> thread-safe.</p>
 * @param t0 initial time
 * @param y0 initial value of the state vector at t0
 * @param dY0dP initial value of the state vector derivative with respect to theparameters at t0
 * @param t target time for the integration(can be set to a value smaller than <code>t0</code> for backward integration)
 * @param y placeholder where to put the state vector at each successfulstep (and hence at the end of integration), can be the same object as y0
 * @param dYdY0 placeholder where to put the state vector derivative with respectto the initial state (dy[i]/dy0[j] is in element array dYdY0[i][j]) at each successful step (and hence at the end of integration)
 * @param dYdP placeholder where to put the state vector derivative with respectto the parameters (dy[i]/dp[j] is in element array dYdP[i][j]) at each successful step (and hence at the end of integration)
 * @return stop time, will be the same as target time if integration reached itstarget, but may be different if some event handler stops it at some point.
 * @throws IntegratorException if the integrator cannot perform integration
 * @throws DerivativeException this exception is propagated to the caller ifthe underlying user function triggers one
 */
public double integrate(final double t0,final double[] y0,final double[][] dY0dP,final double t,final double[] y,final double[][] dYdY0,final double[][] dYdP) throws DerivativeException, IntegratorException {
  final int n=ode.getDimension();
  final int k=ode.getParametersDimension();
  checkDimension(n,y0);
  checkDimension(n,y);
  checkDimension(n,dYdY0);
  checkDimension(n,dYdY0[0]);
  if (k != 0) {
    checkDimension(n,dY0dP);
    checkDimension(k,dY0dP[0]);
    checkDimension(n,dYdP);
    checkDimension(k,dYdP[0]);
  }
  final double[] z=new double[n * (1 + n + k)];
  System.arraycopy(y0,0,z,0,n);
  for (int i=0; i < n; ++i) {
    z[i * (1 + n) + n]=1.0;
    System.arraycopy(dY0dP[i],0,z,n * (n + 1) + i * k,k);
  }
  evaluations=0;
  final double stopTime=integrator.integrate(new MappingWrapper(),t0,z,t,z);
  dispatchCompoundState(z,y,dYdY0,dYdP);
  return stopTime;
}