yDot[i] = k[i] * y[i];
}
}
};
ClassicalRungeKuttaIntegrator integrator = new ClassicalRungeKuttaIntegrator(60.0);
double[] y0 = new double[k.length];
for (int i = 0; i < y0.length; ++i) {
y0[i] = i + 1;
}
double[] y = new double[k.length];
double finalT = integrator.integrate(ode, t0, y0, tEvent, y);
Assert.assertEquals(tEvent, finalT, 5.0e-6);
for (int i = 0; i < y.length; ++i) {
Assert.assertEquals(y0[i] * FastMath.exp(k[i] * (finalT - t0)), y[i], 1.0e-9);
}
integrator.addEventHandler(new EventHandler() {
public void resetState(double t, double[] y) {
}
public double g(double t, double[] y) {
return t - tEvent;
}
public int eventOccurred(double t, double[] y, boolean increasing) {
Assert.assertEquals(tEvent, t, 5.0e-6);
return CONTINUE;
}
}, Double.POSITIVE_INFINITY, 1.0e-20, 100);
finalT = integrator.integrate(ode, t0, y0, tEvent + 120, y);
Assert.assertEquals(tEvent + 120, finalT, 5.0e-6);
for (int i = 0; i < y.length; ++i) {
Assert.assertEquals(y0[i] * FastMath.exp(k[i] * (finalT - t0)), y[i], 1.0e-9);
}