I found this http://www.um.es/fem/Download/Ejs/EjsManual_en_3.4_050914.pdf2.5.4 Events of a differential equationSometimes, when we are implementing the evolution of our simulation through thesolution of a system of differential equations, we want the computer to detect thata given condition which depends on the variables of the system has taken place,allowing us then to make some corrections to adjust the simulation.For instance, suppose that the falling body that we are simulating using equations(2.4) is an elastic ball that we have thrown against the floor. The numericalsolution of these equations doesn’t take into account, by itself, the fact that thecomputed solution will eventually take the ball to a position below ground, thatis, y(t) < 0. As the method for numerical solution advances at constants step oftime, it is very likely that the exact moment of the collision of the ball with thefloor doesn’t coincide with any of the solution steps of the algorithm, taking the ballto a, let’s put it this way, ‘illegal state’. Instead of this, we would have preferredthat the computer had detected the problem and had momentaneously stopped atthe precise instant of the collision, applying then the code necessary to simulate therebounding of the ball against the floor, and continuing the simulation from thesenew initial conditions. This is the archetypical example of what we call an event.More precisely, we define an event as the change of sign of a real-valued functionof the state variables (the variables that we differentiate) and of the independentvariable of an ODE. (Events caused only by the independent variable are traditionallycalled time events, while those caused by the other variables are called stateevents). To simplify the discussion that follows and, since actually all variables dependon the independent variable, we will denote by h(t) the function that changessign in the event.an event is specified by providing: (a) the function hwhich depends on the state, (b) the desired tolerance, and (c) the action to invokeat the event instant.Creating events for an ODENotice that the editor for differential equations includes a button labeled “Events”and a field that indicates that, by default, there are no events defined for thisequation. Clicking the button “Events” will bring in an independent window withan editor with a behavior similar to that found in other parts of the model, andwhich we can use to create as many pages of events for our differential equation aswe want.There exist, however, some differences. Observe in Figure 2.16 that a page forthe edition of events appears divided into two sections (besides the text field forcomments)In the upper section of this page we need to indicate how to detect the event. Forthis, we need to write the code that computes the function h(t) from the values ofthe state and the independent variable of our ODE. This code must end, necessarily,returning a value of type double. To help us remember this, the editor writes bydefault the next code (which, by the way, causes no event at all):return 1.0;In the “Tolerance” field on the upper right corner of this section we need to indicatethe value for the tolerance that we want for this event (this is the in the discussionabove).The lower section is used to tell the computer what to do when it detects (andthen precisely locates) an event. Recall that this action must solve, or at leastsimplify, the situation that triggered the event. In the upper-right corner of thissecond section we find a checkbox labeled “Stop at event”, currently activated, thattells the computer whether it should return from the solution of the ODE at theinstant of the event or not. Notice that, if checked, this causes the real incrementof the independent variable to be smaller that the one originally desired. But still,checking this option may be useful if you want to appreciate the exact moment ofthe event.We can use our example of the falling ball to construct a sample event. For this,edit the code of the upper section of the page so that it reads:return y;This indicates that the event will take place when the ball reaches the level of theground, y = 0. The default value for the tolerance is adequate. As action for theevent, write the code:vy = -vy;which simulates a totally elastic rebounding at the instant the event takes place.Leave the box “Stop at event” checked, so that the system visualizes the instant ofthe rebounding.