# [math] ode event handler Classic List Threaded 3 messages Open this post in threaded view
|

## [math] ode event handler

 Hi there, I'm new to Java and working on a project to integrate some ODEs. I'm having issues knowing how to work with the event handler. My ODE class looks like: public class DipoleODEimplements FirstOrderDifferentialEquations {      public int getDimension() {          return 6; }      public void computeDerivatives(double t, double[] y, double[] yDot) {          double r = y; double r2 = r * r; double r3 = r2 * r; double r4 = r3 * r; double theta = y; double phi = y; double sin_phi = Math.sin(phi); double cos_phi = Math.cos(phi); double pr = y; double ptheta = y; double ptheta2 = ptheta * ptheta; double pphi = y; double cos2 = Math.cos(phi -2 * theta); double sin2 = Math.sin(phi -2 * theta); yDot = pr; yDot = ptheta / r2; yDot =10 * pphi; yDot = ptheta2 / r3 - (cos_phi +3 * cos2) / (4 * r4); yDot = sin2 / (2 * r3); yDot = -(sin_phi +3 * sin2) / (12 * r3); } } When the y value gets below 1.0, I'd like to change the y value and the continue the integration. Basically I'm looking for a ball to bounce off another one. The integration gets stuck though and I can't seem to get things bouncing. Here's my event handler, too: EventHandler handler =new EventHandler() {      @Override public void init(double t0, double[] y0, double t) {      }      @Override public double g(double t, double[] y) {          return y -1.0; }      @Override public ActioneventOccurred(double t, double[] y, boolean increasing) {          return Action.RESET_STATE; }      @Override public void resetState(double t, double[] y) {          y *= -1.0; } }; And adding it to the integrator: dp853.addEventHandler(handler, 50.0, 1e-6, 100); Thanks for the help, -- Bo Johnson (801) 503-2043