Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

I'm using NDSolve to integrate a system of ODEs, and EventLocator to stop the integration when it leaves a certain region in phase space. This works perfectly as it should.

However, I've also added in another couple of events to Sow some bits of data (e.g, the locations of extrema of some variable). Almost all the time, this works perfectly as well. However, occasionally, both sorts of event occur simultaneously (or in the same integration step). In this case, it seems that only one of the event actions is evaluated. In particular, the integration isn't stopped when it should be.

The documentation doesn't seem to mention this situation at all, so it's hard to know if this is a bug, or whether there's a good way round it. Can anyone throw some light on this?

Thanks!

Schematic form of the code:

NDSolve[
    {ODEs for r and v}, {r, v}, {s, s0, \[Infinity]},                      
    Method -> {"EventLocator",  "Event" :> {edgeOfPhaseSpace,anotherEvent},
       "EventAction" :> {Throw[{something;}, "StopIntegration"],
                         doSomething;}}
]

EDIT: The actual code I'm interested in is pretty complicated, with lots of spurious detail, so I've made a simpler model which illustrates concretely what I'm on about:

solution[theta_] := Module[{sol, , tf, tx = 0},
  sol = First@NDSolve[
     {x''[t] == 0, y''[t] == -1, x[0] == 0, y[0] == 0, 
      x'[0] == Cos[theta], y'[0] == Sin[theta]}, {x, y}, {t, 
      0, \[Infinity]},
     Method -> {"EventLocator", "Event" :> {y[t], x[t] - 1/2},
       "EventAction" :> {Throw[tf = t;, "StopIntegration"], tx = t;}
       }, MaxStepSize -> 0.1];
  sol~Join~{stopTime -> tf, xTime -> tx}]

This solves for a particle moving under gravity, sent at an angle theta, and stops the integration when the particle hits y=0 again. It also returns data about the time when the particle hits x=1/2.

It works as expected most of the time. The exception is when the particle hits x=1/2 before it hits y=0, but in the same time step (e.g. theta=1.308). In this case the integration doesn't get stopped, but runs until max steps is reached.

share|improve this question
    
The example here shows what you might do with two events. –  J. M. Aug 7 '12 at 13:44
3  
Would it be possible to see the code that shows this behavior? –  user21 Aug 7 '12 at 14:20
    
@ruebenko I've added some example code which shows the sort of behaviour I'm asking about. –  Holographer Aug 8 '12 at 12:26
1  
I can not reproduce this, I tested on Linux-86-64, V8.0.4. What version and OS do you have? –  user21 Aug 8 '12 at 13:43
    
@ruebenko I've been running it on x86-64, V.7.0.1. I just tested the same code on V.8.0.1, and it seems to work fine! So presumably this was a bug that was fixed with V8. –  Holographer Aug 8 '12 at 13:59
add comment

1 Answer 1

up vote 1 down vote accepted

Seems to have been a bug in V7 but is fixed in V8.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.