% Infectious disease model of E. Hairer, S.P. Norsett, and G. Wanner, % Solving Ordinary Differential Equations I, Springer-Verlag, Berlin, % 1987, p. 295. The maxima of the solution components are located by % finding where the first derivative vanishes. A maximum occurs when % the first derivative goes from a positive to a negative value, so we % tell DDE23 that we are interested only in zeros for which the function % decreases through zero. EXAM4E shows how this is done. options = ddeset('Events','exam4e'); sol = dde23('exam4f',[1, 10],[5; 0.1; 1],[0, 40],options); % Separate the various kinds of events and the solution values % then. ie = 1,2,3 according to which component of the solution % has a maximum. Local variables are used for clarity. xe = sol.xe; ye = sol.ye; ie = sol.ie; n1 = find(ie == 1); x1 = xe(n1); y1 = ye(1,n1); n2 = find(ie == 2); x2 = xe(n2); y2 = ye(2,n2); n3 = find(ie == 3); x3 = xe(n3); y3 = ye(3,n3); plot(sol.x,sol.y,'k',x1,y1,'rs',x2,y2,'rs',x3,y3,'rs') title('Figure 4. Infectious disease model from Hairer et al.') xlabel('Maxima are indicated by red squares.')