Enable zero-crossing detection for fixed-step simulation
Option to use zero-crossing detection with fixed-step solver
Model Configuration Pane: Solver
When you enable zero-crossing detection, you can sometimes use a larger step size without sacrificing accuracy. When a discontinuity occurs in the simulation, the zero-crossing algorithm calculates the time at which the discontinuity occurred and adjusts the continuous state values accordingly. By adjusting the state values only around discontinuities, the solver can retain the accuracy of a smaller step size with overall fewer calculations.
Consider enabling this parameter when your model contains continuous states.
The zero-crossing algorithm for fixed-step solvers has a bounded computational cost. You can adjust the maximum number of calculations that occur due to using zero-crossing detection by modifying the Maximum number of bracketing iterations and Maximum number of zero-crossings per step parameters.
Enabling this parameter enables these parameters:
To enable this parameter, set the solver Type to
Fixed-step solver does not detect or locate zero crossings during simulation.
Fixed-step solver detects and locates zero crossings during simulation.
The table summarizes recommended values for this parameter based on considerations related to code generation.
|Safety precaution||No impact|
|Type: string | character vector|
Version HistoryIntroduced in R2022a
R2023b: Parameter values must match for all models to generate code for model reference hierarchy
When you generate code for a model reference hierarchy using Simulink® Coder™ or Embedded Coder®, the value of the Enable zero-crossing detection for fixed-step simulation parameter must be the same for the top model and all referenced models in the hierarchy.
R2023b: Software issues warning instead of error when parameter enabled for model that has no continuous states
Since fixed-step zero-crossing detection became available in R2022a, the software has issued an error when a model enables fixed-step zero-crossing detection but does not contain any continuous states. Starting in R2023b, the software issues a warning instead to support code generation for model reference hierarchies that use fixed-step zero-crossing detection and have one or more models that do not contain continuous states. This change also provides improved support for configuration references for both simulation and code generation workflows.
Fixed-step zero-crossing detection improves the accuracy of simulation results by compensating continuous state values when discontinuities occur during simulation. Enable fixed-step zero-crossing detection for a model that does not have continuous states only when required for code generation. Enabling fixed-step zero-crossing detection for simulation of a model that has no continuous states might affect simulation performance.