title: Finding zero values with odeint
body: <p>How can I find the point where the first derivative of my equation equals 0 using scipy.integrate.ode?</p>
  
  <p>I set up this function, which gets the answer, but I'm not sure about accuracy and it can't be the most efficient way to do this.</p>
  
  <p>Basically I am using this function to find the time a projectile with initial velocity stops moving. With systems of ODEs, is there a better way to solve for this answer? </p>
  
  <pre><code>import numpy as np
  from scipy import integrate
  
  def find_nearest(array,value):
      idx=(np.abs(array-value)).argmin()
      return array[idx], idx
  
  def deriv(x,t):
      # This function sets up the following relations
      # dx/dt = v , dv/dt = -(Cp/m)*(4+v^2)
      return np.array([ x[1], -(0.005/0.1) * (4+ (x[1]**2)) ])
  
  def findzero(start, stop, v0):
      time = np.linspace(start, stop, 100000)
      #xinit are initial vaules of equation
      xinit = np.array([0.0,v0]) 
      x = integrate.odeint(deriv,xinit,time)
      # find nearest velocity value nearest to 0
      value, num = find_nearest(x[:,1],0.0001)
      print 'closest value ',
      print value
      print 'reaches zero at time ',
      print time[num]
      return time[num]
  # from 0 to 20 seconds with initial velocity of 100 m/s
  b = findzero(0.0,20.0,100.0)
  </code></pre>