Main Content

Max step size

Maximum step size to allow in simulations that use variable-step solvers

Model Configuration Pane: Solver

Description

The Max step size parameter specifies the largest step size, in seconds, that a variable-step solver can take in simulation.

When you configure a referenced model to use a local solver, the Max step size parameter of the referenced model specifies the maximum step size for the local solver. (since R2025a)

Dependencies

To enable this parameter, set the solver Type to Variable-step.

Settings

auto (default) | scalar
auto

By default, the Max step size parameter value is auto, which indicates that the solver determines the maximum step size to use in the simulation. The solver analyzes the model and chooses a step size that satisfies several constraints, including:

  • The maximum step size must be less than or equal to all of these values:

    • The smallest discrete sample time in the model, if the model contains discrete sample times

    • One third of the period of the highest specified frequency in the model, if the model contains blocks that generate periodic signals, such as the Sine Wave block and the Signal Generator block

    • 0.2, if the stop time is Inf

  • The simulation must take at least 50 time steps.

    hmax=tstoptstart50

  • The stop time must be an integer multiple of the step size.

When the model is configured to start the simulation from an initial state specified as a Simulink.op.ModelOperatingPoint object and the Max step size parameter value is auto, the software uses the maximum step size stored in the ModelOperatingPoint object.

Tip

Selecting the Enable decoupled continuous integration parameter can speed up simulations by allowing the solver to determine a larger maximum step size when the Max step size parameter is set to auto.

scalar

Generally, the solver determines an appropriate maximum step size. Consider specifying the maximum step size when:

  • You simulate the model over a large time span. For long time spans, the step size the solver chooses might be too large to find the solution.

  • Your model contains periodic or nearly periodic behavior, and you know the period. Specify the maximum step size as a fraction of the period, such as 1/4.

  • You are concerned about the solver missing significant behavior when using the solver-determined maximum step size.

Examples

expand all

Open the model vdp.

mdl = "vdp";
open_system(mdl)

The model vdp.

To allow the software to select the solver to use for the model, specify the Type parameter as Fixed-step or Variable-step, and set the Solver parameter to auto. For this example, configure the software to select a variable-step solver for the model.

  1. To open the Configuration Parameters dialog box, on the Modeling tab, click Model Settings.

  2. On the Solver pane, set the solver Type to Variable-step and the Solver parameter to auto (Automatic solver selection).

  3. Click OK.

Alternatively, use the set_param function to set the parameter values programmatically.

set_param(mdl,"SolverType","Variable-step", ...
    "SolverName","VariableStepAuto")

Simulate the model. On the Simulation tab, click Run. Alternatively, use the sim function.

out = sim(mdl);

As part of initializing the simulation, the software analyzes the model to select the solver. The status bar on the bottom of the Simulink Editor indicates the selected solver on the right. For this model, the software selects the ode45 solver.

The right side of the status bar shows the selected solver as auto(ode45).

To view more information about the selected solver parameters, click the text in the status bar that indicates the selected solver. The Solver Information menu shows the selected solver and the selected value for the Max step size parameter. For this simulation, the solver uses a maximum step size of 0.4.

The pointer is on the text in the status bar that indicates the selected solver. The Solver information menu shows selected parameter values above three buttons.

If you want to lock down the solver selection and maximum step size, explicitly specify the solver parameter values. In the Solver information menu, click Accept suggested settings .

Alternatively, you can use the set_param function to specify the parameter values programmatically.

set_param(mdl,"SolverName","ode45","MaxStep","0.4")

After you explicitly specify the parameter values, the solver information in the status bar and Solver information menu no longer indicate that the parameter values are automatically selected.

The Solver information menu is opened above the right side of the status bar. The solver information in the status bar and Solver information menu no longer show auto() around the solver parameter values.

Programmatic Use

Parameter: MaxStep
Type: string | character vector
Value: numeric scalar
Default: "auto"

Version History

Introduced before R2006a