function [value,isterminal,direction] = event0(t,x) theta=x(1); theta1=pi/6; value = theta-theta1; isterminal = 1; direction = 1; % If isterminal vector is set to 1, integration will halt % when a zero-crossing is detected. % The elements of the direction vector are -1, 1, or 0, % specifying that the corresponding event must be decreasing, % increasing, or that any crossing is to be detected % Events ? The function is of the form % [value,isterminal,direction] = events(t,y) % value, isterminal, and direction are vectors for which the ith element corresponds to the ith event function: % value(i) is the value of the ith event function. % isterminal(i) = 1 if the integration is to terminate at a zero of this event function, otherwise, 0. % direction(i) = 0 if all zeros are to be located (the default), +1 if only zeros where the event function is increasing, and -1 if only zeros where the event function is decreasing. % If you specify an events function and events are detected, the solver returns three additional outputs: