title: Python scientific: interrupt differential equation solving with a condition
body: <p>I am currently solving a system of differential equation under python using <a href="http://docs.scipy.org/doc/scipy/reference/generated/scipy.integrate.odeint.html" rel="nofollow">odeint</a> to simulate charged particles in a field (the source comes from this <a href="http://packages.python.org/pytrap/" rel="nofollow">package</a>):</p>
  
  <pre><code>time = np.linspace(0, 5, 1000)
  
  def sm(x, t): 
      return np.array([x[1], eta*Ez0(x[0])])
  
  traj = odeint(sm,[0,1.], time)
  </code></pre>
  
  <p>It works fine but I would like to stop the calculation as soon as x[0] &lt; 0. For the moment I just block the evolution of the sytem:</p>
  
  <pre><code>def sm1(x, t): 
      if x[0] &lt; 0:
          return np.array([0, 0]) 
      else:
          return np.array([x[1], eta*Ez0(x[0])])
  
  traj = odeint(sm1,[0,1.],time)
  </code></pre>
  
  <p>but I gess there are better solutions. I've found <a href="http://mail.scipy.org/pipermail/scipy-user/2009-January/019522.html" rel="nofollow">this</a> but is seems to me that it fixes the number of steps, which is regrettable.
  Any suggestion appreciated.</p>