function [value,isterminal,direction]=ex4_event(t,u,dummy)
% [value,isterminal,direction]=ex4_event(t,u,dummy)
% t is time
% u is solution vector
% dummy is a placeholder so ex4_event has same number of
% input arguments as ex4_ode
% isterminal=1/0 tells integrator to quit/not quit at value=0
% direction=-1 event occurs when value=0 in negative direction
% direction= 0 event occurs whenever value=0
% direction=+1 event occurs when value=0 in positive direction
% value is the value of this function (=0 at critical pt)
% in this case, looking for first peak
isterminal=1;
direction=-1; %peak: derivative decreases to zero
value= u(2) ; % Event is that derivative is zero