function [value,isterminal,direction] = exam8e(t,y,Z,state) % The suitcase is vertical if y(1) = 0. It has fallen over % if abs(y(1)) = pi/2. value = [y(1); abs(y(1))-pi/2]; % If vertical, terminate to reset y(2) and if fallen over, % terminate to end the problem. isterminal = [1; 1]; % All events are to be reported. direction = [0; 0];