Skip to content
Tutorials Center
My learning

Topics

Lesson 17 of 36 Β· Continuous and Discrete Systems

Simulink Zero-Crossings and Hybrid Systems: Bouncing Ball Example

Learn how Simulink detects events with zero-crossing detection, which blocks create them, how a bouncing ball hybrid model works, what Zeno behavior is and how to tune related settings.

Smooth differential equations are the easy case. Real systems also have events: a ball hits the floor, a relay switches, a valve hits its end stop, a thermostat turns on. At an event, a variable or the equations themselves change abruptly. Systems that mix continuous dynamics with such discrete events are called hybrid systems. A variable-step solver handles them with zero-crossing detection, and understanding it explains many slow or strange simulations.

Simulink is not available on this site. We describe the product's behavior and settings, and the Python stand-ins implement event detection by hand on the classic bouncing ball.

What is a zero crossing?

A zero-crossing function is a signal inside a block that changes sign when an event happens. Examples:

  • Saturation: u - upper_limit and u - lower_limit; it crosses zero when the input hits a limit.
  • Switch: u2 - threshold.
  • Abs, Sign, MinMax, Relay, Dead Zone, Backlash, Compare To Constant.
  • Integrator with limits or reset.
  • Step (at the step time).
  • Hit Crossing block, whose only job is to detect when a signal crosses a value, in a chosen direction.

When a variable-step solver sees one of these functions change sign during a step, it does not just move on. It narrows down the time of the crossing (root finding inside the step), takes a step that ends exactly at the event, and restarts integration afterwards with the new situation. This keeps the discontinuity from corrupting the error estimate and gives accurate event times with large steps in the smooth parts.

A fixed-step solver cannot do this: an event is noticed only at the next step. The result is a time error of up to one step.

Zero-crossing detection

Watch Block signals change sign
Locate Search the step for the time
Restart Integrate from the event

Variable-step solvers only.

1 / 2

The bouncing ball

A ball dropped from height h0 falls with h'' = -g and bounces with a coefficient of restitution e (so after impact v+ = -e*v-). In Simulink:

  • Two Integrators compute velocity and height from -g.
  • The height integrator's initial condition is h0.
  • A Hit Crossing or a Relay-like logic detects h = 0 while moving down.
  • The velocity integrator is reset at the event (External reset: rising/falling), with initial condition source: external, set to -e*v.

The demo called "bouncing ball" in the Simulink documentation (an sldemo_bounce model) follows this structure. The velocity reset uses the Integrator's state port to avoid an algebraic loop, as described in Integrators and Differential Equations.

Zeno behavior

With e < 1 each bounce is lower and shorter. The bounce intervals form a geometric series, so infinitely many bounces occur in a finite time: after that the ball is at rest. A simulation that follows each bounce takes smaller and smaller steps and may stop with the message that the number of consecutive zero crossings exceeded the limit (default 1000). This is called Zeno behavior. Remedies: add a small threshold (stop bouncing when the velocity is tiny), model the contact with a spring-damper instead of an ideal impact, or increase the limit for investigation.

Event detection by hand

The stand-in finds the time of each bounce by solving the free-fall equation exactly, which is what a solver approximates by root finding.

Python Stand-in: bouncing ball events and Zeno behavior (Python)

Press Run (or Ctrl + Enter) to see the result here.

Program input Β· what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

The interval between bounces shrinks by the factor e each time and the bounces pile up at about t = 8.09 s (the printed Zeno time), even though there are infinitely many of them.

Python Stand-in: fixed step misses the event time (Python)

Press Run (or Ctrl + Enter) to see the result here.

Program input Β· what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

A variable-step solver with zero-crossing detection would report the event at the exact time (within tolerance) without a tiny step everywhere.

Settings

In Modeling > Model Settings > Solver > Zero-crossing options:

Setting Purpose
Zero-crossing control Use local settings (default), Enable all or Disable all
Algorithm Nonadaptive (default) or Adaptive (better for chattering signals)
Time tolerance How closely the event time must be located
Signal threshold Treat a signal near zero as zero
Number of consecutive zero crossings allowed Limit that triggers the Zeno warning (default 1000)

Individual blocks (Switch, Saturation, Abs...) have Enable zero-crossing detection in their dialog. Turning it off can speed up a model where the event does not need exact timing, at the cost of accuracy near the switching instants.

Debugging slow hybrid models

  1. Look at the Solver Profiler (Debug > Performance Advisor > Solver Profiler) to see where steps are small and which blocks cause zero crossings.
  2. Replace abs, sign or hard switches in non-critical paths with smooth approximations (tanh) if exactness is unimportant.
  3. Avoid chattering relays: add hysteresis (switch-on and switch-off points) with a Relay block.
  4. Check that the model does not trigger a crossing every step because of numerical noise near zero.

For a model that must run on a fixed-step solver, you can still detect events: increase the sample rate near the expected event, interpolate the event time in your own logic, or use discrete-time logic throughout.

Check your understanding

Quick check Β· 4 questions

of 4 answered You scored / 4 Β· perfect!

  1. 1. What does a variable-step solver do when it detects a zero crossing within a step?

    It narrows down the event time inside the step and restarts integration after it.
  2. 2. Which block is designed only to detect that a signal crosses a value?

    The Hit Crossing block outputs an event when its input crosses a given offset.
  3. 3. What is Zeno behavior?

    Bounces with a geometric time decrease accumulate at a finite time.
  4. 4. Which block feature prevents relay chattering?

    Hysteresis requires the signal to move past a margin before switching back.

Summary

  • Events such as bounces, saturation and switching create discontinuities; hybrid systems mix them with continuous dynamics.
  • Variable-step solvers use zero-crossing functions from blocks to find event times accurately.
  • Ideal impacts with restitution below one lead to Zeno behavior; model contact differently or stop below a threshold.
  • Tune zero-crossing options, use hysteresis, and check the Solver Profiler for slow models.

Next: Delays, Lookup Tables and Nonlinear Blocks