Advanced tutorial: Bouncing ball Event handling in MATLABŪ

The MotionGenesis file   BouncingBallWithGroundDetection.txt
writes an event-aware MATLABŪ file for a free-flying soccer ball.

With minor modifications (shown below), it detects the instant
the ball first hits ground and/or simulates a bouncing ball.

 Or try a more difficult   coin-flip with bounce (dual event handling in MATLABŪ)

 BouncingBallNoGroundDetection.m (as produced by MotionGenesis)
 BouncingBallGroundDetectionStop.m (minor modification)
 BouncingBallGroundDetectionBounce.m (minor modification)

 To modify   BouncingBallNoGroundDetection.m   to   BouncingBallGroundDetectionStop.m to detect the first instant at which the ball strikes the ground, simply change the MATLABŪ lines from: ```% mdlDerivatives( t, VAR, uSimulink ); % UNCOMMENT FOR EVENT HANDLING % mdlOutputs( t, VAR, uSimulink ); % UNCOMMENT FOR EVENT HANDLING functionsToEvaluateForEvent = []; eventTerminatesIntegration1Otherwise0ToContinue = []; eventDirection_AscendingIs1_CrossingIs0_DescendingIsNegative1 = []; ``` to ```mdlDerivatives( t, VAR, uSimulink ); mdlOutputs( t, VAR, uSimulink ); functionsToEvaluateForEvent = [ y ]; eventTerminatesIntegration1Otherwise0ToContinue = [ 1 ]; eventDirection_AscendingIs1_CrossingIs0_DescendingIsNegative1 = [ -1 ]; ```

 To subsequently modify   BouncingBallGroundDetectionStop.m   to   BouncingBallGroundDetectionBounce.m so the ball bounces with a coefficient of restitution of 0.7, simply change the MATLABŪ lines from: ```eventTerminatesIntegration1Otherwise0ToContinue = [ 1 ]; % Put code here to modify how integration continues. ``` to ```eventTerminatesIntegration1Otherwise0ToContinue = [ 0 ]; yp = -0.7 * yp; ```