function [xdot,isterminal,direction]= tennis1p2(t,x,flag)
global g alpha w etha
if nargin < 3 | isempty(flag) % normal output
   v= sqrt(x(3)^2+x(4)^2);
   Cd=(0.508+1/(22.503+4.196*(v/w)^0.4))*alpha*v;
   Cm=etha*w/(2.022*w+0.981*v)*alpha*v;
   xdot = [x(3), x(4), ...
           -Cd*x(3)+Cm*x(4), -g-Cd*x(4)-Cm*x(3)]';
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

