# WhenEvent "StopIntegration" problem

The first example on the WhenEvent help page is

NDSolve[{y''[t] == -9.81, y == 5, y' == 0,
WhenEvent[y[t] == 0, y'[t] -> -0.95 y'[t]]}, y, {t, 0, 10}];


Say I want to stop the integration at the first bounce, I would put

NDSolve[{y''[t] == -9.81, y == 5, y' == 0,
WhenEvent[y[t] == 0,"StopIntegration"]}, y, {t, 0, 10}];


That, however, does not stop the integration (i.e. it goes on to t=10), neither does the condition y[t] < 0. What am I doing wrong?

Try this:

ySol = NDSolveValue[{y''[t] == -9.81, y == 5, y' == 0,
WhenEvent[y[t] == 0, {tMax = t, "StopIntegration"}]},
y, {t, 0, 10}];
Plot[ySol[x], {x, 0, tMax}]


And in tMax you'll get 1.00964, that's slightly larger than t when y[t] = 0. • great, that works! Aug 7, 2014 at 13:14
• @jacob You're code works too, I think you just want to plot to 10 and it will plot, because it's an InterpolationFunction and can plot outside the defined range. Aug 7, 2014 at 13:15
• ok thanks, that's what was confusing me Aug 7, 2014 at 13:28