function [xdot,isterminal,direction]= tennis0p2(t,x,flag)
global g alpha
if nargin < 3 | isempty(flag) % normal output
   v= sqrt(x(3)^2+x(4)^2);
   xdot = [x(3), x(4), ...
           -alpha*0.508*x(3)*v, -g-alpha*0.508*x(4)*v]';
else
   switch(flag)
   case 'events'  % at ||h||=0 there is a singularity
      xdot= x(2);
      isterminal= 1;
      direction= -1;
   otherwise
      error(['Unknown flag ''' flag '''.']);
   end
end

