Main Content

Fixed-step size (fundamental sample time)

Step size for fixed-step solver

Model Configuration Pane: Solver

Description

When you use a fixed-step solver, the Fixed-step size (fundamental sample time) parameter specifies the size of the fixed step the solver takes during simulation.

When you configure a referenced model to use a local solver, the Fixed-step size (fundamental sample time) parameter of the referenced model specifies the step size for the local solver.

Dependencies

To enable this parameter:

Settings

auto | positive scalar double
auto

By default, the fixed step size is auto. The software determines the appropriate step size for the simulation according to these rules:

  • If the model includes periodic discrete sample times, the software chooses a step size equal to the greatest common divisor of the periodic sample times in the model. This step size ensures that the simulation takes a step for every sample time in the model.

  • If the model does not include periodic discrete sample times and specifies a finite sample time, the solver chooses a step size that divides the simulation into 50 equal steps.

    hmax=tstoptstart50

  • If the model does not include periodic sample times and specifies the stop time as Inf, the simulation uses a step size of 0.2.

  • If the model has no periodic sample times and uses Sine Wave or Signal Generator blocks, the software also considers the maximum frequency for the periodic signals generated by the source blocks. The step size is calculated to ensure that the step size is no smaller than one third of the minimum period of a periodic signal in the model, determined as the inverse of the maximum frequency Freqmax.

    For a simulation with a finite stop time, if one third of the minimum period is smaller than the step size calculated to divide the simulation into fifty even steps, the simulation uses the step size determined using the maximum frequency.

    hmax=min(tstoptstart50,(13)(1Freqmax))

    For a simulation with infinite stop time, if one third of the minimum period is smaller than 0.2, the simulation uses the step size determined using the maximum frequency.

    hmax=min(tstoptstart50,(13)(1Freqmax))

  • When the model is configured to start the simulation from an initial state specified as a Simulink.op.ModelOperatingPoint object, the software uses the fixed step size stored in the ModelOperatingPoint object.

When you allow the solver to determine the fixed step size, you can see the value that the solver determines several ways:

  • Once the model is compiled, the Solver information window and tooltip provide information about the solver and fixed step size. To see the solver information, click or pause on the solver information string in the lower-right corner of the Simulink® Editor.

    The Solver information window shows that the software chose the ode3 fixed-step solver and a fixed step size of 0.4 for this simulation.

    Several actions result in compiling the model, including updating the block diagram and simulating the model.

  • When you use the get_param function to get the value of the FixedStep parameter, the function returns 'auto' if the parameter value is specified as auto. Once the model is compiled, you can programmatically access the fixed step size chosen by the software by using the get_param function to get the value of the CompiledStepSize parameter.

    fixedStepSize = get_param("mdlName","CompiledStepSize");

  • When you return simulation results as a single simulation output object, the metadata in the Simulink.SimulationOutput object includes the fixed step size used in the simulation. The fixed step size is stored as part of the model information in the Simulink.SimulationMetadata object, in the solver information.

    simMetadata = getSimulationMetadata(out);
    simModelInfo = simMetadata.ModelInfo;
    simSolverInfo = simModelInfo.SolverInfo;
    simFixedStep = simSolverInfo.FixedStepSize;

positive scalar double

To use a value other than auto, specify the fixed step size in seconds as a double-precision value.

The specified step size must be less than or equal to the smallest discrete sample time in the model, and all discrete sample times in the model must be evenly divisible by the specified step size.

When you specify the step size of a local solver:

  • The local step size must be less than or equal to the communication step size, which determines the rate at which the parent and local solvers exchange data.

    Before R2024a: When the parent solver is a fixed-step solver, the local solver step size must be an integer multiple of the parent solver step size.

  • When the local step size is smaller than the communication step size, the communication step size must be evenly divisible by the local step size.

    For example, when the communication step size is 0.1 seconds, the local solver can be 0.1 seconds, 0.05 seconds, 0.025 seconds, and so on.

For more information, see Use Local Solvers in Referenced Models.

Recommended Settings

The table summarizes recommended values for this parameter based on considerations related to code generation.

ApplicationSetting
DebuggingNo impact
TraceabilityNo impact
EfficiencyNo impact
Safety precautionNo impact

Programmatic Use

Parameter: FixedStep
Type: string | character vector
Value: "auto" | positive scalar number
Default: "auto"
Parameter: CompiledStepSize
Type: string | character vector
Value: positive scalar number

Version History

Introduced before R2006a