Main Content

Zero-crossing control

Option to control how zero-crossing detection is enabled in the model

Model Configuration Pane: Solver

Description

The Zero-crossing control parameter specifies whether zero-crossing detection is enabled globally or locally in the model. With zero-crossing detection enabled, each time a discontinuity, or zero-crossing, is detected in simulation, the solver determines the time at which the zero crossing occurred and uses this information to adjust the values of continuous states in the model.

For most models, enabling zero-crossing detection speeds up simulation by allowing the solver to take larger time steps while maintaining computational accuracy.

  • When you enable zero-crossing detection for a variable-step solver, the ability to compensate state values based on the location of the discontinuity prevents the solver from taking many small time steps near that time.

  • When you enable zero-crossing detection for a fixed-step solver, you can use a larger fixed time step without sacrificing accuracy in models that have continuous states.

When you configure a referenced model to use a local solver, the Zero-crossing control parameter of the referenced model specifies whether zero-crossing detection is enabled globally or locally in the referenced model. (since R2025a)

Dependencies

This parameter is always enabled when you set the solver Type to Variable-step.

To enable this parameter when you set the solver Type to Fixed-step, select Enable zero-crossing detection for fixed-step simulation.

When you use a variable-step solver, setting Zero-crossing control to either Use local settings or Enable all enables these parameters:

Settings

Use local settings (default) | Enable all | Disable all
Use local settings

When you select this option, you enable or disable zero-crossing detection for each block in your model that registers zero crossings using the block parameters.

Each block reference page indicates whether that block supports zero-crossing detection. To enable or disable the parameter that specifies whether zero-crossing detection is enabled for a block, double-click the block to open the Block Parameters dialog box or select the block and press Ctrl+Shift+I to open the Property Inspector. On macOS, press command+option+O instead.

Enable all

This option enables zero-crossing detection for all blocks in the model that register zero crossings regardless of the parameter setting on each block.

Disable all

This option disables zero-crossing detection for all blocks in the model that register zero crossings regardless of the parameter setting on each block.

This option also disables zero-crossing detection in the referenced models that simulate in normal mode without local solvers. When zero-crossing detection is disabled for one instance of a referenced model in normal mode, zero-crossing detection is also disabled for the other instances of that model in normal mode, regardless of whether the other instances are controlled by a local solver.

Tips

For models that have large dynamic changes, disabling zero-crossing detection can speed up the simulation but can also decrease the accuracy of simulation results. For more information, see Zero-Crossing Detection.

Programmatic Use

Parameter: ZeroCrossControl
Type: string | character vector
Value: "UseLocalSettings" | "EnableAll" | "DisableAll"
Default: "UseLocalSettings"

Version History

Introduced before R2006a