linearize simulink models
generally, real systems are nonlinear. to design an mpc controller for a nonlinear system, you can model the plant in simulink®.
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
the following examples require simulink control design™ software.
you can linearize a simulink model:
from the command line.
using the model linearizer.
using mpc designer. for an example, see .
linearization using matlab code
this example shows how to obtain a linear model of a plant using a matlab script.
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.
obtain steady-state operating point
the operating point defines the nominal conditions at which you linearize a model. it is usually a steady-state condition.
suppose that you plan to operate the cstr with the output concentration, c_a
, at . the nominal feed concentration is , and the nominal feed temperature is 300 k.
create and visualize 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; opspec
opspec = operating point specification for the model cstr_openloop. (time-varying components evaluated at time t=0) states: ---------- x known steadystate min max dxmin dxmax ___________ ___________ ___________ ___________ ___________ ___________ ___________ (1.) cstr_openloop/cstr/c_a 8.5695 false true 0 inf -inf inf (2.) cstr_openloop/cstr/t_k 311.267 false true 0 inf -inf inf inputs: ---------- u known min max _____ _____ _____ _____ (1.) cstr_openloop/coolant temperature 0 false -inf inf outputs: ---------- y known min max _____ _____ _____ _____ (1.) cstr_openloop/cstr 2 true -inf inf
search for an operating point that satisfies the specifications.
op1 = findop('cstr_openloop',opspec);
operating point search report: ---------------------------------
opreport = operating point search report for the model cstr_openloop. (time-varying components evaluated at time t=0) operating point specifications were successfully met. states: ---------- min x max dxmin dx dxmax ___________ ___________ ___________ ___________ ___________ ___________ (1.) cstr_openloop/cstr/c_a 0 2 inf 0 -4.6683e-12 0 (2.) cstr_openloop/cstr/t_k 0 373.1311 inf 0 5.5678e-11 0 inputs: ---------- min u max ________ ________ ________ (1.) cstr_openloop/coolant temperature -inf 299.0349 inf outputs: ---------- min y max ___ ___ ___ (1.) cstr_openloop/cstr 2 2 2
the calculated operating point is c_a
= 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 input used to control the plant.
to specify:
values of known inputs, use the
input.known
andinput.u
fields ofopspec
initial guesses for state values, use the
state.x
field ofopspec
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)
operating point search report: ---------------------------------
opreport = operating point search report for the model cstr_openloop. (time-varying components evaluated at time t=0) operating point specifications were successfully met. states: ---------- min x max dxmin dx dxmax ___________ ___________ ___________ ___________ ___________ ___________ (1.) cstr_openloop/cstr/c_a 0 1.7787 inf 0 0 0 (2.) cstr_openloop/cstr/t_k 0 376.5371 inf 0 -9.9476e-14 0 inputs: ---------- min u max ___ ___ ___ (1.) cstr_openloop/coolant temperature 305 305 305 outputs: none ----------
op2 = operating point for the model cstr_openloop. (time-varying components evaluated at time t=0) states: ---------- x ________ (1.) cstr_openloop/cstr/c_a 1.7787 (2.) cstr_openloop/cstr/t_k 376.5371 inputs: ---------- u ___ (1.) cstr_openloop/coolant temperature 305
specify linearization inputs and outputs
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');
otherwise, specify the input and output signals as shown here.
io(1) = linio('cstr_openloop/coolant temperature',1,'input'); io(2) = linio('cstr_openloop/feed concentration',1,'input'); io(3) = linio('cstr_openloop/feed temperature',1,'input'); io(4) = linio('cstr_openloop/cstr',1,'output'); io(5) = linio('cstr_openloop/cstr',2,'output');
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 continuous-time state-space model.
linearize the model also around the operating point, op2
, using the same input/output signals.
sys = linearize('cstr_openloop',op2,io)
sys = a = c_a t_k c_a -5.622 -0.3458 t_k 55.1 2.822 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 continuous-time state-space model.
linearization using model linearizer in simulink control design
this example shows how to linearize a simulink model using the model linearizer, provided by the simulink control design software.
open simulink model
this example uses the cstr model, cstr_openloop
.
open_system('cstr_openloop')
specify linearization inputs and outputs
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 in the simulink apps tab, click linearization manager. then, in the simulink model window, click the signal. finally, in the insert analysis points gallery, in the closed loop section, select either input perturbation for a linearization input or output measurement for a linearization output.
open model linearizer
to open the model linearizer, in the apps tab, click model linearizer.
specify residual concentration as known trim constraint
to specify the residual concentration as a known trim constant, first in the
simulink
apps tab, click linearization manager. then,
in the simulink model window, click the ca
output signal from the
cstr
block. finally, in the insert analysis
points gallery, in the trim section, select
trim output constraint.
in the model linearizer, on the linear analysis tab, select operating point > trim model.
in the trim the model dialog box, on the outputs tab:
select the known check box for
channel - 1
under cstr_openloop/cstr.set the corresponding value to
2
kmol/m3.
create and verify operating point
in the trim the model dialog box, click start trimming.
the trim progress viewer window opens up showing the optimization progress towards finding a point in the state-input space of the model with the characteristics specified in the states, inputs, and outputs tabs. after the optimization process terminates, close the trim progress window as well as the trim the model dialog box.
the operating point op_trim1
displays in the linear
analysis workspace of model linearizer. select
op_trim1
to display basic information in the linear
analysis workspace section.
double click op_trim1
to view the resulting operating point in
the edit dialog box.
in the edit dialog box, select the input tab.
the coolant temperature at steady state is 299 k, as desired. close the edit dialog box.
linearize model
on the linear analysis tab, in the operating
point drop-down list, make sure op_trim1
is
selected.
in the linearize section, click step to linearize the simulink model and display the step response of the linearized model.
this option creates the linear model linsys1
in the
linear analysis workspace and generates a step response for this
model. linsys1
uses op_trim1
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.
export linearization result
if necessary, you can repeat any of these steps to improve your model performance. once you are satisfied with your linearization result, in the model linearizer, drag the linear model from the linear analysis workspace section of model linearizer to the matlab workspace section just above it. you can now use your linear model to design an mpc controller.
see also
apps
- (simulink control design) | mpc designer
functions
- (simulink control design)