Using Simulink    

The Solver Pane

The Solver pane appears when you first choose Parameters from the Simulation menu or when you select the Solver tab.

The Solver pane allows you to:

Simulation Time

You can change the start time and stop time for the simulation by entering new values in the Start time and Stop time fields. The default start time is 0.0 seconds and the default stop time is 10.0 seconds.

Simulation time and actual clock time are not the same. For example, running a simulation for 10 seconds will usually not take 10 seconds. The amount of time it takes to run a simulation depends on many factors, including the model's complexity, the solver's step sizes, and the computer's clock speed.

Solvers

Simulation of Simulink models involves the numerical integration of sets of ordinary differential equations (ODEs). Simulink provides a number of solvers for the simulation of such equations. Because of the diversity of dynamic system behavior, some solvers may be more efficient than others at solving a particular problem. To obtain accurate and fast results, take care when choosing the solver and setting parameters.

You can choose between variable-step and fixed-step solvers. Variable-step solvers can modify their step sizes during the simulation. They provide error control and zero crossing detection. Fixed-step solvers take the same step size during the simulation. They provide no error control and do not locate zero crossings. For a thorough discussion of solvers, see the MATLAB documentation.

Default solvers.   If you do not choose a solver, Simulink chooses one based on whether your model has states:

Variable-step solvers.   You can choose these variable-step solvers: ode45, ode23, ode113, ode15s, ode23s, and discrete. The default is ode45 for systems with states, or discrete for systems with no states:

Fixed-step solvers.   You can choose these fixed-step solvers: ode5, ode4, ode3, ode2, ode1, and discrete:

If you think your simulation may be providing unsatisfactory results, see Improving Simulation Performance and Accuracy.

Solver Options

The default solver parameters provide accurate and efficient results for most problems. In some cases, however, tuning the parameters can improve performance. (For more information about tuning these parameters, see Improving Simulation Performance and Accuracy). You can tune the selected solver by changing parameter values on the Solver pane.

Step Sizes

For variable-step solvers, you can set the maximum and suggested initial step size parameters. By default, these parameters are automatically determined, indicated by the value auto.

For fixed-step solvers, you can set the fixed step size. The default is also auto.

Maximum step size.   The Max step size parameter controls the largest time step the solver can take. The default is determined from the start and stop times.

Generally, the default maximum step size is sufficient. If you are concerned about the solver missing significant behavior, change the parameter to prevent the solver from taking too large a step. If the time span of the simulation is very long, the default step size may be too large for the solver to find the solution. Also, if your model contains periodic or nearly periodic behavior and you know the period, set the maximum step size to some fraction (such as 1/4) of that period.

In general, for more output points, change the refine factor, not the maximum step size. For more information, see Refine output.

Initial step size.   By default, the solvers select an initial step size by examining the derivatives of the states at the start time. If the first step size is too large, the solver may step over important behavior. The initial step size parameter is a suggested first step size. The solver tries this step size but reduces it if error criteria are not satisfied.

Minimum step size.   Specifies the smallest time step the solver can take. If the solver needs to take a smaller step to meet error tolerances, it issues a warning indicating the current effective relative tolerance. This parameter can be either a real number greater than zero or a two-element vector where the first element is the minimum step size and the second element is the maximum number of minimum step size warnings to be issued before issuing an error. Setting the second element to zero results in an error the first time the solver must take a step smaller than the specified minimum. This is equivalent to changing the minimum step size violation diagnostic to error on the Diagnostics panel. Setting the second element to -1 results in an unlimited number of warnings. This is also the default if the input is a scalar. The default values for this parameter are a minimum step size on the order of machine precision and an unlimited number of warnings.

Error Tolerances

The solvers use standard local error control techniques to monitor the error at each time step. During each time step, the solvers compute the state values at the end of the step and also determine the local error, the estimated error of these state values. They then compare the local error to the acceptable error, which is a function of the relative tolerance (rtol) and absolute tolerance (atol). If the error is greater than the acceptable error for any state, the solver reduces the step size and tries again:

The error for the ith state, ei, is required to satisfy

The following figure shows a plot of a state and the regions in which the acceptable error is determined by the relative tolerance and the absolute tolerance.

If you specify auto (the default), Simulink sets the absolute tolerance for each state initially to 1e-6. As the simulation progresses, Simulink resets the absolute tolerance for each state to the maximum value that the state has assumed thus far times the relative tolerance for that state. Thus, if a state goes from 0 to 1 and reltol is 1e-3, then by the end of the simulation the abstol is set to 1e-3 also. If a state goes from 0 to 1000, then the abstol is set to 1.

If the computed setting is not suitable, you can determine an appropriate setting yourself. You might have to run a simulation more than once to determine an appropriate value for the absolute tolerance. If the magnitudes of the states vary widely, it might be appropriate to specify different absolute tolerance values for different states. You can do this on the Integrator block's dialog box.

The Maximum Order for ode15s

The ode15s solver is based on NDF formulas of order one through five. Although the higher order formulas are more accurate, they are less stable. If your model is stiff and requires more stability, reduce the maximum order to 2 (the highest order for which the NDF formula is A-stable). When you choose the ode15s solver, the dialog box displays this parameter.

As an alternative, you might try using the ode23s solver, which is a fixed-step, lower order (and A-stable) solver.

Multitasking Options

If you select a fixed-step solver, the Solver pane of the Simulation Parameters dialog box displays a Mode options list. The list allows you to select one of the following simulation modes.

MultiTasking.   This mode issues an error if it detects an illegal sample rate transition between blocks, that is, a direct connection between blocks operating at different sample rates. In real-time multitasking systems, illegal sample rate transitions between tasks can result in a task's output not being available when needed by another task. By checking for such transitions, multitasking mode helps you to create valid models of real-world multitasking systems, where sections of your model represent concurrent tasks.

Use rate transition blocks to eliminate illegal rate transitions from your model. Simulink provides two such blocks: Unit Delay (see Unit Delay) and Zero-Order Hold (see Zero-Order Hold). To eliminate an illegal slow-to-fast transition, insert a Unit Delay block running at the slow rate between the slow output port and the fast input port. To eliminate an illegal fast-to-slow transition, insert a Zero-Order Hold block running at the slow rate between the fast output port and the slow input port. For more information, see Chapter 7, "Models with Multiple Sample Rates," in the Real-Time Workshop Users Guide.

SingleTasking.   This mode does not check for sample rate transitions among blocks. This mode is useful when you are modeling a single-tasking system. In such systems, task synchronization is not an issue.

Auto.   This option causes Simulink to use single-tasking mode if all blocks operate at the same rate and multitasking mode if the model contains blocks operating at different rates.

Output Options

The Output options area of the dialog box enables you to control how much output the simulation generates. You can choose from three options:

Refine output.   The Refine output choice provides additional output points when the simulation output is too coarse. This parameter provides an integer number of output points between time steps; for example, a refine factor of 2 provides output midway between the time steps, as well as at the steps. The default refine factor is 1.

To get smoother output, it is much faster to change the refine factor instead of reducing the step size. When the refine factor is changed, the solvers generate additional points by evaluating a continuous extension formula at those points. Changing the refine factor does not change the steps used by the solver.

The refine factor applies to variable-step solvers and is most useful when using ode45. The ode45 solver is capable of taking large steps; when graphing simulation output, you may find that output from this solver is not sufficiently smooth. If this is the case, run the simulation again with a larger refine factor. A value of 4 should provide much smoother results.

Produce additional output.   The Produce additional output choice enables you to specify directly those additional times at which the solver generates output. When you select this option, Simulink displays an Ouput Times field on the Solver pane. Enter a MATLAB expression in this field that evaluates to an additional time or a vector of additional times. The additional output is produced using a continuous extension formula at the additional times. Unlike the refine factor, this option changes the simulation step size so that time steps coincide with the times that you have specified for additional output.

Produce specified output only.   The Produce specified output only choice provides simulation output only at the specified output times. This option changes the simulation step size so that time steps coincide with the times that you have specified for producing output. This choice is useful when comparing different simulations to ensure that the simulations produce output at the same times.

Comparing Output options.   A sample simulation generates output at these times.

Choosing Refine output and specifying a refine factor of 2 generates output at these times.

Choosing the Produce additional output option and specifying [0:10] generates output at these times

and perhaps at additional times, depending on the step-size chosen by the variable-step solver.

Choosing the Produce Specified Output Only option and specifying [0:10] generates output at these times.

In general, you should specify output points as integers times a fundamental step size, e.g.,

is more accurate than


 The Simulation Parameters Dialog Box The Workspace I/O Pane