commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Luc Maisonobe <>
Subject Re: [math] Problem with ODE discrete event
Date Mon, 24 Mar 2014 21:09:02 GMT
Hi Calle,

Le 24/03/2014 17:28, Calle Ekdahl a écrit :
> When using the event handler in the ODE solver I’m getting the error message/exception
> "Exception in thread "main" org.apache.commons.math3.exception.NoBracketingException:
function values at endpoints do not have different signs, endpoints: [692,555, 692,556], values:
[-0, -0]”
> What could be the cause of this? My g switching function:
>     public double g(double t, double[] y) {
>         for(int i=0; i < y.length/6; i++) {
>             double norm = Math.sqrt(y[6*i]*y[6*i]+y[6*i+1]*y[6*i+1]+y[6*i+2]*y[6*i+2]);
>             if(norm-distanceThreshold < minDistance) minDistance = norm-distanceThreshold;
>         }
>         System.out.println(minDistance);
>         return minDistance;
>     }
> The result of System.out.println(minDistance) does include a sign switch:
> 4.682173046832716E-5
> 2.510576831160627E-5
> 3.389511416873603E-6
> -1.8327040230747826E-5
> -1.8327040230747826E-5
> -1.8327040230747826E-5
> However instead of triggering eventOccurred it throws the exception.

I am not sure your function is well defined. If minDistance is a field
in the event defining class, then it keeps a track of past calls and
once it has reached a min value, it never comes back. This seems to be
what you get in the println, as the three last values are identical.

Here is the sequence I suppose is happenning.

At start, you have minDistance some positive value. Then as the
integrator progress in time, the distance reduces (say at times t1, t2,
t3 corresponding to your first points), until at some time it goes below
distanceThreshold and then becomes negative. Say it occurs at t4.

At this step, the integrator detects there was a sign change between t3
and t4, and launches a solver with the taks to find the zero between t3
and t4. However, since minDistance is already stored to be
-1.8327040230747826E-5, you never enter the if in your g function, and
the value reamins the same. Then the solver is lost, as its caller told
it there was a zero between t3 and t4, and in fact it finds the value is
always negative.

Your g function should be well behaved, and depend mainly in the t and y
parameters. Having it store and reuse states from one call to another
call is a source of problems.

Hope this helps,

> ---------------------------------------------------------------------
> To unsubscribe, e-mail:
> For additional commands, e-mail:

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message