sim
Simulate an MPC controller in closed loop with a linear plant
Description
Use the Model Predictive Control Toolbox™
sim
function to simulate, in discrete time, the closed-loop or open-loop
response of an MPC controller with constraints and weights that do not change at run time. The
MPC controller can be implicit or explicit, the controlled plant must be linear and
time-invariant, and you must specify the reference and disturbance signals in advance. By
default, the plant used in the simulation is the one in MPCobj.Model.Plant
,
but you can use a different plant model to assess the controller robustness to model
mismatch.
To run simulink models programmatically instead, see sim
(Simulink).
sim(
simulates the closed-loop response to the specified reference signal, mpcobj
,Ns
,r
)r
.
The simulation runs in discrete time, with sample time mpcobj.Ts
, for the
specified number of simulation steps, Ns
, and simulation results are
plotted. The plant model is the one specified in mpcobj.Model.Plant
(which is discretized or resampled, if needed). The MPC controller mpcobj
can be either a traditional MPC controller (mpc
) or explicit MPC
controller (explicitMPC
).
sim(___,
specifies
additional simulation options. This syntax allows you to alter the default simulation
options, such as initial states, input/output noise, and unmeasured disturbances, plant
mismatch, etc. It also allows you to simulate the plant in open loop. You can use
SimOptions
)SimOptions
with any of the previous input combinations.
[
suppresses plotting and instead returns:y
,t
,u
,xp
,xc
,SimOptions
] = sim(___)
the sequence of plant outputs
y
,the time sequence
t
(equally spaced bympcobj.Ts
),the manipulated variables
u
generated by the MPC controller,the sequence
xp
of states of the model of the plant used for simulation,the sequence
xmpc
of states of the MPC controller (provided by the state observer),and the simulation options object,
SimOptions
.