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(normdistanceThreshold < minDistance) minDistance = normdistanceThreshold;
> }
>
> System.out.println(minDistance);
>
> return minDistance;
> }
>
> The result of System.out.println(minDistance) does include a sign switch:
>
> 4.682173046832716E5
> 2.510576831160627E5
> 3.389511416873603E6
> 1.8327040230747826E5
> 1.8327040230747826E5
> 1.8327040230747826E5
>
> 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.8327040230747826E5, 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,
Luc
> 
> To unsubscribe, email: userunsubscribe@commons.apache.org
> For additional commands, email: userhelp@commons.apache.org
>
>
>

To unsubscribe, email: userunsubscribe@commons.apache.org
For additional commands, email: userhelp@commons.apache.org
