Getting Started Guide: Model Predictive Control Toolbox™
Getting Started Guide: Model Predictive Control Toolbox™
Alberto Bemporad
N. Lawrence Ricker
Manfred Morari
R2019b
How to Contact MathWorks
Phone: 508-647-7000
Introduction
1
Model Predictive Control Toolbox Product Description . . . . . . 1-2
Key Features . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-2
Acknowledgments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-3
Bibliography . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-4
Building Models
2
MPC Modeling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-2
Plant Model . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-2
Input Disturbance Model . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-4
Output Disturbance Model . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-5
Measurement Noise Model . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-6
v
CSTR Model . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-20
vi Contents
1
Introduction
Model Predictive Control Toolbox provides functions, an app, and Simulink® blocks for
designing and simulating model predictive controllers (MPCs). The toolbox lets you
specify plant and disturbance models, horizons, constraints, and weights. By running
closed-loop simulations, you can evaluate controller performance.
You can adjust the behavior of the controller by varying its weights and constraints at run
time. To control a nonlinear plant, you can implement adaptive and gain-scheduled MPCs.
For applications with fast sample rates, you can generate an explicit model predictive
controller from a regular controller or implement an approximate solution.
For rapid prototyping and embedded system implementation, the toolbox supports
automatic C-code and IEC 61131-3 Structured Text generation.
Key Features
• App for interactive design of MPC controllers
• Runtime adjustment of weights and constraints
• Adaptive and gain-scheduled MPCs for controlling systems with nonlinear dynamics
• Explicit MPC and approximate solution for guaranteed worst-case execution time
• Economic MPC with arbitrary nonlinear cost function and constraints
• Computationally efficient quadratic programming (QP) solver, and support for third-
party solvers
• Support for C-code generation (with Simulink Coder™) and IEC 61131-3 Structured
Text generation (with Simulink PLC Coder™)
1-2
Acknowledgments
Acknowledgments
MathWorks would like to acknowledge the following contributors to Model Predictive
Control Toolbox.
Alberto Bemporad
Professor of Control Systems, IMT Institute for Advanced Studies Lucca, Italy.
Research interests include model predictive control, hybrid systems, optimization
algorithms, and applications to automotive, aerospace, and energy systems. Fellow of
the IEEE®. Author of the Model Predictive Control Simulink library and commands.
N. Lawrence Ricker
Professor of Chemical Engineering, University of Washington, Seattle, USA. Research
interests include model predictive control and process optimization. Author of the
Model Predictive Control Simulink library and commands.
Manfred Morari
Professor at the Automatic Control Laboratory and former Head of Department of
Information Technology and Electrical Engineering, ETH Zurich, Switzerland.
Research interests include model predictive control, hybrid systems, and robust
control. Fellow of the IEEE, AIChE, and IFAC. Co-author of the first version of the
toolbox.
1-3
1 Introduction
Bibliography
[1] Allgower, F., and A. Zheng, Nonlinear Model Predictive Control, Springer-Verlag, 2000.
[2] Camacho, E. F., and C. Bordons, Model Predictive Control, Springer-Verlag, 1999.
[3] Kouvaritakis, B., and M. Cannon, Non-Linear Predictive Control: Theory & Practice,
IEE Publishing, 2001.
[4] Maciejowski, J. M., Predictive Control with Constraints, Pearson Education POD, 2002.
[5] Prett, D., and C. Garcia, Fundamental Process Control, Butterworths, 1988.
[6] Rossiter, J. A., Model-Based Predictive Control: A Practical Approach, CRC Press,
2003.
1-4
2
Building Models
MPC Modeling
Model predictive controllers use plant, disturbance, and noise models for prediction and
state estimation. The model structure used in an MPC controller appears in the following
illustration.
Plant Model
You can specify the plant model in one of the following linear-time-invariant (LTI) formats:
• Numeric LTI models — Transfer function (tf), state space (ss), zero-pole-gain (zpk)
• Identified models (requires System Identification Toolbox™) — idss, idtf, idproc,
and idpoly
The MPC controller performs all estimation and optimization calculations using a
discrete-time, delay-free, state-space system with dimensionless input and output
variables. Therefore, when you specify a plant model in the MPC controller, the software
performs the following, if needed:
2-2
MPC Modeling
1 Conversion to state space — The ss command converts the supplied model to an LTI
state-space model.
2 Discretization or resampling — If the model sample time differs from the MPC
controller sample time (defined in the Ts property), one of the following occurs:
xp k + 1 = Apxp k + BSiup k
−1 −1
yp k = So Cxp k + So DSiup k .
where Ap, B, C, and D are the constant zero-delay state-space matrices from step 3,
and:
2-3
2 Building Models
−1
Here, Cp = So C, Bpu, Bpv, and Bpd are the corresponding columns of BSi. Also, Dpu,
−1
Dpv, and Dpd are the corresponding columns of So DSi. Finally, u(k), v(k), and d(k) are
the dimensionless manipulated variables, measured disturbances, and unmeasured
input disturbances, respectively.
The MPC controller enforces the restriction of Dpu = 0, which means that the
controller does not allow direct feedthrough from any manipulated variable to any
plant output.
The input disturbance model is a key factor that influences the following controller
performance attributes:
You can provide the input disturbance model as an LTI state-space (ss), transfer function
(tf), or zero-pole-gain (zpk) object using setindist. The MPC controller converts the
input disturbance model to a discrete-time, delay-free, LTI state-space system using the
same steps used to convert the plant model on page 2-2. The result is:
where Aid, Bid, Cid, and Did are constant state-space matrices, and:
2-4
MPC Modeling
If you do not provide an input disturbance model, then the controller uses a default
model, which has integrators with dimensionless unity gain added to its outputs. An
integrator is added for each unmeasured input disturbance, unless doing so would cause
a violation of state observability. In this case, a static system with dimensionless unity
gain is used instead.
The getoutdist command provides access to the output disturbance model in use.
You can specify a custom output disturbance model as an LTI state-space (ss), transfer
function (tf), or zero-pole-gain (zpk) object using setoutdist. Using the same steps as
for the plant model on page 2-2, the MPC controller converts the specified output
disturbance model to a discrete-time, delay-free, LTI state-space system. The result is:
where Aod, Bod, Cod, and Dod are constant state-space matrices, and:
If you do not specify an output disturbance model, then the controller uses a default
model, which has integrators with dimensionless unity gain added to some or all of its
outputs. These integrators are added according to the following rules:
2-5
2 Building Models
• No disturbances are estimated, that is no integrators are added, for unmeasured plant
outputs.
• An integrator is added for each measured output in order of decreasing output weight.
• For time-varying weights, the sum of the absolute values over time is considered
for each output channel.
• For equal output weights, the order within the output vector is followed.
• For each measured output, an integrator is not added if doing so would cause a
violation of state observability. Instead, a gain with a value of zero is used instead.
If there is an input disturbance model, then the controller adds any default integrators to
that model before constructing the default output disturbance model.
Using the same steps as for the plant model on page 2-2, the MPC controller converts the
measurement noise model to a discrete-time, delay-free, LTI state-space system. The
result is:
xn k + 1 = Anxn k + Bnwn k
yn k = Cnxn k + Dnwn k .
Here, An, Bn, Cn, and Dn are constant state space matrices, and:
If you do not supply a noise model, the default is a unity static gain: nxn = 0, Dn is an nym-
by-nym identity matrix, and An, Bn, and Cn are empty.
2-6
See Also
Note If the minimum eigenvalue of DnDnT is less than 1x10–8, the MPC controller adds
1x10–4 to each diagonal element of Dn. This adjustment makes a successful default
Kalman gain calculation more likely.
See Also
More About
• “Controller State Estimation”
• “Adjust Disturbance and Noise Models”
2-7
2 Building Models
Signal Types
Inputs
The plant inputs are the independent variables affecting the plant. As shown in “MPC
Modeling” on page 2-2, there are three types:
Measured disturbances
The controller can't adjust them, but uses them for feedforward compensation.
Manipulated variables
Unmeasured disturbances
These are independent inputs of which the controller has no direct knowledge, and for
which it must compensate.
Outputs
The plant outputs are the dependent variables (outcomes) you wish to control or monitor.
As shown in “MPC Modeling” on page 2-2, there are two types:
Measured outputs
The controller uses these to estimate unmeasured quantities and as feedback on the
success of its adjustments.
Unmeasured outputs
The controller estimates these based on available measurements and the plant model. The
controller can also hold unmeasured outputs at setpoints or within constraint boundaries.
You must specify the input and output types when designing the controller. See “Input
and Output Types” on page 2-14 for more details.
2-8
See Also
See Also
More About
• “MPC Modeling” on page 2-2
2-9
2 Building Models
Y(s) s+2
= G(s) = 2 e−1.5s
U(s) s + s + 10
Transfer function:
s + 2
exp(-1.5*s) * ------------
s^2 + s + 10
Zero/Pole/Gain Models
Like the TF format, the zero/pole/gain (ZPK) format relates an input/output pair. The
difference is that the ZPK numerator and denominator polynomials are factored, as in
s + 0.45
G(s) = 2.5
(s + 0.3)(s + 0.1 + 0.7i)(s + 0.1 − 0.7i)
You define the ZPK model by specifying the zero(s), pole(s), and gain as in
2-10
Construct Linear Time Invariant Models
State-Space Models
The state-space format is convenient if your model is a set of LTI differential and
algebraic equations. For example, consider the following linearized model of a continuous
stirred-tank reactor (CSTR) involving an exothermic (heat-generating) reaction [1].
dC′ A
= a11C′ A + a12T′ + b11T′c + b12C′ Ai
dt
dT′
= a21C′ A + a22T′ + b21T′c + b22C′ Ai
dt
CSTR Schematic
dx
= Ax + Bu
dt
y = Cx + Du
where
2-11
2 Building Models
C′ A T′c T′
x= , u = , y =
T′ C′ Ai C′ A
The following code shows how to define such a model for some specific values of the aij
and bij constants:
A = [-0.0285 -0.0014
-0.0371 -0.1476];
B = [-0.0850 0.0238
0.0802 0.4462];
C = [0 1
1 0];
D = zeros(2,2);
CSTR = ss(A,B,C,D);
This defines a continuous-time state-space model. If you do not specify a sampling period,
a default sampling value of zero applies. You can also specify discrete-time state-space
models. You can specify delays in both continuous-time and discrete-time models.
Note In the CSTR example, the D matrix is zero and the output does not instantly
respond to change in the input. The Model Predictive Control Toolbox software prohibits
direct (instantaneous) feedthrough from a manipulated variable to an output. For
example, the CSTR model could include direct feedthrough from the unmeasured
disturbance, CAi, to either CA or T but direct feedthrough from Tc to either output would
violate this restriction. If the model had direct feedthrough from Tc, you can add a small
delay at this input to circumvent the problem.
The following code sets some of the CSTR model's optional properties:
2-12
Construct Linear Time Invariant Models
CSTR.InputName = {'T_c','C_A_i'};
CSTR.OutputName = {'T','C_A'};
CSTR.StateName = {'C_A','T'};
CSTR.InputGroup.MV = 1;
CSTR.InputGroup.UD = 2;
CSTR.OutputGroup.MO = 1;
CSTR.OutputGroup.UO = 2;
CSTR
The first three lines specify labels for the input, output and state variables. The next four
specify the signal type for each input and output. The designations MV, UD, MO, and UO
mean manipulated variable, unmeasured disturbance, measured output, and unmeasured
output. (See “Signal Types” on page 2-8 for definitions.) For example, the code specifies
that input 2 of model CSTR is an unmeasured disturbance. The last line causes the LTI
object to be displayed, generating the following lines in the MATLAB® Command Window:
A =
C_A T
C_A -0.0285 -0.0014
T -0.0371 -0.1476
B =
T_c C_Ai
C_A -0.085 0.0238
T 0.0802 0.4462
C =
C_A T
T 0 1
C_A 1 0
D =
T_c C_Ai
T 0 0
C_A 0 0
Input groups:
Name Channels
MV 1
UD 2
Output groups:
Name Channels
2-13
2 Building Models
MO 1
UO 2
Continuous-time model
The optional InputName and OutputName properties affect the model displays, as in the
above example. The software also uses the InputName and OutputName properties to
label plots and tables. In that context, the underscore character causes the next character
to be displayed as a subscript.
As mentioned in “Signal Types” on page 2-8, Model Predictive Control Toolbox software
supports three input types and two output types. In a Model Predictive Control Toolbox
design, designation of the input and output types determines the controller dimensions
and has other important consequences.
The resulting controller has four inputs (the three MOs and the MD) and two outputs (the
MVs). It includes feedforward compensation for the measured disturbance, and assumes
that you wanted to include the unmeasured disturbances and outputs as part of the
regulator design.
If you didn't want a particular signal to be treated as one of the above types, you could do
one of the following:
2-14
Construct Linear Time Invariant Models
Note By default, the software assumes that unspecified plant inputs are manipulated
variables, and unspecified outputs are measured. Thus, if you didn't specify signal
types in the above example, the controller would have four inputs (assuming all plant
outputs were measured) and five outputs (assuming all plant inputs were manipulated
variables).
For model CSTR, the default Model Predictive Control Toolbox assumptions are incorrect.
You must set its InputGroup and OutputGroup properties, as illustrated in the above
code, or modify the default settings when you load the model into MPC Designer.
CSTR = setmpcsignals(CSTR,'UD',2,'UO',2);
sets InputGroup and OutputGroup to the same values as in the previous example. The
CSTR display would then include the following lines:
Input groups:
Name Channels
Unmeasured 2
Manipulated 1
Output groups:
Name Channels
Unmeasured 2
Measured 1
2-15
2 Building Models
References
[1] Seborg, D. E., T. F. Edgar, and D. A. Mellichamp, Process Dynamics and Control, 2nd
Edition, Wiley, 2004, pp. 34–36 and 94–95.
See Also
setmpcsignals | ss | tf | zpk
More About
• “Specify Multi-Input Multi-Output Plants” on page 2-17
2-16
Specify Multi-Input Multi-Output Plants
Outputs y1 and y2 represent measured product purities. The controller manipulates the
inputs, u1 and u2, to hold each output at a specified setpoint. These inputs represent the
flow rates of reflux and reboiler steam, respectively. Input u3 is a measured feed flow rate
disturbance.
The model consists of six transfer functions, one for each input/output pair. Each transfer
function is the first-order-plus-delay form often used by process control engineers.
Specify the individual transfer functions for each input/output pair. For example, g12 is
the transfer function from input u1 to output y2.
Define the input and output signal names and specify the third input as a measured input
disturbance.
2-17
2 Building Models
DC
DC =
6.6
Bottoms Purity: exp(-7*s) * ----------
10.9 s + 1
-19.4
Bottoms Purity: exp(-3*s) * ----------
14.4 s + 1
4.9
Bottoms Purity: exp(-3.4*s) * ----------
13.2 s + 1
Input groups:
Name Channels
Measured 3
Manipulated 1,2
Output groups:
Name Channels
Measured 1,2
2-18
See Also
References
[1] Wood, R. K., and M. W. Berry, Chem. Eng. Sci., Vol. 28, pp. 1707, 1973.
See Also
setmpcsignals | ss | tf | zpk
Related Examples
• “Construct Linear Time Invariant Models” on page 2-10
2-19
2 Building Models
CSTR Model
The linearized model of a continuous stirred-tank reactor (CSTR) involving an exothermic
(heat-generating) reaction is represented by the following differential equations:
dC′ A
= a11C′ A + a12T′ + b11T′c + b12C′ Ai
dt
dT′
= a21C′ A + a22T′ + b21T′c + b22C′ Ai
dt
dx
= Ax + Bu
dt
y = Cx + Du
where
C′ A T′c T′
x= , u = , y =
T′ C′ Ai C′ A
2-20
CSTR Model
The following code shows how to define such a model for some specific values of the aij
and bij constants:
A = [-0.0285 -0.0014
-0.0371 -0.1476];
B = [-0.0850 0.0238
0.0802 0.4462];
C = [0 1
1 0];
D = zeros(2,2);
CSTR = ss(A,B,C,D);
The following code sets some of the CSTR model's optional properties:
CSTR
2-21
2 Building Models
Although an MPC controller can regulate a nonlinear plant, the model used within the
controller must be linear. In other words, the controller employs a linear approximation of
the nonlinear plant. The accuracy of this approximation significantly affects controller
performance.
To obtain such a linear approximation, you linearize the nonlinear plant at a specified
operating point.
Note Simulink Control Design software must be installed to linearize nonlinear Simulink
models.
For this example the CSTR model, CSTR_OpenLoop, is linearized. The model inputs are
the coolant temperature (manipulated variable of the MPC controller), limiting reactant
concentration in the feed stream, and feed temperature. The model states are the
temperature and concentration of the limiting reactant in the product stream. Both states
are measured and used for feedback control.
The operating point defines the nominal conditions at which you linearize a model. It is
usually a steady-state condition.
2-22
Linearize Simulink Models
Suppose that you plan to operate the CSTR with the output concentration, C_A, at
2 kmol/m3. The nominal feed concentration is 10 kmol/m3, and the nominal feed
temperature is 300 K. Create an operating point specification object to define the steady-
state conditions.
opspec = operspec('CSTR_OpenLoop');
opspec = addoutputspec(opspec,'CSTR_OpenLoop/CSTR',2);
opspec.Outputs(1).Known = true;
opspec.Outputs(1).y = 2;
op1 = findop('CSTR_OpenLoop',opspec);
Inputs:
----------
(1.) CSTR_OpenLoop/Coolant Temperature
u: 299 [-Inf Inf]
Outputs:
----------
(1.) CSTR_OpenLoop/CSTR
y: 2 (2)
The calculated operating point is C_A = 2 kmol/m3 and T_K = 373 K. Notice that the
steady-state coolant temperature is also given as 299 K, which is the nominal value of the
manipulated variable of the MPC controller.
To specify:
• Values of known inputs, use the Input.Known and Input.u fields of opspec
2-23
2 Building Models
• Initial guesses for state values, use the State.x field of opspec
For example, the following code specifies the coolant temperature as 305 K and initial
guess values of the C_A and T_K states before calculating the steady-state operating
point:
opspec = operspec('CSTR_OpenLoop');
opspec.States(1).x = 1;
opspec.States(2).x = 400;
opspec.Inputs(1).Known = true;
opspec.Inputs(1).u = 305;
op2 = findop('CSTR_OpenLoop',opspec);
Inputs:
----------
(1.) CSTR_OpenLoop/Coolant Temperature
u: 305
Outputs: None
----------
If the linearization input and output signals are already defined in the model, as in
CSTR_OpenLoop, then use the following to obtain the signal set.
io = getlinio('CSTR_OpenLoop');
2-24
Linearize Simulink Models
Linearize Model
Linearize the model using the specified operating point, op1, and input/output signals,
io.
sys = linearize('CSTR_OpenLoop',op1,io)
sys =
A =
C_A T_K
C_A -5 -0.3427
T_K 47.68 2.785
B =
Coolant Temp Feed Concent Feed Tempera
C_A 0 1 0
T_K 0.3 0 1
C =
C_A T_K
CSTR/1 0 1
CSTR/2 1 0
D =
Coolant Temp Feed Concent Feed Tempera
CSTR/1 0 0 0
CSTR/2 0 0 0
2-25
2 Building Models
open_system('CSTR_OpenLoop')
The linearization inputs and outputs are already specified for CSTR_OpenLoop. The input
signals correspond to the outputs from the Feed Concentration, Feed Temperature,
and Coolant Temperature blocks. The output signals are the inputs to the CSTR
Temperature and Residual Concentration blocks.
To specify a signal as a linearization input or output, first open the Linearization tab. To
do so, in the Simulink Apps gallery, click Linearization Manager. Then, in the Simulink
model window, click the signal.
• Linearization input, on the Linearization tab, in the Insert Analysis Points gallery,
click Input Perturbation.
• Linearization output, on the Linearization tab, in the Insert Analysis Points gallery,
click Output Measurement.
To open the Linear Analysis Tool, in the Apps gallery, click Model Linearizer.
2-26
Linearize Simulink Models
In the Simulink model window, click the CA output signal from the CSTR block. Then, on
the Linearization tab, in the Insert Analysis Points gallery, click Trim Output
Constraint.
2-27
2 Building Models
In the Linear Analysis Tool, on the Linear Analysis tab, select Operating Point >
Trim Model.
2-28
Linearize Simulink Models
Linearize Model
On the Linear Analysis tab, in the Operating Point drop-down list, select op_trim1.
2-29
2 Building Models
This option creates the linear model linsys1 in the Linear Analysis Workspace and
generates a step response for this model. linsys1 uses optrim1 as its operating point.
The step response from feed concentration to output CSTR/2 displays an interesting
inverse response. An examination of the linear model shows that CSTR/2 is the residual
CSTR concentration, C_A. When the feed concentration increases, C_A increases initially
because more reactant is entering, which increases the reaction rate. This rate increase
results in a higher reactor temperature (output CSTR/1), which further increases the
reaction rate and C_A decreases dramatically.
If necessary, you can repeat any of these steps to improve your model performance. Once
you are satisfied with your linearization result, in the Linear Analysis Tool, drag and drop
2-30
See Also
it from the Linear Analysis Workspace to the MATLAB Workspace. You can now use
your linear model to design an MPC controller.
See Also
Linear Analysis Tool | linearize
Related Examples
• “Design MPC Controller in Simulink” on page 3-38
• “Design Controller Using MPC Designer” on page 3-2
• “Design MPC Controller at the Command Line” on page 3-24
2-31
2 Building Models
sys = 'CSTR_ClosedLoop';
open_system(sys)
In the Block Parameters dialog box, ensure that the MPC Controller field is empty, and
click Design to open MPC Designer.
Using MPC Designer, you can define the MPC structure by linearizing the Simulink
model. After you define the initial MPC structure, you can also linearize the model at
different operating points and import the linearized plants.
Note If a controller from the MATLAB workspace is specified in the MPC Controller
field, the app imports the specified controller. In this case, the MPC structure is derived
from the imported controller. In this case, you can still linearize the Simulink model and
import the linearized plants.
On the MPC Designer tab, in the Structure section, click MPC Structure.
2-32
Linearize Simulink Models Using MPC Designer
2-33
2 Building Models
In the Define MPC Structure By Linearization dialog box, in the MPC Structure section,
if the displayed signal dimensions do not match your model, click Change I/O Sizes to
configure the dimensions. Any unmeasured disturbances or unmeasured outputs in your
model are not detected by the MPC Controller block. Specify the dimensions for these
signals.
Tip In the MPC Controller Block Parameters dialog box, in the Default Conditions tab,
you can define the controller sample time and signal dimensions before opening MPC
Designer.
2-34
Linearize Simulink Models Using MPC Designer
Before linearizing the model, assign Simulink signal lines to each MPC signal type in your
model. The app uses these signals as linearization inputs and outputs.
In the Simulink Signals for Plant Inputs and Simulink Signals for Plant Outputs
sections, the Block Path is automatically defined for manipulated variables, measured
outputs, and measured disturbances. MPC Designer detects these signals since they are
connected to the MPC Controller block. If your application has unmeasured disturbances
or unmeasured outputs, select their corresponding Simulink signal lines.
2-35
2 Building Models
In the Simulink model window, click the signal line corresponding to the selected signal
type.
The signal is highlighted, and its block path is added to the Select signals dialog box.
In the Define MPC Structure By Linearization dialog box, the Block Path for the selected
signal type updates.
2-36
Linearize Simulink Models Using MPC Designer
Note If your model has measured disturbances, you must connect the corresponding
plant inputs to the signal line connected to the md port of the MPC Controller block. For
more information, see “Connect Measured Disturbances for Linearization” on page 2-50.
In the Simulink Operating Point section, in the drop-down list, select an operating
point at which to linearize the model.
For information on the different operating point options, see “Specifying Operating
Points” on page 2-39.
Note If you select an option that generates multiple operating points for linearization,
MPC Designer uses only the first operating point to define the plant structure and
linearize the model.
The app linearizes the Simulink model at the specified operating point using the specified
input/output signals, and adds the linearized plant to the Data Browser.
Also, a default controller, which uses the linearized plant as its internal model, and a
default simulation scenario are created.
MPC Designer uses the input/output signal values at the selected operating point as
nominal values.
Linearize Model
After you define the initial MPC structure, you can linearize the Simulink model at
different operating points and import the linearized plants. Doing so is useful for
validating controller performance against modeling errors.
On the MPC Designer tab, in the Import section, click Linearize Model.
2-37
2 Building Models
In the Simulink Signals for Plant Inputs and Simulink Signals for Plant Outputs
sections, the input/output signal configuration is the same as you specified when initially
defining the MPC structure.
You cannot change the signal types and dimensions once the structure has been defined.
However, for each signal type, you can select different signal lines from your Simulink
model. The selected lines must have the same dimensions as defined in the current MPC
structure.
In the Simulink Operating Point section, in the drop-down list, select the operating
points at which to linearize the model.
2-38
Linearize Simulink Models Using MPC Designer
For information on the different operating point options, see “Specifying Operating
Points” on page 2-39.
MPC Designer linearizes the Simulink model at the defined operating point using the
specified input/output signals, and adds the linearized plant to the Data Browser.
If you select the Use selected operating point to update nominal values as well
option, the app updates the controller nominal values using the operating point signal
values.
If you select an option that generates multiple operating points for linearization, the app
linearizes the model at all the specified operating points. The linearized plants are added
to the Data Browser in the same order in which their corresponding operating points are
defined. If you choose to update the nominal values, the app uses the signal values from
the first operating point.
To linearize the model using the initial conditions specified in the Simulink model as the
operating point, select Model Initial Condition.
2-39
2 Building Models
The model initial condition is the default operating point for linearization in MPC
Designer.
To linearize the model at specified simulation snapshot times, select Linearize At.
Linearizing at snapshot times is useful when you know that your model reaches an
equilibrium state after a certain simulation time.
2-40
Linearize Simulink Models Using MPC Designer
In the Enter snapshot times to linearize dialog box, in the Simulation snapshot times
field, enter one or more simulation snapshot times. Enter multiple snapshot times as a
vector.
Click OK.
If you enter multiple snapshot times, and you selected Linearize At from the:
• Define MPC Structure By Linearization dialog box, MPC Designer linearizes the
model using only the first snapshot time. The nominal values of the MPC controller are
defined using the input/output signal values for this snapshot.
• Linearize Simulink Model dialog box, MPC Designer linearizes the model at all the
specified snapshot times. The linearized plant models are added to the Data Browser
in the order specified in the snapshot time array. If you selected the Use selected
operating point to update nominal values as well option, the nominal values are
set using the input/output signal values from the first snapshot.
2-41
2 Building Models
In the Trim the model dialog box, enter the specifications for the steady-state values at
which you want to find an operating point. You can specify values for states, input signals,
and output signals.
2-42
Linearize Simulink Models Using MPC Designer
MPC Designer creates an operating point for the given specifications. The computed
operating point is added to the Simulink Operating Point drop-down list and is
selected.
For examples showing how to specify the conditions for a steady-state operating point
search, see “Compute Steady-State Operating Points from Specifications” (Simulink
Control Design).
2-43
2 Building Models
In the Enter snapshot times to linearize dialog box, in the Simulation snapshot times
field, enter one or more simulation snapshot times. Enter multiple snapshot times as a
vector.
MPC Designer simulates the Simulink model. At each snapshot time, the current state of
the model is used to create an operating point, which is added to the drop-down list and
selected.
If you entered multiple snapshot times, the operating points are stored together as an
array. If you selected Take Simulation Snapshot from the:
2-44
Linearize Simulink Models Using MPC Designer
• Define MPC Structure By Linearization dialog box, MPC Designer linearizes the
model using only the first operating point in the array. The nominal values of the MPC
controller are defined using the input/output signal values for this operating point.
• Linearize Simulink Model dialog box, MPC Designer linearizes the model at all the
operating points in the array. The linearized plant models are added to the Data
Browser in the same order as the operating point array.
In MPC Designer, the Linearize At and Take Simulation Snapshot options generally
produce the same linearized plant and nominal signal values. However, since the Take
Simulation Snapshot option first computes an operating point from the snapshot before
linearization, the results can differ.
Under Existing Operating Points, select a previously defined operating point at which
to linearize the Simulink model. This option is available if one or more previously created
operating points are available in the drop-down list.
2-45
2 Building Models
If the selected operating point represents an operating point array created using multiple
snapshot times, and you selected an operating point from the:
• Define MPC Structure By Linearization dialog box, MPC Designer linearizes the
model using only the first operating point in the array. The nominal values of the MPC
controller are defined using the input/output signal values for this operating point.
• Linearize Simulink Model dialog box, MPC Designer linearizes the model at all the
operating points in the array. The linearized plant models are added to the Data
Browser in the same order as the operating point array.
To linearize the Simulink model at multiple existing operating points, select Linearize at
Multiple Points. This option is available if there are more than one previously created
operating points in the drop-down list.
2-46
Linearize Simulink Models Using MPC Designer
In the Specify multiple operating points dialog box, select the operating points at which to
linearize the model.
To change the operating point order, click an operating point in the list and click Up or
Down to move the highlighted operating point within the list.
Click OK.
• Define MPC Structure By Linearization dialog box, MPC Designer linearizes the
model using only the first specified operating point. The nominal values of the MPC
controller are defined using the input/output signal values for this operating point.
• Linearize Simulink Model dialog box, MPC Designer linearizes the model at all the
specified operating points. The linearized plant models are added to the Data
Browser in the order specified in the Specify multiple operating points dialog box.
To view or edit the selected operating point, under View/Edit, click the Edit option.
2-47
2 Building Models
In the Edit dialog box, if you created the selected operating point from a simulation
snapshot, you can edit the operating point values.
2-48
Linearize Simulink Models Using MPC Designer
If the selected operating point represents an operating point array, in the Select
Operating Point drop-down list, select an operating point to view.
If you obtained the operating point by trimming the model, you can only view the
operating point values.
2-49
2 Building Models
To set the Simulink model initial conditions to the states in the operating point, click
Initialize model. You can then simulate the model at the specified operating point.
When setting the model initial conditions, MPC Designer exports the operating point to
the MATLAB workspace. Also, in the Simulink Configuration Parameters dialog box, in the
Data Import/Export section, it selects the Input and Initial state parameters and
configures them to use the states and inputs in the exported operating point.
To reset the model initial conditions, for example if you delete the exported operating
point, clear the Input and Initial state parameters.
2-50
Linearize Simulink Models Using MPC Designer
Since the measured disturbances connected to the md port are selected as linearization
inputs, you must connect the plant measured disturbance input ports to the selected
signal line, as shown in the following:
Correct MD Connection
If you connect the plant measured disturbance input ports to the corresponding signals
before the Mux block, as shown in the following, there is no linearization path from the
signals at the md port to the plant. As a result, when you linearize the plant using MPC
Designer, the measured disturbance channels linearize to zero.
2-51
2 Building Models
Incorrect MD Connection
See Also
MPC Designer
Related Examples
• “Linearize Simulink Models” on page 2-22
• “Design MPC Controller in Simulink” on page 3-38
2-52
Identify Plant from Data
You can estimate the plant model programmatically at the command line or interactively
using the System Identification app.
This command imports the plant input signal, u, plant output signal, y, and sample time,
Ts to the MATLAB® workspace.
You can optionally assign channel names and units for the input and output signals.
mydata.InputName = 'Voltage';
mydata.InputUnit = 'V';
mydata.OutputName = 'Position';
mydata.OutputUnit = 'cm';
Typically, you must preprocess identification I/O data before estimating a model. For this
example, remove the offsets from the input and output signals by detrending the data.
2-53
2 Building Models
mydatad = detrend(mydata);
You can also remove offsets by creating an ssestOptions object and specifying the
InputOffset and OutputOffset options.
For this example, estimate a second-order, linear state-space model using the detrended
data. To estimate a discrete-time model, specify the sample time as Ts.
ss1 = ssest(mydatad,2,'Ts',Ts)
ss1 =
Discrete-time identified state-space model:
x(t+Ts) = A x(t) + B u(t) + K e(t)
y(t) = C x(t) + D u(t) + e(t)
A =
x1 x2
x1 0.8942 -0.1575
x2 0.1961 0.7616
B =
Voltage
x1 6.008e-05
x2 -0.01219
C =
x1 x2
Position 38.24 -0.3835
D =
Voltage
Position 0
K =
Position
x1 0.03572
x2 0.0223
Parameterization:
FREE form (all coefficients in A, B, C free).
Feedthrough: none
Disturbance component: estimate
Number of free coefficients: 10
2-54
Identify Plant from Data
Status:
Estimated using SSEST on time domain data "mydatad".
Fit to estimation data: 89.85% (prediction focus)
FPE: 0.0156, MSE: 0.01541
You can use this identified plant as the internal prediction model for your MPC controller.
When you do so, the controller converts the identified model to a discrete-time, state-
space model.
By default, the MPC controller discards any unmeasured noise components from your
identified model. To configure noise channels as unmeasured disturbances, you must first
create an augmented state-space model from your identified model. For example:
ss2 = ss(ss1,'augmented')
ss2 =
A =
x1 x2
x1 0.8942 -0.1575
x2 0.1961 0.7616
B =
Voltage v@Position
x1 6.008e-05 0.004448
x2 -0.01219 0.002777
C =
x1 x2
Position 38.24 -0.3835
D =
Voltage v@Position
Position 0 0.1245
Input groups:
Name Channels
Measured 1
Noise 2
2-55
2 Building Models
This command creates a state-space model, ss2, with two input groups, Measured and
Noise, for the measured and noise inputs respectively. When you import the augmented
model into your MPC controller, channels in the Noise input group are defined as
unmeasured disturbances.
Use the impulseest function to estimate an FIR model from measured data. This
function generates the FIR coefficients encapsulated as an idtf object; that is, a transfer
function model with only numerator coefficients. impulseest is especially effective in
situations where the input signal used for identification has low excitation levels. To
design a model predictive controller for this plant, you can convert the identified FIR
plant model to a numeric LTI model. However, this conversion usually yields a high-order
plant, which can degrade the controller design. For example, the numerical precision
issues with high-order plants can affect estimator design. This result is particularly an
issue for MIMO systems.
Model predictive controllers work best with low-order parametric models. Therefore, to
design a model predictive controller using measured plant data, you can:
References
[1] Cutler, C., and F. Yocum, "Experience with the DMC inverse for identification,"
Chemical Process Control — CPC IV (Y. Arkun and W. H. Ray, eds.), CACHE, 1991.
2-56
See Also
[2] Ricker, N. L., "The use of bias least-squares estimators for parameters in discrete-time
pulse response models," Ind. Eng. Chem. Res., Vol. 27, pp. 343, 1988.
[3] Wang, L., P. Gawthrop, C. Chessari, T. Podsiadly, and A. Giles, "Indirect approach to
continuous time system identification of food extruder," J. Process Control, Vol. 14,
Number 6, pp. 603–615, 2004.
See Also
Apps
System Identification
Functions
detrend | iddata | ssest
More About
• “Handling Offsets and Trends in Data” (System Identification Toolbox)
• “Identify Linear Models Using System Identification App” (System Identification
Toolbox)
• “Design MPC Controller for Identified Plant Model”
2-57
3
CSTR Model
dC′ A
= a11C′ A + a12T′ + b11T′c + b12C′ Ai
dt
dT′
= a21C′ A + a22T′ + b21T′c + b22C′ Ai
dt
The prime terms, such as C′A, denote a deviation from the nominal steady-state condition
at which the model has been linearized.
Measurement of reagent concentrations is often difficult. For this example, assume that:
• Tc is a manipulated variable.
3-2
Design Controller Using MPC Designer
dx
= Ax + Bu
dt
y = Cx + Du
where,
C′ A T′c T′
x= , u = , y =
T′ C′ Ai C′ A
For this example, the coolant temperature has a limited range of ±10 degrees from its
nominal value and a limited rate of change of ±4 degrees per sample period.
mpcDesigner
3-3
3 Design MPC Controllers
On the MPC Designer tab, in the Structure section, click MPC Structure.
In the Define MPC Structure By Importing dialog box, in the Select a plant model or an
MPC controller table, select the CSTR model.
Since CSTR is a stable, continuous-time LTI system, MPC Designer sets the controller
sample time to 0.1 Tr, where Tr is the average rise time of CSTR. For this example, in the
Specify MPC controller sample time field, enter a sample time of 1.
By default, all plant inputs are defined as manipulated variables and all plant outputs as
measured outputs. In the Assign plant i/o channels section, assign the input and output
channel indices such that:
3-4
Design Controller Using MPC Designer
3-5
3 Design MPC Controllers
3-6
Design Controller Using MPC Designer
The app imports the CSTR plant to the Data Browser. The following are also added to the
Data Browser:
• mpc1 — Default MPC controller created using sys as its internal model.
• scenario1 — Default simulation scenario.
The app runs the default simulation scenario and updates the Input Response and
Output Response plots.
Tip To view the response plots side-by-side, on the View tab, in the Tiles section, click
Left/Right.
3-7
3 Design MPC Controllers
Once you define the MPC structure, you cannot change it within the current MPC
Designer session. To use a different channel configuration, start a new session of the
app.
In the Input and Output Channel Specifications dialog box, in the Name column, specify a
meaningful name for each input and output channel.
In the Unit column, optionally specify the units for each channel.
Since the state-space model is defined using deviations from the nominal operating point,
set the Nominal Value for each input and output channel to 0.
Keep the Scale Factor for each channel at the default value of 1.
3-8
Design Controller Using MPC Designer
Click OK.
The Input Response and Output Response plot labels update to reflect the new signal
names and units.
On the MPC Designer tab, in the Scenario section, click Edit Scenario > scenario1.
In the Simulation Scenario dialog box, increase the Simulation duration to 30 seconds.
In the Reference Signals table, in the first row, specify a step Size of 2 and a Time of 5.
In the Signal column, in the second row, select a Constant reference to hold the
concentration setpoint at its nominal value.
3-9
3 Design MPC Controllers
The default scenario is configured to simulate a step change of 2 degrees in the reactor
temperature, T, at a time of 5 seconds.
Click OK.
The response plots update to reflect the new simulation scenario configuration.
In the Data Browser, in the Scenarios section, click scenario1. Click scenario1 a
second time, and rename the scenario to stepT.
3-10
Design Controller Using MPC Designer
On the Tuning tab, in the Horizons section, specify a Prediction horizon of 15 and a
Control horizon of 3.
3-11
3 Design MPC Controllers
The response plots update to reflect the new horizons. The Input Response plot shows
that the control actions for the manipulated variable violate the required coolant
temperature constraints.
In the Constraints dialog box, in the Input Constraints section, enter the coolant
temperature upper and lower bounds in the Min and Max columns respectively.
Specify the rate of change limits in the RateMin and RateMax columns.
3-12
Design Controller Using MPC Designer
Click OK.
3-13
3 Design MPC Controllers
The Input Response plot shows the constrained manipulated variable control actions.
Even with the constrained rate of change, the coolant temperature rises quickly to its
maximum limit within three control intervals.
In the Input Weights table, increase the manipulated variable (MV) Rate Weight to
0.3. Increasing the MV rate weight penalizes large MV changes in the controller
optimization cost function.
In the Output Weights table, keep the default Weight values. By default, all unmeasured
outputs have zero weights.
3-14
Design Controller Using MPC Designer
Since there is only one manipulated variable, if the controller tries to hold both outputs at
specific setpoints, one or both outputs will exhibit steady-state error in their responses.
Since the controller ignores setpoints for outputs with zero weight, setting the
concentration output weight to zero allows reactor temperature setpoint tracking with
zero steady-state error.
Click OK.
3-15
3 Design MPC Controllers
The Input Response plot shows the more conservative control actions, which result in a
slower Output Response.
Suppose the application demands zero overshoot in the output response. On the
Performance Tuning tab, drag the Closed-Loop Performance slider to the left until
the Output Response has no overshoot. Moving this slider to the left simultaneously
increases the manipulated variable rate weight of the controller and decreases the output
variable weight, producing a more robust controller.
3-16
Design Controller Using MPC Designer
When you adjust the controller tuning weights using the Closed-Loop Performance
slider, MPC Designer does not change the weights you specified in the Weights dialog
box. Instead, the slider controls an adjustment factor, which is used with the user-
specified weights to define the actual controller weights.
This factor is 1 when the slider is centered; its value decreases as the slider moves left
and increases as the slider moves right. The weighting factor multiplies the manipulated
variable and output variable weights and divides the manipulated variable rate weights
from the Weights dialog box.
To view the actual controller weights, export the controller to the MATLAB workspace,
and view the Weights property of the exported controller object.
3-17
3 Design MPC Controllers
On the MPC Designer tab, in the Scenario section, click Plot Scenario > New
Scenario.
In the Simulation Scenario dialog box, set the Simulation duration to 30 seconds.
In the Unmeasured Disturbances table, in the Signal drop-down list, select Step.
3-18
Design Controller Using MPC Designer
Click OK.
The app adds new scenario to the Data Browser and creates new corresponding Input
Response and Output Response plots.
3-19
3 Design MPC Controllers
In the Output Response plots, the controller returns the reactor temperature, T, to a
value near its setpoint as expected. However, the required control actions cause an
increase in the output concentration, CA to 6 kgmol/m3.
Previously, you defined the controller tuning weights to achieve the primary control
objective of tracking the reactor temperature setpoint with zero steady-state error. Doing
so enables the unmeasured reactor concentration to vary freely. Suppose that unwanted
reactions occur once the reactor concentration exceeds a 3 kgmol/m3. To limit the reactor
concentration, specify an output constraint.
3-20
Design Controller Using MPC Designer
In the Constraints dialog box, in the Output Constraints section, the second row of the
table, specify a Max unmeasured output (UO) value of 3.
By default, all output constraints are soft, meaning that their MinECR and MaxECR
values are greater than zero. To soften the unmeasured output (UO) constraint further,
increase its MaxECR value.
Click OK.
3-21
3 Design MPC Controllers
In the Output Response plots, once the reactor concentration, CA, approaches 3
kgmol/m3, the reactor temperature, T, starts to increase. Since there is only one
manipulated variable, the controller makes a compromise between the two competing
control objectives: Temperature control and constraint satisfaction. A softer output
constraint enables the controller to sacrifice the constraint requirement more to achieve
improved temperature tracking.
Since the output constraint is soft, the controller maintain adequate temperature control
by allowing a small concentration constraint violation. In general, depending on your
application requirements, you can experiment with different constraint settings to achieve
an acceptable control objective compromise.
3-22
See Also
Export Controller
In the Tuning tab, in the Analysis section, click Export Controller to save the
tuned controller, mpc1, to the MATLAB workspace.
To delete a plant, controller, or scenario, in the Data Browser, right-click the item you
want to delete, and select Delete. You can also click the item and hit Delete on the
keyboard.
You cannot delete the current controller. Also, you cannot delete a plant or scenario if it is
the only listed plant or scenario.
If a plant is used by any controller or scenario, you cannot delete the plant.
To delete multiple plants, controllers, or scenarios, hold Shift and click each item that
you want to delete.
References
[1] Seborg, D. E., T. F. Edgar, and D. A. Mellichamp, Process Dynamics and Control, 2nd
Edition, Wiley, 2004, pp. 34–36 and 94–95.
See Also
MPC Designer
More About
• “Specify Constraints”
• “Tune Weights”
• “Design MPC Controller in Simulink” on page 3-38
3-23
3 Design MPC Controllers
This example uses the plant model described in “Design Controller Using MPC Designer”
on page 3-2. Create a state-space model of the plant and set some of the optional model
properties.
CSTR.InputName = {'T_c','C_A_i'};
CSTR.OutputName = {'T','C_A'};
CSTR.StateName = {'C_A','T'};
CSTR.InputGroup.MV = 1;
CSTR.InputGroup.UD = 2;
CSTR.OutputGroup.MO = 1;
CSTR.OutputGroup.UO = 2;
Create Controller
To improve the clarity of the example, suppress Command Window messages from the
MPC controller.
old_status = mpcverbosity('off');
Create a model predictive controller with a control interval, or sample time, of 1 second,
and with all other properties at their default values.
Ts = 1;
MPCobj = mpc(CSTR,Ts)
3-24
Design MPC Controller at the Command Line
Plant Model:
--------------
1 manipulated variable(s) -->| 2 states |
| |--> 1 measured output(s)
0 measured disturbance(s) -->| 2 inputs |
| |--> 1 unmeasured output(s)
1 unmeasured disturbance(s) -->| 2 outputs |
--------------
Indices:
(input vector) Manipulated variables: [1 ]
Unmeasured disturbances: [2 ]
(output vector) Measured outputs: [1 ]
Unmeasured outputs: [2 ]
Weights:
ManipulatedVariables: 0
ManipulatedVariablesRate: 0.1000
OutputVariables: [1 0]
ECR: 100000
Unconstrained
get(MPCobj)
Ts: 1
PredictionHorizon (P): 10
ControlHorizon (C): 2
Model: [1x1 struct]
ManipulatedVariables (MV): [1x1 struct]
OutputVariables (OV): [1x2 struct]
DisturbanceVariables (DV): [1x1 struct]
Weights (W): [1x1 struct]
Optimizer: [1x1 struct]
3-25
3 Design MPC Controllers
Notes: {}
UserData: []
History: 26-Aug-2020 22:28:46
The displayed History value will be different for your controller, since it depends on
when the controller was created. For a description of the editable properties of an MPC
controller, enter mpcprops at the command line.
Use dot notation to modify these properties. For example, change the prediction horizon
to 15.
MPCobj.PredictionHorizon = 15;
You can abbreviate property names provided that the abbreviation is unambiguous.
Many of the controller properties are structures containing additional fields. Use dot
notation to view and modify these field values. For example, you can set the measurement
units for the controller output variables. The OutputUnit property is for display
purposes only and is optional.
MPCobj.MV.Min = -10;
MPCobj.MV.Max = 10;
MPCobj.MV.RateMin = -3;
MPCobj.MV.RateMax = 3;
You can also view and modify the controller tuning weights. For example, modify the
weights for the manipulated variable rate and the output variables.
MPCobj.W.ManipulatedVariablesRate = 0.3;
MPCobj.W.OutputVariables = [1 0];
You can also define time-varying constraints and weights over the prediction horizon,
which shifts at each time step. Time-varying constraints have a nonlinear effect when they
are active. For example, to force the manipulated variable to change more slowly towards
the end of the prediction horizon, enter:
3-26
Design MPC Controller at the Command Line
The -2.5 and 2.5 values are used for the fourth step and beyond.
Similarly, you can specify different output variable weights for each step of the prediction
horizon. For example, enter:
You can also modify the disturbance rejection characteristics of the controller. See
setEstimator, setindist, and setoutdist for more information.
review(MPCobj)
3-27
3 Design MPC Controllers
3-28
Design MPC Controller at the Command Line
In this example, the review command found two potential issues with the design. The
first warning asks whether the user intends to have a weight of zero on the C_A output.
The second warning advises the user to avoid having hard constraints on both MV and
MVRate.
Use the sim function to run a linear simulation of the system. For example, simulate the
closed-loop response of MPCobj for 26 control intervals. Specify setpoints of 2 and 0 for
the reactor temperature and the residual concentration respectively. The setpoint for the
residual concentration is ignored because the tuning weight for the second output is zero.
T = 26;
r = [0 0; 2 0];
sim(MPCobj,T,r)
3-29
3 Design MPC Controllers
3-30
Design MPC Controller at the Command Line
You can modify the simulation options using mpcsimopt. For example, run a simulation
with the manipulated variable constraints turned off.
MPCopts = mpcsimopt;
MPCopts.Constraints = 'off';
sim(MPCobj,T,r,MPCopts)
3-31
3 Design MPC Controllers
3-32
Design MPC Controller at the Command Line
The first move of the manipulated variable now exceeds the specified 3-unit rate
constraint.
You can also perform a simulation with a plant/model mismatch. For example, define a
plant with 50% larger gains than those in the model used by the controller.
Plant = 1.5*CSTR;
MPCopts.Model = Plant;
sim(MPCobj,T,r,MPCopts)
3-33
3 Design MPC Controllers
3-34
Design MPC Controller at the Command Line
Other options include the addition of a specified noise sequence to the manipulated
variables or measured outputs, open-loop simulations, and a look-ahead option for better
setpoint tracking or measured disturbance rejection.
[y,t,u] = sim(MPCobj,T,r);
3-35
3 Design MPC Controllers
The syntax suppresses automatic plotting and returns the simulation results. You can use
the results for other tasks, including custom plotting. For example, plot the manipulated
variable and both output variables in the same figure.
figure
subplot(2,1,1)
plot(t,u)
title('Inputs')
legend('T_c')
subplot(2,1,2)
plot(t,y)
title('Outputs')
legend('T','C_A')
xlabel('Time')
3-36
See Also
mpcverbosity(old_status);
See Also
mpc | review | sim
More About
• “MPC Modeling” on page 2-2
• “Design Controller Using MPC Designer” on page 3-2
• “Design MPC Controller in Simulink” on page 3-38
3-37
3 Design MPC Controllers
This example requires Simulink Control Design software to define the MPC structure by
linearizing a nonlinear Simulink model.
If you do not have Simulink Control Design software, you must first create an mpc object
in the MATLAB workspace. For more information, see “Design Controller Using MPC
Designer” on page 3-2 and “Design MPC Controller at the Command Line” on page 3-24.
CSTR Model
A CSTR is a jacketed nonadiabatic tank reactor commonly used in the process industry.
3-38
Design MPC Controller in Simulink
An inlet stream of reagent A feeds into the tank at a constant rate. A first-order,
irreversible, exothermic reaction takes place to produce the product stream, which exits
the reactor at the same rate as the input stream.
The control objective is to maintain the residual concentration, CA, at its nominal setpoint
by adjusting the coolant temperature, Tc. Changes in the feed concentration, CAi, and
feed temperature, Ti, cause disturbances in the CSTR reaction.
The reactor temperature, T, is usually controlled. However, for this example, ignore the
reactor temperature, and assume that the residual concentration is measured directly.
open_system('CSTR_ClosedLoop')
3-39
3 Design MPC Controllers
In the Block Parameters dialog box, on the General tab, in the Additional Inports
section, check the Measured disturbance (md) option.
3-40
Design MPC Controller in Simulink
In the Simulink model window, connect the Feed Temperature block output to the md
inport.
In the MPC Controller Block Parameters dialog box, click Design to open MPC
Designer.
Note This step requires Simulink Control Design software to linearize the Simulink
model. For more information, see “Linearize Simulink Models Using MPC Designer” on
page 2-32.
If you do not have Simulink Control Design software, you must first create an mpc object
in the MATLAB workspace.
3-41
3 Design MPC Controllers
In MPC Designer, on the MPC Designer tab, in the Structure section, click MPC
Structure.
In the Define MPC Structure By Linearization dialog box, in the Controller Sample
Time section, specify a sample time of 0.1.
In the MPC Structure section, click Change I/O Sizes to add the unmeasured
disturbance and measured disturbance signal dimensions.
In the MPC Block Signal Sizes dialog box, specify the number of input/output channels of
each type:
Click OK.
3-42
Design MPC Controller in Simulink
In the Define MPC Structure By Linearization dialog box, in the Simulink Signals for
Plant Inputs section, the app adds a row for Unmeasured Disturbances (UD).
3-43
3 Design MPC Controllers
3-44
Design MPC Controller in Simulink
The manipulated variable, measured disturbance, and measured output are already
assigned to their respective Simulink signal lines, which are connected to the MPC
Controller block.
In the Simulink Signals for Plant Inputs section, select the Unmeasured
Disturbances (UD) row, and click Select Signals.
In the Simulink model window, click the output signal from the Feed Concentration block.
The signal is highlighted and its block path is added to the Select Signal dialog box.
In the Define MPC Structure By Linearization dialog box, in the Simulink Signals for
Plant Inputs table, the Block Path for the unmeasured disturbance signal is updated.
Linearize the Simulink model at a steady-state equilibrium operating point where the
residual concentration is 2 kgmol/m3. To compute such an operating point, add the CA
signal as a trim output constraint, and specify its target constraint value.
In the Simulink model window, right-click the signal line connected to CA outport of the
CSTR block, and select Linear Analysis Points > Trim Output Constraint.
3-45
3 Design MPC Controllers
The CA signal can now be used to define output specifications for calculating a model
steady-state operating point.
In the Define MPC Structure By Linearization dialog box, in the Simulink Operating
Point section, in the drop-down list, under Create New Operating Point, click Trim
Model.
In the Trim the model dialog box, in the Outputs tab, check the box in the Known
column for Channel-1 and specify a Value of 2.
3-46
Design MPC Controller in Simulink
This setting constrains the value of the output signal during the operating point search to
a known value.
In the Define MPC Structure By Linearization dialog box, in the Simulink Operating
Point section, the computed operating point, op_trim1, is added to the drop-down list
and selected.
3-47
3 Design MPC Controllers
In the Edit dialog box, on the State tab, in the Actual dx column, the near-zero derivative
values indicate that the computed operating point is at steady-state.
Click Initialize model to set the initial states of the Simulink model to the operating
point values in the Actual Values column. Doing so enables you to later simulate the
Simulink model at the computed operating point rather than at the default model initial
conditions.
When setting the model initial conditions, MPC Designer exports the operating point to
the MATLAB workspace. Also, in the Simulink Configuration Parameters dialog box, in the
Data Import/Export section, it selects the Input and Initial state parameters and
configures them to use the states and inputs in the exported operating point.
To reset the model initial conditions, for example if you delete the exported operating
point, clear the Input and Initial state parameters.
3-48
Design MPC Controller in Simulink
In the Define MPC Structure By Linearization dialog box, click Define and Linearize to
linearize the model.
The linearized plant model is added to the Data Browser. Also, the following are added
to the Data Browser:
• A default MPC controller created using the linearized plant as an internal prediction
model
• A default simulation scenario
On the MPC Designer tab, in the Structure section, click I/O Attributes.
In the Input and Output Channel Specifications dialog box, in the Name column, specify
meaningful names for each input and output channel.
3-49
3 Design MPC Controllers
The Nominal Value for each signal is the corresponding steady-state value at the
computed operating point.
Click OK.
The primary objective of the controller is to hold the residual concentration, CA, at the
nominal value of 2 kgmol/m3. To do so, the controller must reject both measured and
unmeasured disturbances.
In the Simulation Scenario dialog box, in the Reference Signals table, in the Signal
drop-down list select Constant to hold the output setpoint at its nominal value.
In the Measured Disturbances table, in the Signal drop-down list, select Step.
3-50
Design MPC Controller in Simulink
Click OK.
In the Data Browser, under Scenarios, click scenario1. Click scenario1 a second
time, and rename it MD_reject.
In the Simulation Scenario dialog box, in the Unmeasured Disturbances table, in the
Signal drop-down list, select Step.
3-51
3 Design MPC Controllers
Click OK.
To make viewing the tuning results easier, arrange the plot area to display the Output
Response plots for both scenarios at the same time.
The plot display area changes to display the Input Response plots above the Output
Response plots.
3-52
Design MPC Controller in Simulink
In the Tuning tab, in the Horizon section, specify a Prediction horizon of 20 and a
Control horizon of 5.
The Output Response plots update based on the new horizon values.
In the Performance Tuning section, drag the Closed-Loop Performance slider to the
right, which leads to tighter control of outputs and more aggressive control moves. Drag
the slider until the MD_reject: Output response reaches steady state in less than 2
seconds.
3-53
3 Design MPC Controllers
Drag the State Estimation slider to the right, which leads to more aggressive
unmeasured disturbance rejection. Drag the slider until the UD_reject: Output response
reaches steady state in less than 3 seconds.
3-54
Design MPC Controller in Simulink
Under Update and Simulate, click Update Block Only. The app exports the tuned
controller, mpc1, to the MATLAB workspace. In the Simulink model, the MPC Controller
block is updated to use the exported controller.
3-55
3 Design MPC Controllers
The model initial conditions are set to the nominal operating point used for linearization.
In the Block Parameters dialog box, enter a Constant Value of 11 to simulate a unit step
at time zero.
3-56
Design MPC Controller in Simulink
Click Apply.
The Concentration output response is similar to the UD_reject response, however the
settling time is around 1 second later. The different result is due to the mismatch between
the linear plant used in the MPC Designer simulation and the nonlinear plant in the
Simulink model.
In the Block Parameters: Feed Concentration dialog box, enter a Constant Value of 10 to
return the feed concentration to its nominal value.
Click OK.
In the Block Parameters: Feed Temperature dialog box, enter a Constant Value of 310 to
simulate a step change of size 10 at time zero.
Click OK.
3-57
3 Design MPC Controllers
The Concentration output response is similar to the MD_reject response from the MPC
Designer simulation.
References
[1] Seborg, D. E., T. F. Edgar, and D. A. Mellichamp, Process Dynamics and Control, 2nd
Edition, Wiley, 2004, pp. 34–36 and 94–95.
See Also
MPC Controller | MPC Designer
More About
• “Tune Weights”
• “Linearize Simulink Models” on page 2-22
3-58
See Also
3-59
3 Design MPC Controllers
Create the controller object with sampling period, prediction and control horizons.
Ts = 0.1;
p = 10;
m = 3;
mpcobj = mpc(plant, Ts, p, m);
Simulate closed-loop control of the linear plant model in Simulink. The MPC Controller
block is configured to use the mpcobj object as its controller.
mdl = 'mpc_doubleint';
open_system(mdl)
sim(mdl)
3-60
Control of a Single-Input-Single-Output Plant
3-61
3 Design MPC Controllers
bdclose(mdl)
See Also
MPC Controller | MPC Designer | mpc
More About
• “Control of a Multi-Input Single-Output Plant” on page 3-63
• “Control of a Multi-Input Multi-Output Nonlinear Plant” on page 3-97
3-62
Control of a Multi-Input Single-Output Plant
The discrete-time linear open-loop dynamic model is defined below with sample time Ts.
Define type of input signals: the first signal is a manipulated variable, the second signal is
a measured disturbance, the third one is an unmeasured disturbance.
model = setmpcsignals(model,'MV',1,'MD',2,'UD',3);
Create the controller object with sampling period, prediction and control horizons.
mpcobj = mpc(model,Ts,10,3);
mpcobj.MV = struct('Min',0,'Max',1,'RateMin',-10,'RateMax',10);
For unmeasured input disturbances, its model is an integrator driven by white noise with
variance = 1000.
3-63
3 Design MPC Controllers
sim(mpcobj,Tf,r,v)
3-64
Control of a Multi-Input Single-Output Plant
SimOptions = mpcsimopt(mpcobj);
d = [zeros(2*Tf/3,1);-0.5*ones(Tf/3,1)];
SimOptions.Unmeas = d; % unmeasured input disturbance signal
SimOptions.OutputNoise=.001*(rand(Tf,1)-.5); % output measurement noise
SimOptions.InputNoise=.05*(rand(Tf,1)-.5); % noise on manipulated variables
Run the closed-loop simulation and save the results to the workspace.
[y,t,u,xp] = sim(mpcobj,Tf,r,v,SimOptions);
Plot results.
3-65
3 Design MPC Controllers
figure
subplot(2,1,1)
plot(0:Tf-1,y,0:Tf-1,r)
title('Output')
grid
subplot(2,1,2)
plot(0:Tf-1,u)
title('Input')
grid
Test the robustness of the MPC controller against a model mismatch. Specify the true
plant simModel, with a nominal output value of 0.1.
3-66
Control of a Multi-Input Single-Output Plant
SimOptions.Model = simModel;
SimOptions.plantinit = [0.1 0 -0.1 0 .05]; % Initial state of the true plant
SimOptions.OutputNoise = []; % remove output measurement noise
SimOptions.InputNoise = []; % remove noise on manipulated variables
3-67
3 Design MPC Controllers
3-68
Control of a Multi-Input Single-Output Plant
Soften Constraints
mpcobj.MV.MinECR = 1;
mpcobj.MV.MaxECR = 1;
mpcobj.OV.Max = 1.1;
sim(mpcobj,Tf,r,v)
3-69
3 Design MPC Controllers
3-70
Control of a Multi-Input Single-Output Plant
MV constraint has been slightly violated while MO constraint has been violated more.
Penalize more output constraint and rerun the simulation.
3-71
3 Design MPC Controllers
3-72
Control of a Multi-Input Single-Output Plant
Now MO constraint has been slightly violated while MV constraint has been violated more
as expected.
Model Predictive Control Toolbox™ software provides a default Kalman filter to estimate
the state of plant, disturbance, and noise models. You can change the Kalman gains.
3-73
3 Design MPC Controllers
e =
0.5708 + 0.4144i
0.5708 - 0.4144i
0.4967 + 0.0000i
0.9334 + 0.1831i
0.9334 - 0.1831i
0.8189 + 0.0000i
Test the behavior of plant in open-loop using the sim command. Set the OpenLoop flag to
on, and provide the sequence of manipulated variables that excite the system.
SimOptions.OpenLoop = 'on';
SimOptions.MVSignal = sin((0:Tf-1)'/10);
sim(mpcobj,Tf,[],v,SimOptions)
3-74
Control of a Multi-Input Single-Output Plant
3-75
3 Design MPC Controllers
To examine whether the MPC controller will be able to reject constant output
disturbances and track constant setpoint with zero offsets in steady-state, compute the
DC gain from output disturbances to controlled outputs using the cloffset command.
DC = cloffset(mpcobj);
fprintf('DC gain from output disturbance to output = %5.8f (=%g) \n',DC,DC);
A zero gain means that the output will track the desired setpoint.
3-76
Control of a Multi-Input Single-Output Plant
[A,B,C,D] = ssdata(model);
Tstop = 5; % Simulation time
x = [0 0 0 0 0]'; % Initial state of the plant
xmpc = mpcstate(mpcobj); % Initial state of the MPC controller
r = 1; % Output reference signal
Store the closed-loop MPC trajectories in arrays YY, UU, and XX.
YY=[];
UU=[];
XX=[];
for t=0:round(Tstop/Ts)-1
% Store states
XX = [XX,x]; %#ok<*AGROW>
% Define measured disturbance signal
v = 0;
if t*Ts>=10
v = 1;
end
% Define unmeasured disturbance signal
d = 0;
if t*Ts>=20
d = -0.5;
end
% Plant equations: output update (no feedthrough from MV to Y)
y = C*x + D(:,2)*v + D(:,3)*d;
YY = [YY,y];
% Compute MPC action
u = mpcmove(mpcobj,xmpc,y,r,v);
% Plant equations: state update
x = A*x + B(:,1)*u + B(:,2)*v + B(:,3)*d;
UU = [UU,u];
end
figure
subplot(2,1,1)
3-77
3 Design MPC Controllers
plot(0:Ts:Tstop-Ts,YY)
grid
title('Output')
subplot(2,1,2)
plot(0:Ts:Tstop-Ts,UU)
grid
title('Input')
If at any time during the simulation you want to check the optimal predicted trajectories,
it can be returned by mpcmove as well. Assume you want to start from the current state
and have a set-point change to 0.5, and assume the measured disturbance is gone.
3-78
Control of a Multi-Input Single-Output Plant
r = 0.5;
v = 0;
[~,Info] = mpcmove(mpcobj,xmpc,y,r,v);
topt = Info.Topt;
yopt = Info.Yopt;
uopt = Info.Uopt;
figure
subplot(2,1,1)
stairs(topt,yopt)
title('Optimal sequence of predicted outputs')
grid
subplot(2,1,2)
stairs(topt,uopt)
title('Optimal sequence of manipulated variables')
grid
3-79
3 Design MPC Controllers
When the constraints are not active, the MPC controller behaves like a linear controller.
You can get the state-space form of the MPC controller.
LTI = ss(mpcobj,'rv');
[AL,BL,CL,DL] = ssdata(LTI);
Simulate linear MPC closed-loop system and compare the linearized MPC controller with
the original MPC controller with constraints turned off.
3-80
Control of a Multi-Input Single-Output Plant
for t=0:round(Tstop/Ts)-1
disp(dispStr{t+1});
end
3-81
3 Design MPC Controllers
figure
plot(0:Ts:Tstop-Ts,YY)
grid
3-82
Control of a Multi-Input Single-Output Plant
Running a closed-loop where all constraints are turned off is easy using sim. We just
specify an option in the SimOptions structure:
SimOptions = mpcsimopt(mpcobj);
SimOptions.Constr = 'off'; % Remove all MPC constraints
SimOptions.Unmeas = d; % unmeasured input disturbance
sim(mpcobj,Tf,r,v,SimOptions);
3-83
3 Design MPC Controllers
3-84
Control of a Multi-Input Single-Output Plant
if ~mpcchecktoolboxinstalled('simulink')
disp('Simulink(R) is required to run this part of the example.')
return
end
mpcobj = mpc(model,Ts,10,3);
mpcobj.MV = struct('Min',0,'Max',1,'RateMin',-10,'RateMax',10);
mpcobj.Model.Disturbance = tf(sqrt(1000),[1 0]);
3-85
3 Design MPC Controllers
[A,B,C,D] = ssdata(sys);
mdl1 = 'mpc_miso';
open_system(mdl1)
sim(mdl1)
3-86
Control of a Multi-Input Single-Output Plant
3-87
3 Design MPC Controllers
3-88
Control of a Multi-Input Single-Output Plant
3-89
3 Design MPC Controllers
3-90
Control of a Multi-Input Single-Output Plant
Next, run a simulation with sinusoidal output noise. Assume output measurements are
affected by a sinusoidal measurement noise of frequency 0.1 Hz. You want to inform the
MPC object about this so that state estimates can be improved.
omega = 2*pi/10;
mpcobj.Model.Noise = 0.5*tf(omega^2,[1 0 omega^2]);
Revise the MPC design and specify a white Gaussian noise unmeasured disturbance with
zero mean and variance 0.1.
mpcobj.Model.Disturbance = tf(0.1);
mpcobj.weights = struct('MV',0,'MVRate',0.1,'OV',0.005);
mpcobj.predictionhorizon = 40;
mpcobj.controlhorizon = 3;
Tstop = 150;
mdl2 = 'mpc_misonoise';
open_system(mdl2)
sim(mdl2,Tstop)
3-91
3 Design MPC Controllers
3-92
Control of a Multi-Input Single-Output Plant
3-93
3 Design MPC Controllers
3-94
Control of a Multi-Input Single-Output Plant
3-95
3 Design MPC Controllers
bdclose(mdl1)
bdclose(mdl2)
See Also
MPC Controller | MPC Designer | mpc
More About
• “Control of a Single-Input-Single-Output Plant” on page 3-60
• “Control of a Multi-Input Multi-Output Nonlinear Plant” on page 3-97
3-96
Control of a Multi-Input Multi-Output Nonlinear Plant
To run this example, Simulink® and Simulink Control Design™ are required.
if ~mpcchecktoolboxinstalled('simulink')
disp('Simulink(R) is required to run this example.')
return
end
if ~mpcchecktoolboxinstalled('slcontrol')
disp('Simulink Control Design(R) is required to run this example.')
return
end
Create the controller object with sampling period, prediction and control horizons:
Ts = 0.2;
p = 5;
m = 2;
mpcobj = mpc(plant,Ts,p,m);
Specify MV constraints.
3-97
3 Design MPC Controllers
mpcobj.MV = struct('Min',{-3;-2;-2},'Max',{3;2;2},'RateMin',{-1000;-1000;-1000});
Run simulation.
mdl1 = 'mpc_nonlinear';
open_system(mdl1)
sim(mdl1)
3-98
Control of a Multi-Input Multi-Output Nonlinear Plant
3-99
3 Design MPC Controllers
3-100
Control of a Multi-Input Multi-Output Nonlinear Plant
Run simulation.
mdl2 = 'mpc_nonlinear_setoutdist';
open_system(mdl2)
sim(mdl2)
3-101
3 Design MPC Controllers
3-102
Control of a Multi-Input Multi-Output Nonlinear Plant
When the constraints are not active, the MPC controller behaves like a linear controller.
mpcobj.MV = [];
setoutdist(mpcobj,'integrators');
The input to the linear controller LTI is the vector [ym;r], where ym is the vector of
measured outputs, and r is the vector of output references.
LTI = ss(mpcobj,'r');
Run simulation.
3-103
3 Design MPC Controllers
3-104
Control of a Multi-Input Multi-Output Nonlinear Plant
3-105
3 Design MPC Controllers
bdclose(mdl1)
bdclose(mdl2)
bdclose(mdl3)
See Also
MPC Controller | MPC Designer | mpc
More About
• “Control of a Single-Input-Single-Output Plant” on page 3-60
• “Control of a Multi-Input Single-Output Plant” on page 3-63
3-106
To linearize a Simulink model using MPC Designer, first open the Simulink model containing the MPC Controller block and open MPC Designer from its Block Parameters dialog . Define the plant input/output structure by assigning signal lines corresponding to each MPC signal type, including manipulated variables and measured/unmeasured disturbances . Specify operating points for linearization in the Simulink Operating Point section using steady-state conditions or simulation snapshots . Click 'Linearize Model' to linearize the model at the selected operating point, which uses these inputs/outputs as nominal values . The linearized plant is then used within the MPC Designer for controller design, integrating both modeling and controller design steps .
Specifying a sample time in an MPC controller ensures that the controller operates using a consistent time interval for calculations, enabling the conversion of continuous-time models to discrete-time for state-space representation, and aligning the model's time domain with the controller's . Defining input/output signal dimensions allows for correct integration and configuration of signal channels, such as manipulated variables and disturbances, ensuring that all signals match the expected structure and facilitating model linearization and control design in Simulink . This setup is crucial for accurate model predictive control and simulation results, as it influences delay handling, scaling of signal variables, and the detection of signal paths in the linearized model ."}
Simulating closed-loop MPC responses under noise conditions involves defining and incorporating disturbance and noise models into the control system and analyzing the output performance. Different noise types, such as white Gaussian noise or sinusoidal noise, provide insight into how random fluctuations and periodic disturbances affect the system, respectively. Sinusoidal measurement noise is particularly insightful for assessing periodic interference impacts on state estimation and control actions. In refining an MPC design, sinusoidal noise helps adjust noise models like `mpcobj.Model.Noise` in the MPC object, ensuring robust filters and estimators are set to handle such explicit noise forms . Incorporating these elements enhances the controller's ability to maintain performance and stability in noisy operational settings.
In Simulink models, when connecting measured disturbances for linearization, it is necessary to link the plants' input ports with the md port of the MPC Controller block. Measured disturbances must be represented as input signals so that MPC Designer can detect and utilize them as plant inputs during linearization . For multiple disturbances, a vector signal representing all disturbances is used . This connection is crucial for accurately modeling disturbance impacts and for validating control strategies within MPC, as disturbances can significantly alter system dynamics and affect the performance and robustness of the controller.
Setting constraints on manipulated variables within a Model Predictive Control (MPC) framework is crucial for ensuring that the control actions remain within feasible operational limits, thus safeguarding the system against dangerous or inefficient states. Constraints can include limits on the range of manipulated variables and their rates of change, which help in maintaining system stability and performance . In Simulink, such constraints are configured by accessing the Constraints dialog within the MPC Designer. Here, you can specify the minimum and maximum bounds as well as the rate of change limits for the manipulated variables, ensuring that their behavior aligns with the operational requirements of the process . Soft constraints can also be used, allowing for controlled violation of these limits if needed to maintain other control objectives, thereby offering a balance between different control goals . These constraints and settings can be dynamically adjusted during runtime to reflect changes in system dynamics or control priorities ."}
When handling multiple operating points for model linearization, MPC Designer provides options to linearize the model at all specified operating points or just the first one, depending on the dialog box used to initiate the process. If multiple operating points are selected from the Define MPC Structure By Linearization dialog box, only the first operating point is used, whereas selecting from the Linearize Simulink Model dialog box linearizes the model at all specified points in order . The linearized plant models are sequentially added to the Data Browser, affecting simulation results by capturing different system dynamics or conditions that can be analyzed for their impact on controller performance . This allows for robust testing and validation of the controller under various scenarios.
Specifying operating point-based nominal values enhances the design of an MPC controller in Simulink by allowing the controller to use the input/output signal values at a defined operating point as baseline conditions. This can improve the accuracy of the linearization process, ensuring that the linear model closely approximates the nonlinear plant behavior under specific conditions. This alignment facilitates better performance by using the appropriate steady-state values as reference points, thereby reducing modeling errors and improving the controller's response to disturbances. When multiple operating points are used, the nominal values are updated based on the first operating point, ensuring consistency with the initial system conditions . By starting with accurate nominal conditions, the controller can better accommodate dynamic changes and maintain system stability .
The integrator model of unmeasured disturbances plays a critical role in Model Predictive Control (MPC) by allowing the controller to compensate for disturbances affecting the plant outputs that are not directly measured. It helps the controller predict the plant output trajectory in the presence of these disturbances, ensuring robust performance over time. In Simulink, to implement unmeasured disturbances, you augment the plant model by creating a state-space model where the unmeasured disturbances are modeled as persistent inputs. This augmented model includes an integrator or a static gain for each disturbance input and is imported into the MPC controller, allowing it to consider these disturbances when predicting future outputs . The default approach is adding integrators with unity gain unless doing so would invalidate state observability in the system .
The robustness of an MPC controller against model mismatch can be tested in Simulink by simulating a closed-loop system with a plant that has different characteristics than the model used by the controller. For instance, you can define a plant with 50% larger gains than those in the model used by the controller to evaluate the impact of the mismatch on controller performance . During testing, key parameters to adjust include manipulated variable constraints, prediction horizon, and control horizons, as well as the plant/model mismatch which can significantly degrade controller performance . Additionally, you can incorporate noise into the measured outputs or manipulated variables and examine how the controller handles these disturbances .
Varying the prediction and control horizons in a Model Predictive Control (MPC) controller affects the controller's ability to anticipate future disturbances and make corrective actions. A longer prediction horizon allows the controller to foresee potential future issues over a more extended period, potentially increasing control accuracy but also increasing computational demand. Conversely, a shorter horizon reduces the computational load but may not account for long-term effects as effectively . In Simulink, configuring these horizons is part of the controller setup process. You can specify prediction and control horizons using the MPC Designer by navigating to the Tuning tab and entering the desired values under the Horizon section. This adjustment can lead to changes in the output response plots, reflecting the controller's performance with different horizon settings .