You are on page 1of 250

Computa tion

Visua liza tion


Progra mming
For Use with MATLAB

Model Predictive Control


Toolbox
Users Guide
Version 1
Manfred Morari
N. LawrenceRicker
How to Contact The M a thW orks:
508-647-7000 Phone
508-647-7001 Fax
The MathWorks, I nc. Mai l
3 Appl e Hi l l Dri ve
Nati ck, MA 01760-2098
ht t p: //www. mat hwor ks . c om Web
f t p. mat hwor ks . com Anonymous FTP server
comp. s of t - s y s . mat l ab Newsgroup
s uppor t @mat hwor ks . c om Techni cal support
s ugge s t @mat hwor ks . c om Product enhancement suggesti ons
bugs @mat hwor ks . c om Bug reports
doc @mat hwor ks . com Documentati on error reports
s ubs c r i be @mat hwor ks . com Subscri bi ng user regi strati on
s e r v i c e@mat hwor ks . c om Order status, l i cense renewal s, passcodes
i nf o@mat hwor ks . c om Sal es, pri ci ng, and general i nformati on
Model PredictiveControl Toolbox Users Guide
COPYRI GHT 1995 - 1998 by The MathWor ks, I nc.
The softwar e descr i bed i n thi s document i s fur ni shed under a l i cense agreement. The software may be used
or copi ed onl y under the terms of the l i cense agr eement. No par t of thi s manual may be photocopi ed or r epr o-
duced i n any for m wi thout pr i or wr i tten consent from The MathWor ks, I nc.
FEDERAL ACQUI SI TI ON: Thi s provi si on appl i es to al l acqui si ti ons of the Progr am and Documentati on by
or for the feder al gover nment of the Uni ted States. By accepti ng del i very of the Pr ogram, the government
her eby agr ees that thi s softwar e qual i fi es as "commerci al "computer softwar e wi thi n the meani ng of FAR
Par t 12.212, DFARS Par t 227.7202-1, DFARS Part 227.7202-3, DFARS Par t 252.227-7013, and DFARS Par t
252.227-7014. The ter ms and condi ti ons of The MathWorks, I nc. Softwar e Li cense Agr eement shal l pertai n
to the gover nments use and di scl osur e of the Pr ogram and Documentati on, and shal l super sede any
confl i cti ng contractual ter ms or condi ti ons. I f thi s l i cense fai l s to meet the gover nments mi ni mum needs or
i s i nconsi stent i n any r espect wi th federal pr ocur ement l aw, the gover nment agr ees to r eturn the Progr am
and Documentati on, unused, to MathWor ks.
MATLAB, Si mul i nk, Statefl ow, Handl e Gr aphi cs, and Real -Ti me Wor kshop ar e r egi stered trademar ks, and
Tar get Language Compi l er i s a tr ademark of The MathWor ks, I nc.
Other pr oduct or br and names are tr ademar ks or r egi stered tr ademar ks of thei r respecti ve hol der s.
Pri nti ng Hi story: January 1995 Fi r st pri nti ng
October 1998 Revi sed (Onl i ne onl y)
i
Contents
Preface
1
Tutorial
Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-2
Target Audi ence for the MPC Tool box . . . . . . . . . . . . . . . . . . . . 1-3
System Requi rements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-3
2
MPC Based on Step ResponseModels
Step ResponseModels . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-2
Model Identification . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-6
Unconstrained Model PredictiveControl . . . . . . . . . . . . . . 2-11
Closed-Loop Analysis . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-18
Constrained Model PredictiveControl . . . . . . . . . . . . . . . . . 2-20
Application: IdleSpeed Control . . . . . . . . . . . . . . . . . . . . . . . 2-22
Process Descri pti on . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-22
Control Probl em Formul ati on . . . . . . . . . . . . . . . . . . . . . . . . . . 2-22
Si mul ati ons . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-24
Application: Control of a Fluid Catalytic CrackingUnit . 2-31
Process Descri pti on . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-31
Control Probl em Formul ati on . . . . . . . . . . . . . . . . . . . . . . . . . . 2-33
ii Contents
Si mul ati ons . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-34
Step Response Model . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-34
Associ ated Vari abl es . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-36
Unconstrai ned Control Law . . . . . . . . . . . . . . . . . . . . . . . . . 2-36
Constrai ned Control Law . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-36
3
MPC Based on State-SpaceModels
State-SpaceModels . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-2
Mod Format . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-3
SI SO Conti nuous-Ti me Transfer Functi on to Mod Format . . . . 3-3
SI SO Di screte-Ti me Transfer Functi on to Mod Format . . . . . . 3-6
MI MO Transfer Functi on Descri pti on to Mod Format . . . . . . . 3-7
Conti nuous or Di screte State-Space to Mod Format . . . . . . . . . 3-9
I denti fi cati on Tool box (Theta) Format to Mod Format . . . . . . 3-9
Combi nati on of Model s i n Mod Format . . . . . . . . . . . . . . . . . . 3-10
Converti ng Mod Format to Other Model Formats . . . . . . . . . . 3-10
Unconstrained MPC UsingState-SpaceModels . . . . . . . . . 3-12
State-SpaceMPC with Constraints . . . . . . . . . . . . . . . . . . . . 3-20
Application: Paper MachineHeadbox Control . . . . . . . . . . 3-26
MPC Desi gn Based on Nomi nal Li near Model . . . . . . . . . . . . . 3-27
MPC of Nonl i near Pl ant . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-38
4
Command Reference
Commands Grouped by Function . . . . . . . . . . . . . . . . . . . . . . . 4-2
Index
Preface
Preface
iv
Acknowledgments
The tool box was devel oped i n cooperati on wi th: Dougl as B. Raven and Al ex
Zheng
The contri buti ons of the fol l owi ng peopl e are acknowl edged: Yaman Arkun,
Ni kol aos Beki ari s, Ri chard D. Braatz, Marc S. Gel ormi no, Evel i o Hernandez,
Tyl er R. Hol comb, I fti khar Huq, Sameer M. Jal napurkar, Jay H. Lee, Yusha
Li u, Si mone L. Ol i vei ra, Argi mi ro R. Secchi , and Shwu-Yi en Yang
We woul d l i ke to thank Li z Cal l anan, Ji m Tung and Wes Wang from the
MathWorks for assi sti ng us wi th the project, and Patri ci a New who di d such
an excel l ent job putti ng the manuscri pt i nto LATEX.
About the Authors
v
About the Authors
Manfred Morari
Manfred Morari recei ved hi s di pl oma from ETH Zuri ch i n 1974 and hi s Ph.D.
from the Uni versi ty of Mi nnesota i n 1977, both i n chemi cal engi neeri ng.
Currentl y he i s the McCol l um-Corcoran Professor and Executi ve Offi cer for
Control and Dynami cal Systems at the Cal i forni a I nsti tute of Technol ogy.
Morari s research i nterests are i n the areas of process control and desi gn. I n
recogni ti on of hi s numerous contri buti ons, he has recei ved the Donal d P.
Eckman Award of the Automati c Control Counci l , the Al l an P. Col burn Award
of the AI ChE, the Curti s W. McGraw Research Award of the ASEE, was a Case
Vi si ti ng Schol ar, the Gul f Vi si ti ng Professor at Carnegi e Mel l on Uni versi ty
and was recentl y el ected to the Nati onal Academy of Engi neeri ng. Dr. Morari
has hel d appoi ntments wi th Exxon R&E and I CI and has consul ted
i nternati onal l y for a number of major corporati ons. He has coauthored one
book on Robust Process Control wi th another on Model Predi cti ve Control i n
preparati on.
N. Lawrence Ricker
Larry Ri cker recei ved hi s B.S. degree from the Uni versi ty of Mi chi gan i n 1970,
and hi s M.S. and Ph.D. degrees from the Uni versi ty of Cal i forni a, Berkel ey, i n
1972/78. Al l are i n Chemi cal Engi neeri ng. He i s currentl y Professor of
Chemi cal Engi neeri ng at the Uni versi ty of Washi ngton, Seattl e. Dr. Ri cker has
over 80 publ i cati ons i n the general area of chemi cal pl ant desi gn and operati on.
He has been acti ve i n Model Predi cti ve Control research and teachi ng for more
than a decade. For exampl e, he publ i shed one of the fi rst nonpropri etary
studi es of the appl i cati on of MPC to an i ndustri al process, and i s currentl y
i nvol ved i n a l arge-scal e MPC appl i cati on i nvol vi ng more than 40 deci si on
vari abl es.
Preface
vi
1
Tutori al
1 Tutori al
1-2
Introduction
The Model Predi cti ve Control (MPC) Tool box i s a col l ecti on of functi ons
(commands) devel oped for the anal ysi s and desi gn of model predi cti ve control
(MPC) systems. Model predi cti ve control was concei ved i n the 1970s pri mari l y
by i ndustry. I ts popul ari ty steadi l y i ncreased throughout the 1980s. At
present, there i s l i ttl e doubt that i t i s the most wi del y used mul ti vari abl e
control al gori thm i n the chemi cal process i ndustri es and i n other areas. Whi l e
MPC i s sui tabl e for al most any ki nd of probl em, i t di spl ays i ts mai n strength
when appl i ed to probl ems wi th:
A l arge number of mani pul ated and control l ed vari abl es
Constrai nts i mposed on both the mani pul ated and contr ol l ed var i abl es
Changi ng control objecti ves and/or equi pment (sensor/actuator) fai l ure
Ti me del ays
Some of the popul ar names associ ated wi th model predi cti ve control are
Dynami c Matri x Control (DMC), I DCOM, model al gori thmi c control , etc. Whi l e
these al gori thms di ffer i n certai n detai l s, the mai n i deas behi nd them are very
si mi l ar. I ndeed, i n i ts basi c unconstrai ned form MPC i s cl osel y rel ated to l i near
quadrati c opti mal control . I n the constrai ned case, however, MPC l eads to an
opti mi zati on probl em whi ch i s sol ved on-l i ne i n real ti me at each sampl i ng
i nterval . MPC takes ful l advantage of the power avai l abl e i n todays control
computer hardware.
Thi s software and the accompanyi ng manual are not i ntended to teach the user
the basi c i deas behi nd MPC. Background materi al i s avai l abl e i n standard
textbooks l i ke those authored by Seborg, Edgar and Mel l i champ (1989)
1
,
Deshpande and Ash (1988)
2
and the monograph devoted sol el y to thi s topi c
authored by Morari and coworkers (Morari et al ., 1994)
3
. Thi s secti on provi des
a basi c i ntroducti on to the mai n i deas behi nd MPC and the speci fi c form of
i mpl ementati on chosen for thi s tool box. The al gori thms used here are
consi stent wi th those descri bed i n the monograph by Morari et al . I ndeed, the
software i s meant to accompany the monograph and vi ce versa. The routi nes
i ncl uded i n the MPC Tool box fal l i nto two basi c categori es: routi nes whi ch use
1. D.E. Seborg, T.F. Edgar , D.A. Mel l i champ; Process Dynamics and Control; JohnWi l ey & Sons,
1989
2. P.B. Deshpande, R.H. Ash; Computer Process Control with Advanced Control Applications,
2nd ed., I SA, 1988
3. M. Morar i , C.E. Gar ci a, J.H. Lee, D.M. Pr ett; Model PredictiveControl; Prenti ce Hal l , 1994
(I n the process of bei ng wr i tten.)
Introducti on
1-3
a step response model descri pti on and routi nes whi ch use a state-space model
descri pti on. I n addi ti on, si mpl e i denti fi cati on tool s are provi ded for i denti fyi ng
step response model s from pl ant data. Fi nal l y, there are al so vari ous
conversi on routi nes whi ch convert between di fferent model formats and
anal ysi s routi nes whi ch can ai d i n determi ni ng the stabi l i ty of the
unconstrai ned system, etc. Al l MPC Tool box commands have a bui l t-i n usage
di spl ay. Any command cal l ed wi th no i nput arguments resul ts i n a bri ef
descri pti on of the command l i ne. For exampl e, typi ng mpccon at the command
l i ne gi ves the fol l owi ng:
us age: Kmpc = mpccon( mode l , y wt , uwt , M, P)
The fol l owi ng secti ons i ncl ude several exampl es. They are avai l abl e i n the
tutori al programs mpct ut . m, mpct ut i d. m, mpct ut s t . m, and mpct ut s s . m. You
can copy these demo fi l es from the mpct ool s /mpcdemos source i nto a l ocal
di rectory and exami ne the effects of modi fyi ng some of the commands.
Target Audience for the MPC Toolbox
The package i s i ntended for the cl assroom and for the practi ci ng engi neer. I t
can assi st i n communi cati ng the concepts of MPC to a student i n an
i ntroductory control course. At the same ti me i t i s sophi sti cated enough to
al l ow an engi neer i n i ndustry to eval uate al ternate control strategi es i n
si mul ati on studi es.
System Requirements
The MPC Tool box assumes the fol l owi ng operati ng system requi rements:
MATLAB

i s runni ng on your system.


I f nonl i near systems are to be si mul ated, Si mul i nk

i s requi red for the


functi ons nl cmpc and nl mpcs i m.
I f the theta format from the System I denti fi cati on Tool box i s to be used to
create model s i n the MPC mod format (usi ng the MPC Tool box functi on,
t h2mod), then the System I denti fi cati on Tool box functi on pol y f or mand the
Control System Tool box functi on appe nd are requi red.
1 Tutori al
1-4
The MPC Tool box anal ysi s and si mul ati on al gori thms are numeri cal l y
i ntensi ve and requi re approxi matel y 1MB of memory, dependi ng on the
number of i nputs and outputs. The avai l abl e memory on your computer may
l i mi t the si ze of the systems handl ed by the MPC Tool box.
Note: there i s a pack command i n MATLAB that can hel p free memory space
by compacti ng fragmented memory l ocati ons. For reasonabl e response ti mes,
a computer wi th power equi val ent to an 80386 machi ne i s recommended
unl ess onl y si mpl e tutori al exampl e probl ems are of i nterest.
2
MPC Based on Step
Response Model s
2 M PC Based on Step Response M odels
2-2
Step Response Models
Step response model s are based on the fol l owi ng i dea. Assume that the system
i s at rest. For a l i near ti me-i nvari ant si ngl e-i nput si ngl e-output (SI SO) system
l et the output change for a uni t i nput change v be gi ven by
{0, s
1
, s
2
, . . . , s
n
, s
n
, . . .}
Here we assume that the system settl es exactl y after nsteps. The step response
{s
1
, s
2
, . . . , s
n
}consti tutes a compl ete model of the system, whi ch al l ows us to
compute the system output for any i nput sequence:
Step response model s can be used for both stabl e and i ntegrati ng processes. For
an i ntegrati ng process i t i s assumed that the sl ope of the response remai ns
constant after n steps, i .e.,
s
n
s
n 1
= s
n + 1
s
n
= s
n + 2
s
n + 1
= . . .
For a mul ti -i nput mul ti -output (MI MO) process wi th n
v
i nputs and n
y
outputs,
one obtai ns a seri es of step response coeffi ci ent matri ces
where s
l,m,i
i s the i
th
step response coeffi ci ent rel ati ng the m
th
i nput to the l
th
output.
y k ( ) s
i
v k i ( )
i 1 =
n

s
n
v k n 1 ( ) + =
S
i
s
1 1 i , ,
s
1 2 i , ,
s
1 n
v
i , ,
s
2 1 i , ,
s
n
y
1 i , ,
s
n
y
2 i , ,
s
n
y
n
v
i , ,
=

Step Response M odels


2-3
The MPC Tool box stores step response model s i n the fol l owi ng format:
where del t 2 i s the sampl i ng ti me and the vector nout i ndi cates i f a parti cul ar
output i s i ntegrati ng or not:
nout ( i ) = 0 i f output i i s i ntegrati ng.
nout ( i ) = 1 i f output i i s stabl e.
The step response can be obtai ned di rectl y from i denti fi cati on experi ments, or
generated from a conti nuous or di screte transfer functi on or state-space model .
For exampl e, i f the di screte system descri pti on (sampl i ng ti me T = 0.1) i s
y(k) = 0.5y(k 1) + v(k 3)
then the transfer functi on i s
plant
S
1
S
2
S
n
nout(1) 0 0
nout(2) 0 0
nout n
y
( ) 0 0
n
y
0 0
delt2 0 0
n n
y
n
y
2 + + ( ) n
v


g z ( )
z
3
1 0.5z
1
+
-------------------------- =
2 M PC Based on Step Response M odels
2-4
The fol l owi ng commands (see mpct ut . m) generate the step response model for
thi s system and pl ot i t:
num = 1;
den = [ 1 0. 5] ;
del t 1 = 0. 1;
del ay = 2;
g = pol y 2t f d( num, den, del t 1, del ay ) ;
% Set up t he model i n t f f or mat
t f i nal = 1. 6;
del t 2 = del t 1;
nout = 1;
pl ant = t f d2s t ep( t f i nal , del t 2, nout , g) ;
% Cal cul at e t he s t ep r es pons e
pl ot s t ep( pl ant ) % Pl ot t he s t ep r es pons e
0 0.2 0.4 0.6 0.8 1 1.2 1.4 1.6
0
0.1
0.2
0.3
0.4
0.5
0.6
0.7
0.8
0.9
1
u1 step response : y1
TIME
Step Response M odels
2-5
Al ternati vel y, we coul d fi rst generate a state-space descri pti on appl yi ng the
command t f 2s s and then generate the step response wi th s s 2s t ep. I n thi s
case, we need to pad the numerator and denomi nator pol ynomi al s to account
for the ti me del ay.
num = [ 0 0 0 num] ;
den = [ den 0 0] ;
[ phi , gam, c, d] = t f 2s s ( num, den) ; % Conv er t t o s t at e- s pace
pl ant = s s 2s t e p( phi , gam, c , d, t f i nal , de l t 1, del t 2, nout ) ;
% Cal cul at e s t ep r es pons e
We can get some i nformati on on the contents of a matri x i n the MPC Tool box
vi a the command mpci nf o. For our exampl e, mpci nf o( pl ant ) returns:
Thi s i s a mat r i x i n MPC St ep f or mat .
s ampl i ng t i me = 0. 1
number of i nput s = 1
number of out put s = 1
number of s t ep r es pons e c oef f i ci ent s = 16
Al l out put s ar e s t abl e.
2 M PC Based on Step Response M odels
2-6
Model Identification
The i denti fi cati on routi nes avai l abl e i n the MPC Tool box are desi gned for
mul ti -i nput si ngl e-output (MI SO) systems. Based on a hi stori cal record of the
output y
l
(k) and the i nputs v
1
(k); v
2
(k), . . . , (k),
the step response coeffi ci ents
are esti mated. For the esti mati on of the step response coeffi ci ents we wri te the
SI SO model i n the form
where
y(k) = y(k) y(k 1)
and
h
i
= s
i
s
i 1
v
n
v
yy
l
y
l
1 ( )
y
l
2 ( )
y
l
3 ( )
=

v
v
1
1 ( ) v
2
1 ( ) v
n
v
1 ( )
v
1
2 ( ) v
2
2 ( ) v
n
v
2 ( )
v
1
3 ( ) v
2
3 ( ) v
n
v
3 ( )
=

s
l 1 1 , ,
s
l 2 1 , ,
s
l n
v
1 , ,
s
l 1 2 , ,
s
l 2 2 , ,
s
l n
v
2 , ,
s
l 1 i , ,
s
l 2 i , ,
s
l n
v
i , ,

y k ( ) h
i
v k i ( )
i 1 =
n

=
M odel Identi fi cati on
2-7
h
i
are the i mpul se response coeffi ci ents. Thi s model al l ows the desi gner to
present al l the i nput (v) and output(y
l
) i nformati on i n devi ati on form, whi ch i s
often desi rabl e. I f the parti cul ar output i s i ntegrati ng, then the model
where
(y(k)) = y(k) y(k 1)
h
i
= h
i
h
i 1
shoul d be used to esti mate h
i
, and thus h
i
and s
i
are gi ven by
For parameter esti mati on i t i s usual l y recommended to scal e al l the vari abl es
such that they are the same order of magni tude. Thi s may be done vi a the MPC
Tool box functi ons aut os c or s cal . Then the data has to be arranged i nto the
form
Y = X
where Y contai ns al l the output i nformati on (y(k) for stabl e and (y(k)) for
i ntegrati ng outputs) and X al l the i nput i nformati on (v(k)) appropri atel y
arranged. i s a vector i ncl udi ng al l the parameters to be esti mated (h
i
for
stabl e and h
i
for i ntegrati ng outputs). Thi s rearrangement of the i nput and
output i nformati on i s handl ed by wr t r eg. The parameters can be esti mated
vi a mul ti vari abl e l east squares regressi on (ml r ) or parti al l east squares (pl s r ).
Fi nal l y, the step response model i s generated from the i mpul se response
coeffi ci ents vi a i mp2s t ep. The fol l owi ng exampl e (see mpct ut i d)i l l ustrates thi s
procedure.
y k ( ) ( ) h
i
v k i ( )
i 1 =
n

=
h
i
h
k
k 1 =
i

=
s
i
h
j
j 1 =
i

h
k
k 1 =
j

j 1 =
i

= =
2 M PC Based on Step Response M odels
2-8
Example:
% Load t he i nput and out put dat a. The i nput and out put
% dat a ar e gener at ed f r om t he f ol l owi ng t r ans f er
% f unct i ons and r andom z er o- mean noi s es .
% TF f r om i nput 1 t o out put 1: g11=5. 72ex p( - 14s ) /
% ( 60s +1)
% TF f r om i nput 2 t o out put 1: g12=1. 52ex p( - 15s ) /
% ( 25s +1)
% Sampl i ng t i me of 7 mi nut es was us ed.
%
% l oad ml r dat
%
% Det er mi ne t he s t andar d dev i at i ons f or i nput dat a us i ng
% aut os c .
[ ax , mx , s t dx ] =aut os c( x ) ;
%
% Scal e t he i nput dat a by t hei r s t andar d dev i at i ons onl y .
mx =0*mx ;
s x =s cal ( x , mx , s t dx ) ;
%
% Put t he i nput and out put dat a i n a f or m s uch t hat t hey
% can be us ed t o det er mi ne t he i mpul s e r es pons e
% coef f i ci ent s . 35 c oef f i ci ent s ( n) ar e us ed.
n=35;
[ x r eg, y r eg] =wr t r eg( s x , y , n) ;
%
% Det er mi ne t he i mpul s e r es pons e coef f i ci e nt s v i a ml r .
% By s pe ci f y i ng pl ot opt =2, t wo pl ot s pl ot of pr edi ct e d
% out put and act ual out put , and pl ot of t he out put
% r es i dual ( or pr edi ct i on er r or ) ar e pr oduced.
ni nput =2; pl ot opt =2;
[ t het a, y r es ] =ml r ( x r e g, y r eg, ni nput , pl ot opt ) ;
M odel Identi fi cati on
2-9
% Scal e t het a bas ed on t he s t andar d dev i at i ons us ed i n
% s cal i ng t he i nput .
t he t a=s cal ( t he t a, mx , s t dx ) ;
%
% Conv er t t he i mpul s e model t o a s t ep model t o be us ed
% i n MPC des i gn.
% Sampl i ng t i me of 7 mi nut es was us ed i n det er mi ni ng
% t he i mpul s e model .
% Number of out put s ( 1 i n t hi s cas e) mus t be s pe ci f i ed.
nout =1;
del t =7;
model =i mp2s t ep( del t , nout , t het a) ;
%
% Pl ot t he s t e p r es pons e.
pl ot s t ep( model )
0 20 40 60 80 100 120 140 160 180
6
4
2
0
2
4
Actual value (o) versus Predicted Value (+)
Sample Number
O
u
t
p
u
t
0 20 40 60 80 100 120 140 160 180
0.4
0.3
0.2
0.1
0
0.1
0.2
0.3
Output Residual or Prediction Error
Sample Number
R
e
s
i
d
u
a
l
2 M PC Based on Step Response M odels
2-10
0 50 100 150 200 250
0
1
2
3
4
5
6
u1 step response : y1
TIME
0 50 100 150 200 250
0.2
0
0.2
0.4
0.6
0.8
1
1.2
1.4
1.6
1.8
u2 step response : y1
TIME
Unconstrai ned M odel Predi cti ve C ontrol
2-11
Unconstrained Model Predictive Control
The MPC control l aw can be most easi l y deri ved by referri ng to the fol l owi ng
fi gure.
For any assumed set of present and future control moves u(k), u(k + 1),
. . . , u(k + m 1) the future behavi or of the process outputs y(k + 1| k),
y(k +2| k), . . . , y(k +p| k) can be predi cted over a hori zon p. The mpresent and
future control moves (m p) are computed to mi ni mi ze a quadrati c objecti ve of
the form
Here and are wei ghti ng matri ces to penal i ze parti cul ar components of
y or u at certai n future ti me i nterval s. r(k + l) i s the (possi bl y ti me-varyi ng)
vector of future reference val ues (setpoi nts). Though mcontrol moves are
cal cul ated, onl y the fi rst one (u(k)) i s i mpl emented. At the next sampl i ng
i nterval , new val ues of the measured output are obtai ned, the control hori zon
i s shi fted forward by one step, and the same computati ons are repeated. The
resul ti ng control l aw i s referred to as movi ng hori zon or recedi ng hori zon.
future past
target
u(k)
k+p k
k+1
k+2
horizon
y(k+1|k)
^
y
Projected
Manipulated
Variables
Outputs
mi n
u k ( )u k m 1 + ( )

l
y
y k l| k + ( ) r k l + ( ) [ ] ( )
2
l=1
p

+

l
u
u k l + 1 ( ) [ ]
2
l=1
m

l
y

l
u
2 M PC Based on Step Response M odels
2-12
The predi cted process outputs y(k + 1| k), . . . ,y(k + p| k) depend on the current
measurement and assumpti ons we make about the unmeasured
di sturbances and measurement noi se affecti ng the outputs. The MPC Tool box
assumes that the unmeasured di sturbances for each output are steps passi ng
through a fi rst order l ag wi th ti me constant t f i l t er ( 2, : ) .
1
For rejecti ng
measurement noi se, the ti me constant of an exponenti al fi l ter t f i l t er ( 1, : )
can be speci fi ed by the user. (I t can be shown that thi s procedure i s opti mal for
whi te noi se di sturbances passed through an i ntegrator and a fi rst order l ag,
and whi te measurement noi se). For conventi onal Dynami c Matri x Control
(DMC) the di sturbance ti me constant i s assumed to be zero
( t f i l t er ( 2, : ) = z er os ( 1, ny ) ) , i .e., the unmeasured di sturbances have the
form of steps, and the noi se fi l ter ti me constant i s al so set to zero
( t f i l t er ( 1, : ) = z er os ( 1, ny ) ) , i .e., there i s no measurement noi se fi l teri ng
for doi ng the predi cti on.
Under the stated assumpti ons, i t can be shown that a l i near ti me-i nvari ant
feedback control l aw resul ts
u(k) = K
MP C
E
p
(k + 1| k)
where E
p
(k + 1| k) i s the vector of predi cted future errors over the hori zon p
whi ch woul d resul t i f al l present and future mani pul ated vari abl e moves were
equal to zero u(k) = u(k + 1) = . . . = 0.
For open-l oop stabl e pl ants, nomi nal stabi l i ty of the cl osed-l oop system
depends onl y on K
MP C
whi ch i n turn i s affected by the hori zon p, the number
of moves mand the wei ghti ng matri ces and . No preci se condi ti ons on m,
p, and exi st whi ch guarantee cl osed-l oop stabi l i ty. I n general ,
decreasi ng mrel ati ve to p makes the control acti on l ess aggressi ve and tends
to stabi l i ze a system. For p = 1, nomi nal stabi l i ty of the cl osed-l oop system i s
guaranteed for any fi ni te m, and ti me-i nvari ant i nput and output wei ghts.
More commonl y, i s used as a tuni ng parameter. I ncreasi ng al ways has
the effect of maki ng the control acti on l ess aggressi ve.
The noi se fi l ter ti me constant t f i l t er ( 1, : ) and the di sturbance ti me constant
t f i l t er ( 2, : ) do not affect cl osed-l oop stabi l i ty or the response of the system
to setpoi nt changes or measured di sturbances. They do, however, affect the
robustness and the response to unmeasured di sturbances.
1. See cmpc i n the Refer ence secti on for detai l s on how to speci fy t f i l t er .
y k ( )

l
y

l
u

l
y

l
u

l
u

l
u
Unconstrai ned M odel Predi cti ve C ontrol
2-13
I ncreasi ng the noi se fi l ter ti me constant makes the system more robust and the
unmeasured di sturbance response more sl uggi sh. I ncreasi ng the di sturbance
ti me constant i ncreases the l ead i n the l oop, maki ng the control acti on
somewhat more aggressi ve, and i s recommended for di sturbances whi ch have
a sl ow effect on the output.
Al l control l ers desi gned wi th the MPC Tool box track steps asymptoti cal l y
error-free (Type 1). I f the unmeasured di sturbance model or the system i tsel f
i s i ntegrati ng, ramps are al so tracked error-free (Type 2).
Example: (see mpct ut s t . m)
% Pl ant t r ans f er f unct i on: g=5. 72ex p( - 14s ) /( 60s +1)
% Di s t ur bance t r ans f er f unct i on: gd=1. 52ex p( - 15s ) /
% ( 25s +1)
%
% Bui l d t he s t ep r es pons e model s f or a s ampl i ng per i od
% of 7.
del t 1=0;
del ay 1=14;
num1=5. 72;
den1=[ 60 1] ;
g=pol y 2t f d( num1, den1, del t 1, del ay 1) ;
t f i nal =245;
del t 2=7;
nout 1=1;
pl ant =t f d2s t ep( t f i nal , del t 2, nout 1, g) ;
del ay 2=15;
num2=1. 52;
den2=[ 25 1] ;
gd=pol y 2t f d( num2, den2, del t 1, del ay 2) ;
del t 2=7;
nout 2=1;
dpl ant =t f d2s t e p( t f i nal , de l t 2, nout 2, gd) ;
%
% Cal cul at e t he MPC cont r ol l er gai n mat r i x f or
% No pl ant /model mi s mat ch,
% Out put Wei ght =1, I nput Wei ght =0
% I nput Hor i z on=5, Out put Hor i z on=20
model =pl ant ;
y wt =1; uwt =0;
2 M PC Based on Step Response M odels
2-14
M=5; P=20;
Kmpc1=mpccon( model , y wt , uwt , M, P) ;
%
% Si mul at e and pl ot r es pons e f or unmeas ur e d and meas ur ed
% s t ep di s t ur bance t hr ough dpl ant .
t end=245;
r =[ ] ; us at =[ ] ; t f i l t er =[ ] ;
dmodel =[ ] ;
ds t ep=1;
[ y 1, u1] =mpcs i m( pl ant , model , Kmpc 1, t end, r , us at , t f i l t er , . . .
dpl ant , dmodel , ds t ep) ;
dmodel =dpl ant ; % meas ur ed di s t ur bance
[ y 2, u2] =mpcs i m( pl ant , model , Kmpc 1, t end, r , us at , t f i l t er , . . .
dpl ant , dmodel , ds t ep) ;
pl ot al l ( [ y 1, y 2] , [ u1, u2] , del t 2) ;
paus e; % Per f ect r ej ect i on f or meas ur ed di s t ur bance c as e.
%
% Cal cul at e a new MPC cont r ol l e r gai n mat r i x f or
% No pl ant /model mi s mat ch,
% Out put Wei ght =1, I nput Wei ght =10
0 50 100 150 200 250
0
0.2
0.4
0.6
0.8
1
Outputs
Time
0 50 100 150 200 250
0.7
0.6
0.5
0.4
0.3
0.2
0.1
0
Manipulated Variables
Time
Unconstrai ned M odel Predi cti ve C ontrol
2-15
% I nput Hor i z on=5, Out put Hor i z on=20
model =pl ant ;
y wt =1; uwt =10;
M=5; P=20;
mpc 2=mpccon( model , y wt , uwt , M, P) ;
%
% Si mul at e and pl ot r es pons e f or unme as ur ed and meas ur ed
% s t ep di s t ur bance t hr ough dpl ant .
t end=245;
r =[ ] ; us at =[ ] ; t f i l t e r =[ ] ;
dmodel =[ ] ;
ds t ep=1;
[ y 3, u3] =mpcs i m( pl ant , mode l , Kmpc2, t end, r , us at , t f i l t er , . . .
dpl ant , dmodel , ds t e p) ;
dmodel =dpl ant ; % meas ur ed di s t ur bance
[ y 4, u4] =mpcs i m( pl ant , mode l , Kmpc2, t end, r , us at , t f i l t er , . . .
dpl ant , dmodel , ds t e p) ;
pl ot al l ( [ y 3, y 4] , [ u3, u4] , del t 2) ;
paus e;
0 50 100 150 200 250
0.2
0
0.2
0.4
0.6
0.8
1
1.2
Outputs
Time
0 50 100 150 200 250
0.35
0.3
0.25
0.2
0.15
0.1
0.05
0
Manipulated Variables
Time
2 M PC Based on Step Response M odels
2-16
%
% Si mul at e and pl ot r es pons e f or unmeas ur e d
% s t ep di s t ur bance t hr ough dpl ant wi t h uwt =0,
% wi t h and wi t hout noi s e f i l t er i ng.
t end=245;
r =[ ] ; us at =[ ] ; dmodel =[ ] ;
t f i l t er =[ ] ;
ds t ep=1;
[ y 5, u5] =mpcs i m( pl ant , model , Kmpc 1, t end, r , us at , t f i l t er , . . .
dpl ant , dmodel , ds t ep) ;
t f i l t er =20; % noi s e f i l t er i ng t i me cons t ant =20
[ y 6, u6] =mpcs i m( pl ant , model , Kmpc 1, t end, r , us at , t f i l t er , . . .
dpl ant , dmodel , ds t ep) ;
pl ot al l ( [ y 5, y 6] , [ u5, u6] , del t 2) ;
paus e;
0 50 100 150 200 250
0
0.2
0.4
0.6
0.8
1
Outputs
Time
0 50 100 150 200 250
0.7
0.6
0.5
0.4
0.3
0.2
0.1
0
Manipulated Variables
Time
Unconstrai ned M odel Predi cti ve C ontrol
2-17
%
% Si mul at e and pl ot r es pons e f or unme as ur ed
% s t ep di s t ur bance t hr ough dpl ant wi t h uwt =0,
% wi t h and wi t hout unmeas ur ed di s t ur bance t i me c ons t ant
% bei ng s peci f i ed.
t end=245;
r =[ ] ; us at =[ ] ; dmodel =[ ] ;
t f i l t er =[ ] ;
ds t ep=1;
[ y 7, u7] =mpcs i m( pl ant , mode l , Kmpc1, t end, r , us at , t f i l t er , . . .
dpl ant , dmodel , ds t e p) ;
t f i l t er =[ 0; 25] ; % unmeas ur ed di s t ur bance t i me cons t ant =25
[ y 8, u8] =mpcs i m( pl ant , mode l , Kmpc1, t end, r , us at , t f i l t er , . . .
dpl ant , dmodel , ds t e p) ;
pl ot al l ( [ y 7, y 8] , [ u7, u8] , del t 2) ;
paus e;
0 50 100 150 200 250
0
0.2
0.4
0.6
0.8
1
Outputs
Time
0 50 100 150 200 250
1.5
1
0.5
0
Manipulated Variables
Time
2 M PC Based on Step Response M odels
2-18
Closed-Loop Analysis
Apart from si mul ati on, other tool s are avai l abl e i n the MPC Tool box to anal yze
the stabi l i ty and performance of a cl osed-l oop system. We can obtai n the
state-space descri pti on of the cl osed-l oop system wi th the command mpccl and
then determi ne the pol e l ocati ons wi th s mpc pol e.
Example: (mpct ut s t . m)
% Cons t r uct a cl os ed- l oop s y s t e m f or no di s t ur bances
% and uwt = 0. Det er mi ne t he pol es of t he s y s t em.
cl mod = mpccl ( pl ant , model , Kmpc1) ;
pol es = s mpcpol e( cl mod) ;
max pol e = max ( pol es )
Resul t i s: max pol e = 1. 0
The cl osed-l oop system i s stabl e i f al l the pol es are i nsi de or on the uni t-ci rcl e.
Furthermore we can exami ne the frequency response of the cl osed-l oop system.
For mul ti vari abl e systems, si ngul ar val ues as a functi on of frequency can be
obtai ned usi ng s v df r s p.
Example: (mpct ut s t . m)
% Cal cul at e and pl ot t he f r eque ncy r es pons e of t he
% s ens i t i v i t y and compl ement ar y s ens i t i v i t y f unct i ons .
f r eq = [ - 3, 0, 30] ;
ny = 1;
i n = [ 1: ny ] ; % i nput i s r f or c omp. s ens i t i v i t y
out = [ 1: ny ] ; % out put i s y p f or comp. s ens i t i v i t y
[ f r s p, ey ef r s p] = mod2f r s p( cl mod, f r eq, out , i n) ;
pl ot f r s p( ey ef r s p) ; % s ens i t i v i t y
paus e;
pl ot f r s p( f r s p) ; % compl ement ar y s ens i t i v i t y
paus e; % Magni t ude = 1 f or al l f r equenci es chos en.
C losed-Loop Analysi s
2-19
10
3
10
2
10
1
10
0
10
2
10
1
10
0
10
1
Frequency (radians/time)
L
o
g

M
a
g
n
i
t
u
d
e
BODE PLOTS
10
3
10
2
10
1
10
0
100
50
0
50
100
Frequency (radians/time)
P
h
a
s
e

(
d
e
g
r
e
e
s
)
10
3
10
2
10
1
10
0
10
0
10
1
Frequency (radians/time)
L
o
g

M
a
g
n
i
t
u
d
e
BODE PLOTS
10
3
10
2
10
1
10
0
800
600
400
200
0
Frequency (radians/time)
P
h
a
s
e

(
d
e
g
r
e
e
s
)
2 M PC Based on Step Response M odels
2-20
Constrained Model Predictive Control
The control acti on can al so be computed subject to hard constrai nts on the
mani pul ated vari abl es and the outputs.
Mani pul ated vari abl e constrai nts:
u
min
(l) u(k +l) u
max
(l)
Mani pul ated vari abl e rate constrai nts:
| u(k + l)| u
max
(l)
Output vari abl e constrai nts:
y
min
(l) y(k + l | k) y
max
(l)
When hard constrai nts of thi s form are i mposed, a quadrati c program has to be
sol ved at each ti me step to determi ne the control acti on and the resul ti ng
control l aw i s general l y nonl i near. The performance of such a control system
has to be eval uated vi a si mul ati on.
Example: (mpct ut s t . m)
% Si mul at e and pl ot r es pons e f or unmeas ur e d s t ep
% di s t ur bance t hr ough dpl ant wi t h and wi t hout
% i nput cons t r ai nt s .
% No pl ant /model mi s mat ch,
% Out put Wei ght = 1, I nput Wei ght = 0
% I nput Hor i z on = 5, Out put Hor i z on = 20
% Mi ni mum Cons t r ai nt on I nput = - 0. 4
% Max i mum Cons t r ai nt on I nput = i nf
% Del t a Cons t r ai nt on I nput = 0. 1
model = pl ant ;
y wt = 1; uwt = 0;
M = 5; P = 20;
t end = 245;
r = 0;
ul i m = [ ] ;
y l i m = [ ] ; t f i l t er = [ ] ; dmodel = [ ] ;
ds t ep = 1;
[ y 9, u9] = cmpc( pl ant , model , y wt , uwt , M, P, t end, r , . . .
ul i m, y l i m, t f i l t er , dpl ant , dmodel , ds t ep) ;
ul i m = [ - 0. 4, i nf , 0. 1] ; % i mpos e cons t r ai nt s
C onstrai ned M odel Predi cti ve C ontrol
2-21
[ y 10, u10] = cmpc( pl ant , model , y wt , uwt , M, P, t end, r , . . .
ul i m, y l i m, t f i l t er , dpl ant , dmode l , ds t ep) ;
pl ot al l ( [ y 9, y 10] , [ u9, u10] , del t 2) ;
0 50 100 150 200 250
0
0.2
0.4
0.6
0.8
1
Outputs
Time
0 50 100 150 200 250
0.6
0.5
0.4
0.3
0.2
0.1
0
0.1
Manipulated Variables
Time
2 M PC Based on Step Response M odels
2-22
Application: Idle Speed Control
Process Description
An i dl e speed control
2
system shoul d mai ntai n the desi red engi ne rpm wi th
automati c transmi ssi on i n neutral or dri ve. Despi te sudden l oad changes due
to the acti ons of ai r condi ti oni ng, power steeri ng, etc., the control system
shoul d mai ntai n smooth stabl e operati on. Because of varyi ng operati ng
condi ti ons and engi ne-to-engi ne vari abi l i ty i nevi tabl e i n mass producti on, the
system dynami cs may change. The control l er must be desi gned to be robust
wi th respect to these changes. Two control i nputs, bypass val ve (or throttl e)
openi ng and spark advance, are used to mai ntai n the engi ne rpm at a desi red
i dl e speed l evel . For safe operati on, spark advance shoul d not change by more
than 20 degrees. Al so, spark advance shoul d be at the desi gn poi nt at
steady-state for fuel economy. Thus, spark advance i s vi ewed both as a
mani pul ated i nput and a control l ed output.
Control Problem Formulation
Here we consi der two di fferent operati ng condi ti ons (transmi ssi on i n neutral
and dri ve posi ti ons) and the model s for the two pl ants are taken from the paper
by Hrovat and Bodenhei mer.
3
The goal i s to desi gn a model predi cti ve
control l er such that the cl osed l oop performance at both operati ng condi ti ons i s
good i n the presence of the i nput constrai nt speci fi ed above. There i s no
synthesi s method avai l abl e whi ch systemati cal l y generates a control l er desi gn
whi ch guarantees robust performance (or even just robust stabi l i ty) i n the
presence of constrai nts. Thus, we must rel y on both desi gn and si mul ati on tool s
to determi ne achi evabl e performance objecti ves when there are both
constrai nts and robustness requi rements. The tool box hel ps us toward thi s
objecti ve.
Consi der the fol l owi ng system:
2. More detai l on the probl em for mul ati on can be found i n the paper by Wi l l i ams et al ., I dl e
Speed Contr ol Desi gn Usi ng an H

Appr oach, Proceedings of American Control Conference,


1989, pages 19501956.
3. D. Hrovat and B. Bodenhei mer, Robust Automoti ve I dl e Speed Control Desi gn Based on
-Synthesi s, Proceedings of American Control Conference, 1993, pages 17781783.
y
1
y
2
G
11
G
21
0 1
u
1
u
2
G
d
0
w + =
Appli cati on: Idle Speed C ontrol
2-23
where y
1
i s engi ne rpm, y
2
and u
2
are spark advance, u
1
i s bypass val ve, wi s
torque l oad (unmeasured di sturbance), and G
11
, G
21
and Gd are the
correspondi ng transfer functi ons. After scal i ng, the constrai nts on spark
advance become 0.7, i .e., | u
2
| 0.7.
Pl ant #1 corresponds to operati on i n dri ve at 800 rpm and a l oad of 30 Nm and
the transfer functi ons are gi ven by
Pl ant #2 corresponds to operati on at 800 rpm i n neutral wi th zero l oad and the
transfer functi ons are gi ven by
The goal i s to desi gn a model predi cti ve control l er such that the cl osed-l oop
performance i s good for pl ants #1 and #2 when subjected to an unmeasured
torque l oad di sturbance.
G
11
9.62e
0.16s
s
2
2.4s 5.05 + +
----------------------------------------- =
G
21
15.9 s ( 3 )e +
0.04s
s
2
2.4s 5.05 + +
----------------------------------------------- =
G
d
19.1 s 3 + ( )
s
2
2.4s 5.05 + +
----------------------------------------- =
G
11
20.5e
0.16s
s
2
2.2s 12.8 + +
----------------------------------------- =
G
21
47.6 s ( 3.5 )e +
0.04s
s
2
2.2s 12.8 + +
---------------------------------------------------- =
G
d
19.1 s 3.5 + ( )
s
2
2.2s 12.8 + +
----------------------------------------- =
2 M PC Based on Step Response M odels
2-24
Simulations
Si nce the tool box handl es onl y di screte-ti me systems, the model s are
di screti zed usi ng a sampl i ng ti me of 0.1. We approxi mate each of the di screte
transfer functi ons wi th 40 step response coeffi ci ents. The functi on cmpc i s used
to generate the control l er and to si mul ate the cl osed-l oop response because i t
determi nes optimal changes of the mani pul ated vari abl es subject to
constrai nts. For compari son (Si mul ati on #4), we al so use the functi ons mpccon
for control l er desi gn and mpcs i mfor si mul ati ng cl osed-l oop responses. On-l i ne
computati ons are si mpl er, but the resul ti ng control l er i s l i near and the
constrai nts are not handl ed i n an opti mal fashi on. The fol l owi ng addi ti onal
functi ons from the tool box are al so used: t f d2s t ep and pl ot al l . The MATLAB
code for the fol l owi ng si mul ati ons can be found i n the fi l e i dl ect r . mi n the
di rectory mpcdemos .
Figure 2-1 Responses to a Unit Torque Disturbance for Plant #1 (no model/
plant mismatch)
Simula tion # 1 . No model /pl ant mi smatch. The fol l owi ng parameters are used:
M = 10, P = i nf , y wt = [ 5 1] , uwt = [ 0. 5 0. 5] ,
t f i l t er = [ ]
The l arger wei ght on the fi rst output (engi ne rpm) i s to emphasi ze that
control l i ng engi ne rpm i s more i mportant than control l i ng spark advance.
Fi gure 2-1 and Fi gure 2-2 show the cl osed-l oop response for a uni t step torque
1 2 3 4 5 6 7 8 9 10 0
5
0
-5
1 2 3 4 5 6 7 8 9 10 0
5
0
-5
10
Outputs
Time
Manipulated Variables
Time
y2
y1
u1
u2
Appli cati on: Idle Speed C ontrol
2-25
l oad change. No model /pl ant mi smatch i s i ntroduced, i .e., we use Pl ant #1 and
Pl ant #2 as the nomi nal model for si mul ati ng the cl osed l oop response for Pl ant
#1 and Pl ant #2, respecti vel y.
As we can see, both control l ers perform wel l for thei r respecti ve pl ants.
Because of the i nfi ni te output hori zon, i .e., P = i nf , nomi nal stabi l i ty i s
guaranteed for both systems. I n some sense, the performance observed i n
Fi gure 2-1 and Fi gure 2-2 i s the best whi ch can be expected, when the spark
advance constrai nt i s i nvoked and there i s no model /pl ant mi smatch.
Obvi ousl y, i f we want to control Pl ant #1 and Pl ant #2 wi th the same control l er
the nomi nal performance for each pl ant wi l l deteri orate.
Figure 2-2 Responses to a Unit Torque Disturbance for Plant #2
(no model/ plant mismatch)
1 2 3 4 5 6 7 8 9 10 0
1 2 3 4 5 6 7 8 9 10 0
0
-2
-4
2
Outputs
Time
Manipulated Variables
Time
5
0
-5
y2
y1
u1
u2
2 M PC Based on Step Response M odels
2-26
Figure 2-3 Responses to a Unit Torque Disturbance for Plant #1
(nominal model = Plant #2)
Simula tion # 2 . Model /pl ant mi smatch. Al l parameters are kept the same as i n
Si mul ati on #1. Shown i n Fi gure 2-3 i s the response to a uni t torque di sturbance
for Pl ant #1 usi ng Pl ant #2 as the nomi nal model . Fi gure 2-4 depi cts the
response to a uni t torque di sturbance for Pl ant #2 usi ng Pl ant #1 as the
nomi nal model . As one can see, both systems are unstabl e. Therefore, the
control l ers must be detuned to i mprove robustness i f one wants to control both
pl ants wi th the same control l er.
1 2 3 4 5 6 7 8 9 10 0
1 2 3 4 5 6 7 8 9 10 0
10
0
-10
20
Outputs
Time
Manipulated Variables
Time
20
0
-20
y2
y1
u1
u2
Appli cati on: Idle Speed C ontrol
2-27
Figure 2-4 Responses to a Unit Torque Disturbance for Plant #2 (nominal
model = Plant #1)
Simula tion # 3 . The i nput wei ght i s i ncreased to [10 20] to i mprove robustness.
Al l other parameters are kept the same as i n Si mul ati on #1. Pl ant #1 i s used
as the nomi nal model . The si mul ati on resul ts depi cted i n Fi gure 2-5 and Fi gure
2-6 seem to i ndi cate that wi th an i nput wei ght of [10 20] the control l er
stabi l i zes both pl ants. However, we must poi nt out that the desi gn procedure
guarantees gl obal asymptoti c stabi l i ty onl y for the nomi nal system, i .e., Pl ant
#1. Because of the i nput constrai nts, the system i s nonl i near. The observed
stabi l i ty for Pl ant #2 i n Fi gure 2-6 shoul d not be mi staken as an i ndi cati on of
gl obal asymptoti c stabi l i ty.
1 2 3 4 5 6 7 8 9 10 0
1 2 3 4 5 6 7 8 9 10 0
2
0
-2
4
Outputs
Time
Manipulated Variables
Time
5
0
-5
y2
y1
u1
u2
2 M PC Based on Step Response M odels
2-28
Figure 2-5 Responses to a Unit Torque Disturbance for Plant #1 (nominal
model = Plant #1)
Figure 2-6 Responses to a Unit Torque Disturbance for Plant #2 (nominal
model = Plant #1)
1 2 3 4 5 6 7 8 9 10 0
1 2 3 4 5 6 7 8 9 10 0
0
10
Outputs
Time
Manipulated Variables
Time
5
-5
-10
y2
y1
u1
u2
0
1 2 3 4 5 6 7 8 9 10 0
1 2 3 4 5 6 7 8 9 10 0
0
-2
-4
2
Outputs
Time
Manipulated Variables
Time
4
2
0
y2
y1
u1
u2
Appli cati on: Idle Speed C ontrol
2-29
As expected, the nomi nal performance for both Pl ant #1 and Pl ant #2 has
deteri orated when compared to the si mul ati ons shown i n Fi gure 2-1 and Fi gure
2-2. A si mi l ar effect woul d be observed i f we had detuned the control l er whi ch
uses Pl ant #2 as the nomi nal model .
Simula tion # 4 . The parameter val ues are the same as i n Si mul ati on #3. I nstead
of usi ng cmpc , we use mpccon and mpcs i mfor si mul ati ng the cl osed l oop
responses. Fi gure 2-2 compares the responses for Pl ant #1 usi ng mpccon and
mpcs i m, and cmpc . As we can see, for thi s exampl e and these tuni ng
parameters, the i mprovement obtai ned through the on-l i ne opti mi zati on i n
cmpc i s smal l . However, the di fference coul d be l arge, especi al l y for
i l l -condi ti oned systems and other tuni ng parameters. For exampl e, by reduci ng
the output hori zon to P = 80 whi l e keepi ng the other parameters the same, the
responses for Pl ant #1 found wi th mpccon and mpc s i mare si gni fi cantl y sl ower
than those obtai ned wi th cmpc (Fi gure 2-8).
Figure 2-7 Comparison of Responses From cmpc, and mpccon and mpcs i m for
Plant #1 P = i nf
2 4 6 8 10 0
-4
-5
-6
-3
Solid: cmpc
Time
0
-1
-2
1
Dashed: mpccon and mpcsim
O
u
t
p
u
t
y1
y2
2 M PC Based on Step Response M odels
2-30
Figure 2-8 Comparison of Responses From c mpc, and mpccon and mpcs i m for
Plant #1 ( P = 80)
2 4 6 8 10 0
-4
-5
-6
-3
Solid: cmpc
Time
0
-1
-2
1
Dashed: mpccon and mpcsim
O
u
t
p
u
t
y1
y2
-7
Appli cati on: C ontrol of a Flui d C atalyti c C racki ng Uni t
2-31
Application: Control of a Fluid Catalytic Cracking Unit
Process Description
Fl ui d Catal yti c Cracki ng Uni ts (FCCUs) are wi del y used i n the petrol eum
refi ni ng i ndustry to convert hi gh boi l i ng oi l cuts (of l ow economi c val ue) to
l i ghter more val uabl e hydrocarbons i ncl udi ng gasol i ne. Cracki ng refers to the
catal yst enhanced thermal breakdown of hi gh mol ecul ar wei ght hydrocarbons
i nto l ower mol ecul ar wei ght materi al s. A schemati c of the FCCU studi ed
4
i s
gi ven i n Fi gure 2-9. Fresh feed i s contacted wi th hot catal yst at the base of the
ri ser and travel s rapi dl y up the ri ser where the cracki ng reacti ons occur. The
desi rabl e products of reacti on are gaseous (l i ghter) hydrocarbons whi ch are
passed to a fracti onator and subsequentl y to separati on uni ts for recovery and
puri fi cati on. The undesi rabl e byproduct of cracki ng i s coke whi ch i s deposi ted
on the catal yst parti cl es, reduci ng thei r acti vi ty. Catal yst coated wi th coke i s
transported to the regenerator secti on where the coke i s burned off thereby
restori ng catal yti c acti vi ty and rai si ng catal yst temperature. The regenerated
catal yst i s then transported to the ri ser base where i t i s contacted wi th more
fresh feed. Regenerated catal yst at the el evated temperature provi des the heat
requi red to vapori ze the fresh feed as wel l as the energy requi red for the
endothermi c cracki ng reacti on.
4. A detai l ed probl em descri pti on and the model used for thi s study can be found i n the paper by
McFarl ane et al ., Dynami c Si mul ator for a Model I V Fl ui d Catal yti c Cracki ng Uni t, Comp. &
Chem. Eng., 17(3), 1993, pages 275300
2 M PC Based on Step Response M odels
2-32
Figure 2-9 Fluid Catalytic Cracking Unit Schematic
Product composi ti on, and therefore the economi c vi abi l i ty of the process, i s
determi ned by the cracki ng temperature. The bul k of the combusti on ai r i n the
regenerator secti on i s provi ded by the mai n ai r compressor whi ch i s operated
at ful l capaci ty. Addi ti onal combusti on ai r i s provi ded by the l i ft ai r
compressor, the throughput of whi ch i s adjustabl e by al teri ng compressor
speed. By mai ntai ni ng excess fl ue gas oxygen concentrati on, i t i s possi bl e to
ensure essenti al l y compl ete coke removal from the catal yst.
Appli cati on: C ontrol of a Flui d C atalyti c C racki ng Uni t
2-33
Control Problem Formulation
The open l oop system i s model ed as fol l ows:
where
G i s the pl ant model and G
d
i s the di sturbance model . The vari abl es are:
Control l ed vari abl es
- Cracki ng temperature (T
r
)
- Fl ue gas oxygen concentrati on ( )
Associ ated vari abl e
- Li ft Ai r Compressor Surge I ndi cator (F
la
)
Mani pul ated vari abl es
- Li ft ai r compressor speed (V
lift
)
- Fl ue gas val ve openi ng (V
fg
)
Model ed di sturbances
- Vari ati ons i n ambi ent temperature affect compressor throughput (d
1
)
- Fl uctuati ons i n heavy oi l feed composi ti on to the FCCU (d
2
)
- Pressure upset i n down stream uni ts propagati ng back to the FCCU (d
3
)
I n addi ti on to the control l ed vari abl es there are many process vari abl es that
need not be mai ntai ned at speci fi c setpoi nts but whi ch need to be wi thi n
bounds for safety or economi c r easons. These vari abl es ar e cal l ed associated
variables. For exampl e, compressors must not surge duri ng process upsets i .e.,
the sucti on fl ow rate must be greater than some mi ni mum fl ow rate (surge fl ow
rate).
The control objecti ve i s to mai ntai n the control l ed vari abl es (cracki ng
temperature and fl ue gas oxygen concentrati on) at pre-determi ned setpoi nts i n
the presence of typi cal process di sturbances whi l e mai ntai ni ng safe pl ant
operati on.
y Gu G
d
d + =
u V
fg
V
l i ft
[ ]
T
= y C
O
2 sg ,
T
r
F
l a
[ ]
T
= d d
1
d
2
d
3
[ ]
T
=
C
O
2 sg ,
2 M PC Based on Step Response M odels
2-34
Simulations
State-space real i zati ons of the pl ant and di sturbance model s are avai l abl e i n
the MATLAB fi l e f cc_dat . mat i n the di rectory mpcde mos . A MATLAB scri pt
detai l i ng the si mul ati ons i s al so i ncl uded (f cc_demo. m). The fol l owi ng tabl e
gi ves the parameters used for control l er desi gn and exami nati on of the cl osed
l oop response:
Table 2-1 FCCU Simulation Parameters
Step Response M odel
Fi gure 2-10A shows the pl ant open l oop step response to a uni t step i n V
fg
.
Al though the pl ant i s stabl e the settl i ng ti me i s l arge (1 day). The ti me scal e of
i nterest for control purposes i s on the order of one hour whi ch corresponds
to the i ni ti al pl ant response, Fi gure 2-10B. For ti me scal es of one hour, the
process can be approxi mated by an i ntegrati ng system. I n deri vi ng the step
response model , the pl ant i s therefore assumed to be an i ntegrati ng process.
Si mul ati on Ti me(s) t end = 2500
#Step Response Coeffi ci ents 60
Process Sampl i ng Ti me del t 2 = 100
Output Wei ghts y wt = [ 3 3 0]
I nput Wei ghts uwt = [ 0 2]
Predi cti on Hor i zon (steps) P = 12
#mani pul ated vari abl e moves M = 3
i nput constrai nts u
i
[ -1,1] , i = 1,2
output constrai nts y
i
[ -1,1] , i = 1,2
y
3
-1 ( hard constrai nt)
Appli cati on: C ontrol of a Flui d C atalyti c C racki ng Uni t
2-35
Figure 2-10 Open Loop Step Response to u = [ 1 0]
Figure 2-11 Unconstrained Closed Loop Response to d = [ 0 - 0. 5 - 0. 75]
0 2 4 6
x 10
4
600
500
400
300
200
100
0
time (s)
c
O
2
s
g
A
0 2000 4000 6000 8000 10000
300
250
200
150
100
50
0
time (s)
c
O
2
s
g
B
0 500 1000 1500 2000 2500
2
1
0
1
2
time (s)
o
u
t
p
u
t

v
a
r
i
a
b
l
e
s
cO2sg
Tr
surge indicator
Disturbance Rejection, UNCONSTRAINED DESIGN
0 500 1000 1500 2000 2500
1
0.8
0.6
0.4
0.2
0
0.2
0.4
time (s)
m
a
n
i
p
u
l
a
t
e
d

v
a
r
i
a
b
l
e
s
V
f
g
V
l
ift
2 M PC Based on Step Response M odels
2-36
Associa ted Va ria bles
As menti oned previ ousl y, associ ated vari abl es need not be at any setpoi nt as
l ong as they are wi thi n acceptabl e bounds. Devi ati ons of associ ated vari abl es
from the nomi nal val ue do not appear i n over al l objecti ve functi on to be
mi ni mi zed and the output wei ght correspondi ng to the associ ated vari abl e i s
set to zero i n Tabl e 2-1.
Unconstr a ined Control La w
Fi gure 2-11 shows the cl osed l oop response to a di sturbance
d = [ 0 - 0. 5 - 0. 75] at t = 0. The control l er gai n matri x i s deri ved usi ng
mpccon and the cl osed l oop response i s exami ned usi ng mpcs i m. Note the
fol l owi ng:
At the fi rst ti me step (t = 100s) the control l ed vari abl es are outsi de thei r
al l owed l i mi ts. The onset of the di sturbance at t = 0 i s unknown to the
control l er at t = 0 si nce there i s no di sturbance feedforward l oop. Thus from
t =0 to t =100s there i s no control acti on and the process response i s the open
l oop response wi th no control acti on. Onl y after t = 100s i s correcti ve acti on
i mpl emented.
At t = 200s (2
nd
ti me step) ri ser temperature i s outsi de the al l owed l i mi ts.
The l i ft ai r compressor surges duri ng the i nterval 200s t 800s whi ch i s
unacceptabl e. Compressor surgi ng wi l l resul t i n undesi rabl e vi brati ons i n
the compressor l eadi ng to rapi d wear and tear.
Constra ined Control La w
I t i s cl ear that the unconstrai ned control l aw generated usi ng mpcs i mi s
physi cal l y unacceptabl e si nce hard output constrai nts are vi ol ated. Fi gure 2-12
shows the cl osed l oop response of the nomi nal pl ant to the same di sturbance
taki ng process constrai nts expl i ci tl y i nto account. The cl osed l oop response i s
determi ned usi ng the command cmpc.
Appli cati on: C ontrol of a Flui d C atalyti c C racki ng Uni t
2-37
Figure 2-12 Constrained Closed Loop Response to d = [0 -0.5 -0.75]
The output l i mi t vector i s:
0 500 1000 1500 2000 2500
2
1
0
1
2
time (s)
o
u
t
p
u
t

v
a
r
i
a
b
l
e
s
Disturbance Rejection, CONSTRAINED DESIGN
cO2sg
Tr
surge indicator
0 500 1000 1500 2000 2500
1
0.8
0.6
0.4
0.2
0
0.2
0.4
time (s)
m
a
n
i
p
u
l
a
t
e
d

v
a
r
i
a
b
l
e
s
V
f
g
V
l
ift
ylim
1 1 1 1 1 Inf
1 1 1 1 1 Inf
Inf Inf Inf Inf Inf Inf
=
2 M PC Based on Step Response M odels
2-38
Note the fol l owi ng:
At the fi rst ti me step (t = 100s) the control l ed vari abl es are outsi de thei r
al l owed l i mi ts. I n fact the outputs are i denti cal to the outputs for the
unconstrai ned case at t =100s. Thi s shoul d be expected as there i s no control
acti on from t = 0 to t = 100s for both constrai ned and unconstrai ned desi gns.
At t = 200s (2
nd
ti me step) ri ser temperature (y
2
) i s sti l l outsi de the al l owed
l i mi ts. Thi s i s because the constrai ned QP sol ved at t = 100s assumes that
di sturbances are constant for t > 100s whi ch i s not the case for thi s process.
Thus whi l e the mani pul ated vari abl e move made at t =100s ensures that the
pr edi cted y
2
= 1 at t = 200s, the actual output at t = 200s exceeds one.
The l i ft ai r compressor does not surge duri ng the di sturbance transi ent,
Fi gure 2-13.
The constrai ned control l aw therefore ensures safe operati on whi l e rejecti ng
process di sturbances. I f no constrai nts are vi ol ated, mpccon and mpcs i m, and
cmpc wi l l gi ve i denti cal cl osed l oop responses. Note that the di sturbance
d = [ 0 - 0. 5 - 0. 75] was speci fi cal l y chosen to i l l ustrate the possi bi l i ty of
constrai nt vi ol ati ons duri ng di sturbance transi ent peri ods.
Figure 2-13 Comparison of Constrained and Unconstrained Response of F
la

to d = [ 0 - 0. 5 - 0. 75]
0 500 1000 1500 2000 2500
1.2
1
0.8
0.6
0.4
0.2
0
0.2
Unconstrained Response
Constrained Response
time (s)
a
s
s
o
c
i
a
t
e
d

v
a
r
i
a
b
l
e
Associated Variable Response to Constrained & Unconstrained Control Laws
3
MPC Based on
State-Space Model s
3 M PC Based on State-Space M odels
3-2
State-Space Models
Consi der the process shown i n the above bl ock di agram. The general
di screte-ti me l i near ti me i nvari ant (LTI ) state-space representati on used i n
the MPC Tool box i s:
where x i s a vector of n state vari abl es, u represents the n
u
mani pul ated
vari abl es, d represents n
d
measured but freel y-varyi ng i nputs (i .e., measured
di sturbances), wrepresents n
w
unmeasured di sturbances, y i s a vector of n
y
pl ant outputs, z i s measurement noi se, and ,
u
, etc., are constant matri ces of
appropri ate si ze. The vari abl e (k) represents the pl ant output before the
addi ti on of measur ement noi se. Defi ne:

y y
Unmeasured
Disturbances
Manipulated
Variables
Measured
Disturbances
Measurement
Noise
w
u
d
+ +
z
Plant
Measured
Outputs
x k 1 + ( ) x k ( )
u
u k ( )
d
d k ( )
w
w k ( ) + + + =
y k ( ) y k ( ) z k ( ) + =
Cx k ( ) D
u
u k ( ) D
d
d k ( ) D
w
w k ( ) z k ( ) + + + + =
y


u

d

w
=
D
D
u
D
d
D
w
=
State-Space M odels
3-3
I n many appl i cati ons, al l outputs are measured. I n some cases, however, one
has n
ym
measured and n
yu
unmeasured outputs i n y, where n
ym
+ n
yu
= n
y
. I f
so, the MPC Tool box assumes that the y vector and the C and D matri ces are
arranged such that the measured outputs come fi rst, fol l owed by the
unmeasured outputs.
Mod Format
The MPC Tool box works wi th state-space model s i n a speci al format, cal l ed the
mod format. The mod format i s a si ngl e matri x that contai ns the state-space
, , C, and D matri ces pl us some addi ti onal i nformati on (see mod f or mat i n
the "Command Reference"chapter for detai l s). The MPC Tool box i ncl udes a
number of commands that make i t easy to generate model s i n the mod format.
The fol l owi ng secti ons i l l ustrate the use of these commands.
SISO Continuous-Time Transfer Function to Mod
Format
The MPC Tool box uses a format cal l ed the t f format. Let the conti nuous-ti me
transfer functi on be
where T
d
i s the ti me del ay. The t f format i s a matri x consi sti ng of three rows:
The t f matri x wi l l al ways have at l east two col umns, si nce that i s the
mi ni mum wi dth of the thi rd row.
row 1: The n coeffi ci ents of the numerator pol ynomi al , b
0
to b
n
.
row 2: The n coeffi ci ents of the denomi nator pol ynomi al , a
0
to a
n
.
row 3: col umn 1: The sampl i ng peri od. This must bezerofor a
continuous system. (I t must be posi ti ve for di screte transfer
functi ons see next secti on).
col umn 2: The ti me del ay i n ti me uni ts. I t must sati sfy Td 0.
G s ( )
b
0
s
n
b
1
s
n 1
b
n
+ + +
a
0
s
n
a
1
s
n 1
a
n
+ + +
----------------------------------------------------------------e
T
d
s
=
3 M PC Based on State-Space M odels
3-4
You can ei ther defi ne a model i n the t f format di rectl y or use the command
pol y 2t f d. The general form of thi s command i s
g = pol y 2t f d( num, den, del t , del ay )
For exampl e, consi der a SI SO system model ed by the transfer functi on
To create the t f format di rectl y you coul d use the command
G = [ 0 - 13. 6 1; 54. 3 113. 5 1; 0 5. 3 0] ;
whi ch defi nes a matri x consi sti ng of three rows and three col umns. Note that
al l rows must have the same number of col umns so you must be careful to
i nsert zeros where appropri ate. The pol y 2t f d command i s more conveni ent
si nce i t does that for you automati cal l y:
G = pol y 2t f d( [ - 13. 6 1] , [ 54. 3 113. 5 1] , 0, 5. 3) ;
Ei ther command woul d defi ne a vari abl e Gi n your workspace, contai ni ng the
matri x
To convert thi s to the mod format, use the command t f d2mod, whi ch has the
form
model = t f d2mod( del t , ny , g1, g2, g3, . . . , gN)
G=
0 -13.6000 1.0000
54.3000 113.5000 1.0000
0 5.3000 0
G s ( )
13.6s 1 +
54.3s
2
113.5s 1 + +
---------------------------------------------------e
5.3s
=
State-Space M odels
3-5
where:
Suppose you want to convert the SI SO model defi ned above to the mod format
wi th a sampl i ng peri od of 2.1 ti me uni ts. The appropri ate command woul d be
mod = t f d2mod( 2. 1, 1, G) ;
Thi s woul d defi ne a vari abl e cal l ed mod i n your workspace that woul d contai n
the di screte-ti me state-space descri pti on of your system.
del t The sampl i ng peri od. t f d2mod wi l l convert your
conti nuous ti me transfer functi on(s) g1, . . . , gNto
di screte-ti me usi ng thi s sampl i ng peri od.
ny i s the number of output vari abl es i n the pl ant you are
model i ng.
g1, g2, . . . , gN A sequence of N transfer functi ons i n the tf format, where
N 1. t f d2mod assumes that these are the i ndi vi dual
el ements of a transfer-functi on matri x:
Thus N must be an i nteger mul ti pl e (n
u
) of the number of
outputs, n
y
. You suppl y the transfer functi ons i n
column-wiseorder. I n other words, you fi rst gi ve the n
y
transfer functi ons for i nput 1 ( ), then the n
y
transfer functi ons for i nput 2 ( ), etc.
g
1 1 ,
g
1 2 ,
g
1 n
u
,
g
2 1 ,
g
2 2 ,
g
2 n
u
,
g
n
y
1 ,
g
n
y
2 ,
g
n
y
n
u
,

.
.
.
g
1 1 ,
to g
n
y
1 ,
g
1 2 ,
to g
n
y
2 ,
3 M PC Based on State-Space M odels
3-6
SISO Discrete-Time Transfer Function to Mod Format
Suppose you have a transfer functi on i n di screte-ti me format (i n terms of the
forward-shi ft operator, z):
where d i s an integer ( 0) and represents the sampl i ng peri ods of pure del ay.
The correspondi ng tf format i s the same as for the conti nuous-ti me case except
for the defi ni ti on of the thi rd row:
As i n the previ ous secti on, you can use pol y 2t f d fol l owed by t f d2mod to get
such a transfer functi on i n mod format. For exampl e, the di screte-ti me
representati on of the SI SO system consi dered i n the previ ous secti on i s
I f you had thi s to begi n wi th, you coul d convert i t to the mod format as fol l ows:
G = pol y 2t f d( [ - 0. 1048 0. 1215 0. 0033] , [ 1 - 0. 9882 0. 0082] , 2. 1, 3) ;
mod = t f d2mod( 2. 1, 1, G) ;
Note that both the pol y 2t f d and t f d2mod commands speci fy the same
sampl i ng peri od (del t =2. 1). Thi s woul d be the usual case, but you have the
opti on of converti ng a di screte-ti me model i n the tf format to a di fferent
sampl i ng peri od i n the mod format.
col umn 1 i s the sampl i ng peri od for whi ch G(z) was created. I t must
be posi ti ve (i n contrast to the conti nuous-ti me case
descri bed above).
col umn 2 i s the periods of pure del ay, d, whi ch must be an integer 0.
Contrast thi s to the conti nuous case, where the del ay i s
gi ven i n ti me uni ts.
G q ( )
b
0
b
1
z
1
b
n
z
n
+ + +
a
0
a
1
q
1
a
n
z
n
+ + +
--------------------------------------------------------------z
d
=
G z ( )
0.1048 0.1215z
1
0.0033z
2
+ +
1 0.9882z
1
0.0082z
2
+
-----------------------------------------------------------------------------------------z
3
=
State-Space M odels
3-7
MIMO Transfer Function Description to Mod Format
Suppose you have a transfer-functi on matri x descri pti on of your system i n the
form
where g
i,j
i s the transfer functi on of the i
th
output wi th respect to the j
th
i nput.
I f al l n
y
outputs are measured and al l n
u
i nputs are mani pul ated vari abl es, the
defaul t mode of t f d2mod wi l l gi ve you the correct mod format. For exampl e,
consi der the 2-output, 3-i nput system:
The fol l owi ng sequence of commands woul d convert thi s to the equi val ent mod
format wi th a sampl i ng peri od of T = 4:
g11 = pol y 2t f d( 12. 8, [ 16. 7 1] , 0, 1) ;
g21 = pol y 2t f d( 6. 6, [ 10. 9 1] , 0, 7) ;
g12 = pol y 2t f d( - 18. 9, [ 21. 0 1] , 0, 3) ;
g22 = pol y 2t f d( - 19. 4, [ 14. 4 1] , 0, 3) ;
g13 = pol y 2t f d( 3. 8, [ 14. 9 1] , 0, 8) ;
g23 = pol y 2t f d( 4. 9, [ 13. 2 1] , 0, 3) ;
pmod = t f d2mod( 4, 2, g11, g21, g12, g22, g13, g23) ;
g
1 1 ,
g
1 2 ,
g
1 n
u
,
g
2 1 ,
g
2 2 ,
g
2 n
u
,
g
n
y
1 ,
g
n
y
2 ,
g
n
y
n
u
,

.
.
.
y
1
s ( )
y
2
s ( )
12.8e
s
16.7s 1 +
------------------------
18.9e
3s
21.0s 1 +
-------------------------
3.8e
8s
14.9s 1 +
------------------------
6.6e
7s
10.9s 1 +
------------------------
19.4e
3s
14.4s 1 +
-------------------------
4.9e
3s
13.2s 1 +
------------------------
u
1
s ( )
u
2
s ( )
u
3
s ( )
=
3 M PC Based on State-Space M odels
3-8
Suppose, however, that the thi rd i nput were actual l y an unmeasured
di sturbance, i .e., the system were
I n thi s case you woul d need to overri de the defaul t mode of t f d2mod by
speci fyi ng the number of i nputs i n each of the three categori es descri bed at the
begi nni ng of thi s secti on, i .e., mani pul ated vari abl es, measured di sturbances,
and unmeasured di sturbances. Thi s and other i nformati on about the system i s
contai ned i n the fi rst 7 col umns of row 1 of the mod format, as fol l ows:
For exampl e, i f you had defi ned pmod usi ng the defaul t mode of t f d2mod as
shown above, the contents of row 1, col umns 1 to 7 of pmod woul d be:
4 13 3 0 0 2 0
You coul d overri de thi s to set n
u
= 2 and n
w
= 1 as fol l ows:
pmod( 1, 3) =2;
pmod( 1, 5) =1;
col umn 1 T, the sampl i ng peri od.
2 n, the number of states.
3 n
u
, the number of mani pul ated vari abl e i nputs.
4 n
d
, the number of measured di sturbances.
5 n
w
, the number of unmeasured di sturbances.
6 n
ym
, the number of measured outputs.
7 n
yu
, the number of unmeasured outputs.
y
1
s
y
2
s
12.8e
s
16.7s 1 +
------------------------
18.9e
3s
21.0s 1 +
-------------------------
6.6e
7s
10.9s 1 +
------------------------
19.4e
3s
14.4s 1 +
-------------------------
u
1
s
u
2
s
=
3.8e
8s
14.9s 1 +
------------------------
4.9e
3s
13.2s 1 +
------------------------
w s ( ) +
State-Space M odels
3-9
Note that i n the ori gi nal transfer functi on matri x descri pti on, the fi rst n
u
col umns must be for the mani pul ated vari abl es, the next n
d
for the measured
di sturbances (i f any), and the l ast n
w
for the unmeasured di sturbances (i f any).
Si mi l arl y, the fi rst n
ym
outputs must be measured and the l ast n
yu
( 0)
unmeasured.
Continuous or Discrete State-Space to Mod Format
I f you have a conti nuous-ti me state-space model , you may convert i t to mod
format by fi rst usi ng the functi on c2dmp (conti nuous to di screte-ti me
state-space), fol l owed by s s 2mod(di screte-ti me state-space to mod format). Of
course, i f you are starti ng wi th a di screte-ti me state-space model you can ski p
the fi rst step.
For exampl e, suppose a, b, c, and d are matri ces descri bi ng a conti nuous-ti me
system. To convert to the mod format usi ng a sampl i ng peri od of T = 1.5, you
coul d use the fol l owi ng commands:
[ phi , gam] = c2dmp( a, b, 1. 5) ;
mod = s s 2mod( phi , gam, c, d, 1. 5) ;
I f your system i s compl i cated, i .e., i t contai ns di sturbance i nputs and/or
unmeasured outputs, you wi l l need to overri de the defaul t mode of s s 2mod. See
the Command Reference secti on for more detai l s.
Identification Toolbox (Theta) Format to Mod
Format
The System I denti fi cati on Tool box i denti fi es di screte-ti me transfer-functi on
model s from i nput/output data. The resul t i s a model i n a speci al form cal l ed
the theta format (see the SystemI dentification Toolbox Users Guidefor
detai l s). I n general , each theta model descri bes the response of a si ngl e output
to one or more i nputs (MI SO model ).
The MPC Tool box functi on, t h2mod, converts one or more such model s to the
mod format. Suppose, for exampl e, that
t h1 i s the theta model descri bi ng the response of output y
1
to i nputs u
1
and u
2
.
t h2 i s the theta model descri bi ng the response of output y
2
to i nputs u
1
and u
2
.
3 M PC Based on State-Space M odels
3-10
Then the fol l owi ng command woul d provi de the equi val ent mod format wi th
n
y
= 2 and n
u
= 2:
mod = t h2mod( t h1, t h2) ;
Combination of Models in Mod Format
The functi ons addmod, addmd, addumd, appmod, par amod, and s er mod al l ow you
to combi ne si mpl e model s i n the mod format to generate more compl ex pl ant
structures. For exampl e, addmd i ncl udes the effect of one or more measured
di sturbances i n an exi sti ng model , as shown i n the fol l owi ng schemati c:
pmod gi ves the effect of one or more mani pul ated vari abl es, u(k), and opti onal
unmeasured di sturbance(s), w(k), on the output(s), y(k). dmod gi ves the effect of
the measured di sturbance(s), d(k), on the same outputs. Once you have defi ned
pmod and dmod (e.g., starti ng from transfer functi ons as i l l ustrated above), you
can use the command addmd to generate the composi te, model :
model = addmd( pmod, dmod) ;
Pl ease see Chapter 4, Command Reference for more detai l s on the vari ous
model -bui l di ng commands.
Converting Mod Format to Other Model Formats
The functi on mod2s s converts a model i n the mod format to the standard
di screte-ti me state-space format:
[ phi , gam, c, d, mi nf o] = mod2s s ( mod) ;
Here, phi , gam, c, and d are the coeffi ci ent matri ces of
dmod
w
d
Model

y
+
+
u
y
d
pmod
w
u
x k 1 + ( ) x k ( ) u k ( ) + =
State-Space M odels
3-11
The vector mi nf o contai ns the fi rst 7 col umns of the fi rst row i n mod. The secti on
MI MO Transfer Functi on Descri pti on to Mod Format gi ves the si gni fi cance
of thi s i nformati on.
Once you have phi , gam, c, and d, you can use d2cmp, s s 2t f 2, and other
functi ons to convert from di screte state-space to other model forms.
The functi on mod2s t ep uses a model i n the mod format to generate a step-
response model i n the stepformat as requi red by the functi ons mpcc on, mpcs i m,
etc., di scussed i n Chapter 2, MPC Based on Step Response Model s. See the
Chapter 4, Command Reference for detai l s on the use of mod2s t ep.
y k ( ) Cx k ( ) Du k ( ) + =
3 M PC Based on State-Space M odels
3-12
Unconstrained MPC Using State-Space Models
Once you have descri bed your system by generati ng state-space model s i n the
mod format you can use the commands:
I n addi ti on, you can anal yze certai n properti es of the cl osed-l oop system usi ng
the commands:
Note: s mpcgai n, s mpcpol e and mod2f r s p al so work wi th open-l oop model s i n
the mod format.
s mpccon to cal cul ate the unconstrai ned control l er gai n matri x.
s mpces t to desi gn a state esti mator (opti onal ).
s mpcs i m to si mul ate the response of the cl osed-l oop system to one or
more speci fi ed i nputs.
pl ot al l
(or pl ot eac h) to pl ot the response(s).
s mpccl to gener ate a model of the cl osed-l oop system (pl ant pl us
control l er).
s mpcgai n to cal cul ate the cl osed-l oop gai n matri x.
s mpcpol e to cal cul ate the cl osed-l oop pol es.
mod2f r s p (and pl ot f r s p) to cal cul ate and pl ot the cl osed-l oop
frequency response.
s v df r s p to cal cul ate the si ngul ar val ues of the frequency response.
Unconstrai ned M PC Usi ng State-Space M odels
3-13
Example: (see mpct ut s s . m)
The fol l owi ng exampl e (mpct ut s s . m) i l l ustrates the basi c procedures. The
exampl e process has 2 measured outputs, 2 mani pul ated vari abl es, and an
unmeasured di sturbance:
We fi rst defi ne the model i n the mod format. The fol l owi ng commands use a
sampl i ng peri od of T = 2 ti me uni ts (chosen arbi trari l y):
del t = 2;
ny = 2;
g11 = pol y 2t f d( 12. 8, [ 16. 7 1] , 0, 1) ;
g21 = pol y 2t f d( 6. 6, [ 10. 9 1] , 0, 7) ;
g12 = pol y 2t f d( - 18. 9, [ 21. 0 1] , 0, 3) ;
g22 = pol y 2t f d( - 19. 4, [ 14. 4 1] , 0, 3) ;
umod = t f d2mod( del t , ny , g11, g21, g12, g22) ;
% Def i nes t he ef f ect of u i nput s
g13 = pol y 2t f d( 3. 8, [ 14. 9 1] , 0, 8) ;
g23 = pol y 2t f d( 4. 9, [ 13. 2 1] , 0, 3) ;
dmod = t f d2mod( del t , ny , g13, g23) ;
% Def i nes t he ef f ect of w i nput
pmod = addumd( umod, dmod) ; % Combi nes t he t wo model s .
We now desi gn an unconstrai ned MPC control l er. The desi gn parameters are
essenti al l y the same as for the functi ons based on step response model s (see
Chapter 2). I n thi s case, start by choosi ng desi gn parameters such that we get
the perfect controller:
i mod = pmod; % as s ume per f ect model i ng
y wt = [ ] ; % def aul t ( uni t y ) wei ght s on bot h out put s
uwt = [ ] ; % def aul t ( z er o) wei ght s on bot h i nput s
P = 5; % pr edi ct i on hor i z on
M = P; % cont r ol hor i z on
Ks = s mpccon( i mod, y wt , uwt , M, P) ;
y
1
s
y
2
s
12.8e
s
16.7s 1 +
------------------------
18.9e
3s
21.0s 1 +
-------------------------
6.6e
7s
10.9s 1 +
------------------------
19.4e
3s
14.4s 1 +
-------------------------
u
1
s
u
2
s
=
3.8e
8s
14.9s 1 +
------------------------
4.9e
3s
13.2s 1 +
------------------------
w s ( ) +
3 M PC Based on State-Space M odels
3-14
We check the desi gn by runni ng a si mul ati on for a step i ncrease i n the setpoi nt
of output y
1
:
t end=30; % t i me per i od f or s i mul at i on.
r = [ 1 0] ; % s et poi nt s f or t he t wo out put s .
[ y , u] = s mpcs i m( pmod, i mod, Ks , t e nd, r ) ;
pl ot al l ( y , u, del t )
Note that there i s no model error si nce we used the same model to represent
the plant (pmod) as that used to desi gn the control l er (i mod). The resul ts are:
Note that we get perfect tracki ng of the speci fi ed setpoi nt change (y
1
= 1,
y
2
= 0), but the mani pul ated vari abl es are ringing. You coul d have anti ci pated
thi s by cal cul ati ng the pol es of the control l er:
[ cl mod, c mod] = s mpcc l ( pmod, i mod, Ks ) ;
s mpcpol e ( cmod)
The resul t shows that one of the pol es i s at -0.9487 and another i s at -0.9223.
I n general , such negati ve-real pol es cause ri ngi ng.
0 5 10 15 20 25 30
0.2
0
0.2
0.4
0.6
0.8
1
1.2
Outputs
Time
0 5 10 15 20 25 30
1.5
1
0.5
0
0.5
1
1.5
Manipulated Variables
Time
Unconstrai ned M PC Usi ng State-Space M odels
3-15
One way to mi ni mi ze ri ngi ng i s to make the predi cti on hori zon si gni fi cantl y
l arger than the control hori zon:
P = 10;
M = 3;
Ks = s mpccon( i mod, y wt , uwt , M, P) ;
[ y , u] = s mpcs i m( pmod, i mod, Ks , t end, r ) ;
pl ot al l ( y , u, de l t )
Thi s resul ts i n the fol l owi ng i mproved responses:
Another (often more effecti ve) way i s to use blocking. I n the case of bl ocki ng,
each el ement of the vector M i ndi cates the number of steps over whi ch u = 0
duri ng the opti mi zati on. For exampl e, M = [2 3] i ndi cates that u(k + 1) = u(k)
or u(k + 1) = 0 and u(k + 4) = u(k + 3) = u(k + 2) (or u(k + 3) = u(k + 4) = 0):
0 5 10 15 20 25 30
0.2
0
0.2
0.4
0.6
0.8
1
1.2
Outputs
Time
0 5 10 15 20 25 30
0.4
0.2
0
0.2
0.4
0.6
0.8
1
Manipulated Variables
Time
3 M PC Based on State-Space M odels
3-16
M = [ 2 3 4] ; % Def i nes 3 bl ocks of cont r ol mov es
Ks = s mpccon( i mod, y wt , uwt , M, P) ;
[ y , u] = s mpcs i m( pmod, i mod, Ks , t e nd, r ) ;
pl ot al l ( y , u, del t )
paus e
Thi s compl etel y el i mi nates the ri ngi ng, as shown i n the fol l owi ng responses, at
the expense of a more sl uggi sh servo response and a l arger di sturbance i n y
2
.
A thi rd approach i s to i ncrease the wei ghts on the mani pul ated vari abl es:
uwt = [ 1 1] ; % i ncr e as e i nput wei ght i ng
P = 5; % or i gi nal pr edi ct i on hor i z on
M = P; % or i gi nal cont r ol hor i z on
Ks = s mpccon( i mod, y wt , uwt , M, P) ;
[ y , u] = s mpcs i m( pmod, i mod, Ks , t e nd, r ) ;
pl ot al l ( y , u, del t )
0 5 10 15 20 25 30
0.2
0
0.2
0.4
0.6
0.8
1
1.2
Outputs
Time
0 5 10 15 20 25 30
0
0.1
0.2
0.3
0.4
0.5
Manipulated Variables
Time
Unconstrai ned M PC Usi ng State-Space M odels
3-17
for whi ch the response i s:
I n general , you must choose the hori zons and wei ghts by tri al -and-error, usi ng
si mul ati ons to judge thei r effecti veness.
The servo-response of the l ast control l er l ooks good. Lets see how i t responds
to a uni t-step i n the unmeasured di sturbance, w(k):
ul i m = [ ] ; % def aul t ( no) cons t r ai nt s on u v ar i abl es .
Kes t = [ ] ; % def aul t ( DMC) s t at e es t i mat or .
r = [ 0 0] ; % Bot h out put s et poi nt s at z er o.
z = [ ] ; % def aul t ( z er o) meas ur ement noi s e.
v = [ ] ; % def aul t ( z er o) meas ur ed di s t ur bances .
w = [ 1] ; % uni t - s t ep i n unmeas ur ed di s t ur bance.
[ y , u] = s mpcs i m( pmod, i mod, Ks , t end, r , ul i m, Kes t , z , v , w) ;
pl ot al l ( y , u, de l t )
paus e
0 5 10 15 20 25 30
0.2
0
0.2
0.4
0.6
0.8
1
1.2
Outputs
Time
0 5 10 15 20 25 30
0.1
0
0.1
0.2
0.3
0.4
0.5
0.6
Manipulated Variables
Time
3 M PC Based on State-Space M odels
3-18
Note that both setpoi nts are zero. The resul ti ng response i s:
The regul atory response has a rather l ong transi ent. Lets see i f we can i mprove
i t by usi ng a state esti mator other than the defaul t (DMC) esti mator:
[ Kes t , ne wmod] = s mpc es t ( i mod, [ 15 15] , [ 3 3] ) ;
Ks = s mpccon( newmod, y wt , uwt , M, P) ;
[ y , u] = s mpcs i m( pmod, newmod, Ks , t end, r , ul i m, Kes t , z , v , w) ;
pl ot al l ( y , u, del t )
0 5 10 15 20 25 30
0
0.2
0.4
0.6
0.8
1
1.2
1.4
Outputs
Time
0 5 10 15 20 25 30
0
0.1
0.2
0.3
0.4
Manipulated Variables
Time
Unconstrai ned M PC Usi ng State-Space M odels
3-19
See the detai l ed descri pti on of the s mpces t functi on for a di scussi on of the
esti mator desi gn par ameter s. The resul ts show that the control l er now
compensates for the di sturbance much more rapi dl y:
0 5 10 15 20 25 30
0.2
0
0.2
0.4
0.6
0.8
1
1.2
Outputs
Time
0 5 10 15 20 25 30
0
0.1
0.2
0.3
0.4
0.5
0.6
0.7
Manipulated Variables
Time
3 M PC Based on State-Space M odels
3-20
State-Space MPC with Constraints
The functi on s cmpc handl es probl ems wi th i nequal i ty constrai nts on the
mani pul ated vari abl es and/or outputs. The recommended procedure i s to fi rst
use the tool s descri bed i n the secti on secti on Unconstrai ned MPC Usi ng
State-Space Model s to fi nd val ues of the predi cti on hori zon, P, control hori zon,
M, i nput and output wei ghts, and a state-esti mati on strategy that work wel l for
the unconstrai ned versi on of your probl em. Then defi ne the constrai nts and
sol ve the probl em usi ng s cmpc . The fol l owi ng exampl e i l l ustrates the use of
s cmpc.
Example: (see mpct ut s s . m)
We use the same exampl e process as i n the previ ous secti on, but use a sampl i ng
peri od of 1 and omi t the unmeasured di sturbance i nput:
T = 1;
g11 = pol y 2t f d( 12. 8, [ 16. 7 1] , 0, 1) ;
g21 = pol y 2t f d( 6. 6, [ 10. 9 1] , 0, 7) ;
g12 = pol y 2t f d( - 18. 9, [ 21. 0 1] , 0, 3) ;
g22 = pol y 2t f d( - 19. 4, [ 14. 4 1] , 0, 3) ;
i mod = t f d2mod( 2, T, g11, g21, g12, g22) ;
The fol l owi ng statements speci fy parameters requi red i n both the constrai ned
and unconstrai ned cases, and cal cul ate the gai n for the unconstrai ned
control l er.
nhor = 10; % Pr edi ct i on hor i z on.
y wt = [ ] ; % Uni t y wei ght i ng on out put t r acki ng er r or s
% ( def aul t ) .
uwt = [ ] ; % Zer o we i ght i ng on man. v ar i abl e mov es
% ( def aul t ) .
bl ks = [ 2 3 5] ; % Al l ows 3 mov e s of mani pul at ed v ar i abl es .
K = [ ] ; % DMC- t y pe s t at e es t i mat i on ( def aul t ) .
Ks = s mpccon( i mod, y wt , uwt , bl ks , nhor ) ;
State-Space M PC wi th C onstrai nts
3-21
Lets fi rst veri fy that the constrai ned and unconstrai ned sol uti ons wi l l be the
same when the constrai nts are loosei .e. i nacti ve. The fol l owi ng statements
defi ne upper and l ower bounds on u(k) at - and , respecti vel y, and bounds on
u(k) at 10 (both u
1
and u
2
).
1
Al so, bounds on y(k) are set at the defaul t val ues
of .
ul i m = [ - i nf - i nf i nf i nf 10 10] ;
y l i m = [ ] ; % Def aul t - - no l i mi t s on out put s .
For the si mul ati on we wi l l make a step change of 0.8 i n the setpoi nt for y
1
. We
wi l l al so assume a perfect model , i .e., use the same model for the pl ant as was
used to desi gn the control l er.
s et pt s = [ 0. 8 0] ; % Def i ne t he s t ep i n t he s et poi nt .
pl ant = i mod;
t end = 20; % Dur at i on of t he s i mul at i on
[ y 1, u1] = s mpc s i m( pl ant , i mod, Ks , t end, s et pt s , ul i m, K) ;
[ y , u] = s cmpc( pl ant , i mod, y wt , uwt , bl ks , nhor , t end, . . .
s et pt s , ul i m, y l i m, K) ;
pl ot al l ( [ y y 1] , [ u u1] , T)
The above pl ot al l command pl ots the resul ts from s mpcs i mand s cmpc on the
same graph. Si nce the constrai nts were l oose, there shoul d be no di fference. I n
the fol l owi ng pl ots, you can onl y di sti ngui sh two curves, i .e., the two
si mul ati ons gi ve the same val ues of yand u, as expected.
1. Fi ni te bounds on u ar e requi red by s cmpc. Here they are chosen l arge enough so that they
have no effect.
3 M PC Based on State-Space M odels
3-22
Now l ets add some constrai nts to the probl em. Suppose we want the maxi mum
val ue of y
2
to be -0.1. I n the previ ous case i t goes sl i ghtl y above zero (dashed
l i ne i n the Outputs pl ot). The fol l owi ng statements defi ne a hard upper l i mi t of
y
2
=-0.1, startingat the4th stepin theprediction horizon. Thi s accounts for the
mi ni mum del ay of 3 sampl i ng peri ods before y
2
can be affected by ei ther u
1
or
u
2
, i .e., i t i s i mportant to l eave y
2
unconstrai ned for the fi rst 3 steps i n the
predi cti on hori zon. I n thi s case, si nce the i ni ti al condi ti on i s y
2
= 0, i t i s
impossibleto make y
2
-0.1 pri or to t = 4. I f you were to attempt to do so, you
woul d get an error message stati ng that the probl em i s i nfeasi bl e. Note al so
that the upper bound on y
2
supersedes the setpoi nt, whi ch i s sti l l speci fi ed as
zero. The control l er thus maxi mi zes the val ue of y
2
at steady state.
y l i m = [ - i nf - i nf i nf i nf
- i nf - i nf i nf i nf
- i nf - i nf i nf i nf
- i nf - i nf i nf - 0. 1] ;
[ y , u] = s cmpc( pl ant , i mod, y wt , uwt , bl ks , nhor , t end, . . .
s et pt s , ul i m, y l i m, K) ;
0 2 4 6 8 10 12 14 16 18 20
0.2
0
0.2
0.4
0.6
0.8
1
1.2
Outputs
Time
0 2 4 6 8 10 12 14 16 18 20
0.1
0
0.1
0.2
0.3
0.4
0.5
0.6
Manipulated Variables
Time
State-Space M PC wi th C onstrai nts
3-23
The fol l owi ng pl ot shows that the constrai nts are sati sfi ed for t 4, as expected.
I f you use a l ong predi cti on hori zon wi th constrai nts, the cal cul ati ons can be
ti me-consumi ng. You can mi ni mi ze thi s by turningoff constrai nts that are far
out i n the predi cti on hori zon. The fol l owi ng exampl e defi nes bounds on y
1
and
y
2
, then turns them off beyond the 4th poi nt i n the predi cti on hori zon. The
cal cul ati ons are much faster than woul d be the case i f onl y the fi rst 4 rows of
y l i mhad been used (try i t). Al so, si nce there i s nei ther model error nor
unmeasured di sturbances, the sol uti on sati sfi es al l constrai nts for t 4 i n any
case. I n general , output constrai nts must be chosen careful l y to avoi d
i nfeasi bi l i ti es and maxi mi ze the speed of the cal cul ati ons.
y l i m = [ - i nf - i nf i nf i nf
- i nf - i nf 0. 8 i nf
- i nf - i nf i nf i nf
- i nf 0. 10 i nf i nf ]
- i nf - i nf i nf i nf
% Tur ns of f r e mai ni ng bounds .
0 2 4 6 8 10 12 14 16 18 20
0.4
0.2
0
0.2
0.4
0.6
0.8
1
Outputs
Time
0 2 4 6 8 10 12 14 16 18 20
0
0.1
0.2
0.3
0.4
0.5
0.6
0.7
Manipulated Variables
Time
3 M PC Based on State-Space M odels
3-24
[ y , u] = s cmpc( pl ant , i mod, y wt , uwt , bl ks , nhor , t end, . . .
s et pt s , ul i m, y l i m, K) ;
pl ot al l ( y , u, T)
As a fi nal exampl e we i mpose bounds on the mani pul ated vari abl es:
ul i m = [ - 0. 5 - 0. 5 0. 5 0 0. 3 0. 3
- i nf - i nf i nf i nf 0. 3 0. 3] ;
[ y , u] = s cmpc( pl ant , i mod, y wt , uwt , bl ks , nhor , t end, . . .
s e t pt s , ul i m, y l i m, K) ;
pl ot al l ( y , u, T)
Agai n, to save computer ti me the constrai nts appl y onl y for the fi rst bl ock i n
the predi cti on hori zon, i .e., the constrai nts are turned off for peri ods 2 through
P = 10. The fol l owi ng pl ot shows that the upper bound of u
2
0 and u
1
0.3
are the most restri cti ve. The former prevents y
2
from comi ng back to the
mi ni mum al l owed val ue of 0.1.
0 2 4 6 8 10 12 14 16 18 20
0
0.2
0.4
0.6
0.8
1
Outputs
Time
0 2 4 6 8 10 12 14 16 18 20
0.1
0
0.1
0.2
0.3
0.4
0.5
0.6
Manipulated Variables
Time
State-Space M PC wi th C onstrai nts
3-25
0 2 4 6 8 10 12 14 16 18 20
0
0.2
0.4
0.6
0.8
1
Outputs
Time
0 2 4 6 8 10 12 14 16 18 20
0.1
0
0.1
0.2
0.3
0.4
Manipulated Variables
Time
3 M PC Based on State-Space M odels
3-26
Application: Paper Machine Headbox Control
Yi ng et al . (1992)
2
studi ed the control of composi ti on and l i qui d l evel i n a paper
machi ne headbox, a schemati c of whi ch i s shown i n Fi gure 3-1. The process
model i s gi ven by a set of ordi nary di fferenti al equati ons (ODEs) i n bi l i near
form. Usi ng thei r nomencl ature, the states are x
T
= [H
1
H
2
N
1
N
2
], where H
1
i s the l i qui d l evel i n the feed tank, H
2
i s that i n the headbox, N
1
i s the
consi stency (percentage of pul p fi bers i n suspensi on) i n the feed tank, and N
2
i s that i n the headbox. Al l states except H
1
are measured, i .e., the measured
outputs are y
T
= [H
2
N
1
N
2
]. The pri mary control objecti ve i s to hol d H
2
and N
2
(y
1
and y
3
) at speci fi ed setpoi nts.
There are two mani pul ated vari abl es: u
T
=[G
p
G
w
], where G
p
i s the fl owrate of
stock enteri ng the feed tank, and G
w
i s that of the recycl ed whitewater. There
i s a si ngl e measured di sturbance: v=[N
p
], the consi stency of the stock enteri ng
the feed tank, and a si ngl e unmeasured di sturbance: d = [N
w
], the consi stency
of the whi te water. Al l vari abl es are normal i zed such that they are zero at the
nomi nal steady state, and vari ati ons about the steady-state are of the same
order of magni tude. The process i s open-l oop stabl e.
2. Yi ng, Y., M. Rao, and Y. Sun, Bi l i near Control Str ategy for Paper-Maki ng Pr ocess, Chem. Eng.
Comm. 1992, 111, 1328.
Appli cati on: Paper M achi ne Headbox C ontrol
3-27
Figure 3-1 Schematic of Paper Machine Headbox Control Problem
MPC Design Based on Nominal Linear Model
The standard MPC desi gn methods requi re a l i near model of the pl ant. We
therefore l i neari ze the bi l i near model at the nomi nal steady-state condi ti on
(x = 0; u = 0; v = 0; d = 0). Si nce the model i s si mpl e, one can l i neari ze i t
anal yti cal l y to obtai n:
where x
m
, y
m
, and d
m
are the model states, outputs, and di sturbances,
respecti vel y. The desi red cl osed-l oop response ti me i s of the order of 10
mi nutes, so we choose a sampl i ng peri od of T
s
= 2 mi nutes. The fi l e pm_l i n. m
i n the di rectory mpcdemos contai ns the code for al l the computati ons i n thi s
secti on of the manual . The fol l owi ng commands defi ne the l i near model and
pl ot the response of the outputs to a uni t step i n each mani pul ated vari abl e:
Feed
Tank
Headbox
Wire
White Water
Stock
Wet Paper
H
1
N
1
H
2
N
2
N
w
N
p
G
p
G
w
x

m
Ax
m
B
0
u B
v
v B
d
d
m
+ + + =
3 M PC Based on State-Space M odels
3-28
Figure 3-2 Responses of Paper Machine Outputs to Unit Step in u
1
% Mat r i c es = of t he l i near i z ed paper machi ne model
A = [ - 1. 93 0 0 0; . 394 - . 426 0 0; 0 0 . 63 0; . 82 - . 784
. 413 - . 426] ;
B = [ 1. 274 1. 274 0 0; 0 0 0 0; 1. 34 - . 65 . 203 . 406; 0 0 0 0] ;
C = [ 0 1 0 0; 0 0 1 0; 0 0 0 1] ;
D = z er os ( 3, 4) ;
% Di s cr e t i z e t he l i near model and s av e i n mod f or m.
dt = 2;
0 10 20 30
0
0.1
0.2
0.3
0.4
0.5
0.6
0.7
u1 step response : y1
TIME
0 10 20 30
0
0.5
1
1.5
2
2.5
u1 step response : y2
TIME
0 10 20 30
0
0.5
1
1.5
2
2.5
u1 step response : y3
TIME
Appli cati on: Paper M achi ne Headbox C ontrol
3-29
[ PHI , GAM] = c2dmp( A, B, dt ) ;
mi nf o = [ dt , 4, 2, 1, 1, 3, 0] ;
i mod = s s 2mod( PHI , GAM, C, D, mi nf o) ;
pl ot s t ep( mod2s t ep( i mod, 30) )
Figure 3-3 Responses of Paper Machine Outputs to Unit Step in u
2
0 10 20 30
0
0.1
0.2
0.3
0.4
0.5
0.6
0.7
u2 step response : y1
TIME
0 10 20 30
1.4
1.2
1
0.8
0.6
0.4
0.2
0
u2 step response : y2
TIME
0 10 20 30
1
0.8
0.6
0.4
0.2
0
0.2
0.4
u2 step response : y3
TIME
3 M PC Based on State-Space M odels
3-30
The step responses (Fi gure 3-2 and Fi gure 3-3) show that there are l arge
i nteracti ons i n the open-l oop system. Adjustments i n u
1
and u
2
have strong
effects on both y
1
and y
3
. Al so, the u
2
y
3
step exhi bi ts an i nverse response.
We begi n by attempti ng a control l er desi gn for good response of both y
1
and y
3
:
% Def i ne cont r ol l er par amet er s
P = 10; % Pr edi ct i on hor i z on
M = 3; % Cont r ol hor i z on
y wt = [ 1, 0, 1] ; % Equal wei ght i ng of y ( 1) and y ( 3) ,
% no cont r ol of y ( 2)
uwt = 0. 6*[ 1 1] ; % Equal wei ght i ng of u( 1) and u( 2) .
ul i m = [ - 10*[ 1 1] 10*[ 1 1] 2*[ 1 1] ] ; % Cons t r ai nt s on u
y l i m = [ ] ; % No cons t r ai nt s on y
Kes t = [ ] ; % Us e de f aul t es t i mat or
% Si mul at i on us i ng s cmpc - - no model er r or
pmod=i mod; % pl ant and i nt er nal model ar e i dent i cal
s et pt s = [ 1 0 0] ;
% s er v o r es pons e t o s t ep i n y ( 1) s et poi nt
t end = 30; % dur at i on of s i mul at i on
[ y , u, y m] = s cmpc( pmod, i mod, y wt , uwt , M, P, t end, . . .
s et pt s , ul i m, y l i m, Kes t ) ;
pl ot al l ( y , u, dt )
The predi cti on hori zon of 10 sampl i ng peri ods (20 mi nutes) extends wel l past
the desi red cl osed-l oop response ti me. Prel i mi nary tri al s suggested that l onger
hori zons i ncreased the computati onal l oad but provi ded no advantage i n
setpoi nt tracki ng. The use of M < P i s not requi red i n thi s case, but hel ps to
reduce the computati onal l oad and i nhi bi t ri ngi ng of the mani pul ated
vari abl es. Note the equal penal ti es on setpoi nt tracki ng errors for y
1
and y
3
(y wt vari abl e), refl ecti ng our desi re to track both setpoi nts accuratel y. There i s
no penal ty on y
2
, si nce i t does not have a setpoi nt. The l i sted uwt penal ti es were
determi ned by runni ng several tri al s. Fi gure 3-4 shows smooth control of y
1
wi th the desi red 10-mi nute response ti me, but there i s a noti ceabl e di sturbance
i n y
3
.
Appli cati on: Paper M achi ne Headbox C ontrol
3-31
Figure 3-4 Response of closed-loop system to unit step in y
1
setpoint for equal
output weighting. Output y
2
is uncontrolled, and the y
3
setpoint is zero
One coul d repeat the si mul ati on for a step change i n the y
3
setpoi nt as fol l ows:
s et pt s = [ 0 0 1] ; % s er v o r es pons e t o s t ep i n y ( 3) s et poi nt
[ y , u, y m] = s cmpc( pmod, i mod, y wt , uwt , M, P, t end, . . .
s et pt s , ul i m, y l i m, Kes t ) ;
pl ot al l ( y , u, dt )
0 5 10 15 20 25 30
1
0.5
0
0.5
1
1.5
Outputs
Time
0 5 10 15 20 25 30
0
0.2
0.4
0.6
0.8
1
1.2
1.4
Manipulated Variables
Time
3 M PC Based on State-Space M odels
3-32
Normal l y, control of consi stency (y
3
) i s more i mportant than control of l i qui d
l evel , y
1
. We can achi eve better control of y
3
i f we al l ow l arger tracki ng errors
i n y
1
. For exampl e, an al ternati ve control l er desi gn uses unequal wei ghts on
the control l ed outputs:
y wt = [ 0. 2, 0, 1] ; % Unequal wei ght i ng of y ( 1) and y ( 3) ,
% no cont r ol of y ( 2)
s et pt s = [ 1 0 0] ;
% s er v o r es pons e t o s t ep i n y ( 1) s et poi nt
[ y , u, y m] = s cmpc( pmod, i mod, y wt , uwt , M, P, t end, . . .
s et pt s , ul i m, y l i m, Kes t ) ;
pl ot al l ( y , u, dt )
As shown i n Fi gure 3-5, a y
1
setpoi nt change causes a much smal l er
di sturbance i n y
3
than before (compare wi th Fi gure 3-4). The di sadvantage i s
that the response ti me of y
1
has i ncreased from about 8 to 25 mi nutes.
Si mi l arl y, a step change i n the y
3
setpoi nt woul d cause a l arger di sturbance i n
y
1
than i n the ori gi nal desi gn. Overal l , however, the control l er wi th unequal
wei ghti ng gi ves better nomi nal performance and wi l l be used as the basi s for
subsequent desi gns.
Appli cati on: Paper M achi ne Headbox C ontrol
3-33
Figure 3-5 Response of closed-loop system to Unit step in y
1
setpoint for
unequal output weighting. Output y
2
is uncontrolled, and the y
3
setpoint is
zero.
We now eval uate the response of the above control l er to a uni t step i n the
measured di sturbance, v(i .e., feedforward control ). The commands requi red for
thi s are:
s et pt s = [ 0 0 0] ; % out put
s et poi nt s z = [ ] ; % meas ur ement noi s e
v = 1; % meas ur ed di s t ur bance
d = 0; % unmeas ur ed di s t ur bance [ y , u, y m] =
s cmpc( pmod, i mod, y wt , uwt , M, P, t end, . . .
s et pt s , ul i m, y l i m, Kes t , z , v , d) ;
pl ot al l ( y , u, dt )
0 5 10 15 20 25 30
1
0.5
0
0.5
1
Outputs
Time
0 5 10 15 20 25 30
0.2
0
0.2
0.4
0.6
0.8
1
1.2
Manipulated Variables
Time
3 M PC Based on State-Space M odels
3-34
As shown i n Fi gure 3-6, both control l ed outputs are hel d near thei r setpoi nts,
wi th l arger devi ati ons i n y
1
, as expected.
Figure 3-6 Response of closed-loop system to unit step in measured
disturbance, v. unequal output weighting with y
1
and y
3
setpoints at zero.
Fi nal l y, we check the response to a step i n the unmeasured di sturbance. The
requi red commands are:
s et pt s = [ 0 0 0] ; % out put s et poi nt s
v = 0; % meas ur ed di s t ur bance
d = 1; % unmeas ur ed di s t ur bance
[ y , u, y m] = s cmpc( pmod, i mod, y wt , uwt , M, P, t end, . . .
s et pt s , ul i m, y l i m, Kes t , z , v , d) ;
pl ot al l ( y , u, dt )
0 5 10 15 20 25 30
0.04
0.02
0
0.02
0.04
0.06
0.08
0.1
Outputs
Time
0 5 10 15 20 25 30
0.2
0.15
0.1
0.05
0
0.05
0.1
0.15
Manipulated Variables
Time
Appli cati on: Paper M achi ne Headbox C ontrol
3-35
As shown i n Fi gure 3-7, the unmeasured di sturbance causes si gni fi cant
devi ati ons i n both control l ed outputs. I n fact, the hi gher-pri ori ty output, y
3
,
exhi bi ts the l arger tracki ng error of the two control l ed vari abl es.
Figure 3-7 Response of closed-loop system (with default state estimator) to
unit step in unmeasured disturbance, d. unequal output weighting with y
1

and y
3
setpoints at zero.
The cl osed-l oop response to unmeasured di sturbances can often be i mproved by
a change i n the state esti mator. I n the previ ous tri al s, we were usi ng the
defaul t esti mator, whi ch assumes that di sturbances are i ndependent, random
steps at each output. I n fact, the known unmeasured di sturbance, d, has no
effect on y
1
, and i ts effects on y
2
and y
3
are approxi matel y fi rst order wi th ti me
constants of 3 and 5 mi nutes, respecti vel y. One way to expl oi t thi s knowl edge
i s to speci fy an expected covari ance for d and a measurement noi se covari ance
for y, then use the Kal man gai n for the model ed di sturbance characteri sti cs.
0 5 10 15 20 25 30
0.2
0.1
0
0.1
0.2
0.3
0.4
0.5
Outputs
Time
0 5 10 15 20 25 30
0.4
0.3
0.2
0.1
0
0.1
0.2
0.3
Manipulated Variables
Time
3 M PC Based on State-Space M odels
3-36
Consi der the fol l owi ng sequence of commands, l eadi ng to the responses shown
i n Fi gure 3-8:
Figure 3-8 Response of closed-loop system to unit step in unmeasured
disturbance, d. with Kalman Estimator, unequal output weighting with y
1
and
y
3
setpoints at zero.
% Es t i mat or des i gn
Q = 30;
R = 1*ey e( 3) ;
Kes t = s mpces t ( i mod, Q, R) ;
% Si mul at i on us i ng s cmpc - - no model er r or
s et pt s = [ 0 0 0] ; % s er v o r es pons e t o s t ep i n y 1 s et poi nt
d = 1; % unmeas ur ed di s t ur bance
[ y , u, y m] = s cmpc( pmod, i mod, y wt , uwt , M, P, t end, . . .
s et pt s , ul i m, y l i m, Kes t , z , v , d) ;
pl ot al l ( y , u, dt )
0 5 10 15 20 25 30
0.2
0.1
0
0.1
0.2
0.3
0.4
0.5
Outputs
Time
0 5 10 15 20 25 30
0.4
0.3
0.2
0.1
0
0.1
0.2
0.3
Manipulated Variables
Time
Appli cati on: Paper M achi ne Headbox C ontrol
3-37
The resul ti ng Kest matri x i s:
Kes t =
0 0 0
0. 0000 - 0. 0000 0. 0000
0. 0000 0. 7446 0. 0732
- 0. 0000 0. 2985 0. 0851
0. 0000 - 0. 0000 0. 0000
- 0. 0000 0. 7777 0. 2934
0. 0000 0. 2934 0. 1977
We have speci fi ed equal measurement noi se for each output (Ri s di agonal wi th
a rank equal to the number of outputs, and equal el ements on the di agonal ).
Thi s makes the Kal man esti mator gi ve equal wei ght to each output
measurement.
3
The di mensi on of Qmust equal the number of el ements i n d
(uni ty i n thi s case). A rel ati vel y l arge val ue of Q( i , i ) si gni fi es an i mportant
di sturbance mode. I n practi ce, the el ements of Qand R are tuni ng parameters,
and one adjusts the rel ati ve magni tudes to achi eve the desi red bal ance of fast
di sturbance rejecti on (usual l y promoted by maki ng Q rel ati vel y l arge) and
robustness.
For the chosen Qand R, and the di sturbance model i n i mod, the el ements of
col umn 1 of Kes t (shown above) are essenti al l y zero. Thus, the measurement of
y
1
provi des no i nformati on regardi ng the effect of d on the process states.
Output y
2
, on the other hand, provi des l arge correcti ons to the state esti mates.
I f i t were not avai l abl e, rejecti on of d woul d degrade.
4
Fi gure 3-8 shows that al though the revi sed esti mator reduced the di sturbance
i n y
3
, i t i s sti l l si gni fi cant (compare to Fi gure 3-7). A key l i mi ti ng factor i s the
use of a 2-mi nute sampl i ng peri od. As shown i n Fi gure 3-8, the control l er does
not respond to the di sturbance unti l i t i s fi rst detected at t =2 mi nutes. You can
veri fy that reduci ng the sampl i ng peri od to 0.25 mi nutes (hol di ng al l other
parameters constant) greatl y reduces the di sturbance i n y
3
. Such a change
woul d al so speed up the setpoi nt tracki ng i n the nomi nal case. I t may cause
robustness probl ems, however, so we defer further consi derati on of the
sampl i ng peri od to tests wi th the nonl i near pl ant (see next secti on).
Thi s appl i cati on i s unusual i n that the characteri sti cs of the unmeasured
di sturbance are known. When thi s i s not the case, the output disturbanceform
3. I f a measurement were known to be i naccurate, i ts R( i , i ) val ue shoul d be rel ati vel y l ar ge.
4. You can see how ser i ous the degr adati on woul d be by setti ng R( 2, 2) to a l ar ge val ue,
e.g.,10000.
3 M PC Based on State-Space M odels
3-38
of the esti mator si mpl i fi es the desi gn procedure. I t requi res onl y a rough i dea
of the characteri sti c ti mes for the di sturbances, and the si gnal -to-noi se rati o for
each output. For exampl e, you can veri fy that the fol l owi ng desi gn rejects the
d di sturbance al most as wel l as the optimal Kal man desi gn:
% Al t er nat i v e es t i mat or des i gn - - out put di s t ur bances
t aus = [ 5 5 5] ;
s i gnoi s e = [ 10 10 10] ;
[ Kes t , newmod] = s mpces t ( i mod, t aus , s i gnoi s e) ;
% Si mul at i on us i ng s cmpc - - no model er r or
[ y , u, y m] = s cmpc( pmod, newmod, y wt , uwt , M, P, t end, . . .
s et pt s , ul i m, y l i m, Kes t , z , v , d) ;
pl ot al l ( y , u, dt )
MPC of Nonlinear Plant
We are now ready to test the control l er desi gn on the real (nonl i near) pl ant. A
speci al versi on of the s cmpc functi on (cal l ed s cmpcnl ) i s avai l abl e for thi s
purpose. I t uses a nonl i near pl ant model i n the S-functi on format requi red by
Si mul i nk. (See the Si mul i nk documentati on for more i nformati on on how to
wri te such model s.) The model of the paper machi ne i s i n the fi l e pap_mach. m.
Si mul ati ons wi th Si mul i nk i nvol vi ng nonl i near model s usual l y take much
l onger (by an order of magni tude) than l i near si mul ati ons of a pl ant of
comparabl e compl exi ty. Thi s i s especi al l y l i kel y i f the pl ant model i s i n the form
of an .M fi l e, as i s the case here. I f such model s are to be used extensi vel y, i t
may be worthwhi l e to code them as a . mex fi l e (see MATLAB documentati on).
To see how wel l the MPC desi gn rejects the d di sturbance of Fi gure 3-8, we
coul d use the commands found i n the fi l e pm_nonl . mi n the di rectory
mpcdemos . The onl y di fferences between these commands and those for the
ori gi nal l i near si mul ati on are:
We have defi ned the i ni ti al val ues of the pl ant state and mani pul ated
vari abl es (x 0 and u0, respecti vel y).
A step si ze for numeri cal i ntegrati on has been speci fi ed. The val ue of 0.05
mi nutes provi des reasonabl e accuracy i n thi s appl i cati on. I n general , one
must choose the step si ze to fi t the probl em (or use a vari abl e step-si ze
i ntegrati on method, as provi ded by Si mul i nk).
You can veri fy that the resul ts are nearl y i denti cal to those shown i n Fi gure
3-8. I n other words, the nonl i neari ti es i n the pl ant have caused negl i gi bl e
Appli cati on: Paper M achi ne Headbox C ontrol
3-39
performance degradati on. Very si mi l ar resul ts are al so obtai ned for the
setpoi nt change of Fi gure 3-4.
As the magni tude of the di sturbance (or setpoi nt change) i ncreases, nonl i near
effects become si gni fi cant. For exampl e, Fi gure 3-9 i s for a step i n d of 7 uni ts.
I f the pl ant were l i near, the curves i n Fi gure 3-9 woul d be the same shape as
those i n Fi gure 3-8, but scal ed by a factor of 7. Al though thi s i s approxi matel y
true, there are some qual i tati ve di fferences. For exampl e, at t = 8 mi nutes i n
Fi gure 3-9, y
2
has gone bel ow y
1
, whereas i n Fi gure 3-8, y
2
> y
1
at al l ti mes.
Figure 3-9 As for Figure 3-8, but With Nonlinear Plant, and Step in d of 7
Units
5 10 15 20 25 0
-1
-2
-3
0
3
2
1
4
-4
30
y2
y3
y1
Outputs
Time
Manipulated Variables
-3
-4
-2
2
0
-1
1
5 10 15 20 25 0 30
u2
u1
Time
3 M PC Based on State-Space M odels
3-40
I f d i s i ncreased to 8, control qual i ty degrades dramati cal l y and the maxi mum
tracki ng error i n y
3
goes to about -10
5
(not shown). Thi s i s caused by changes
i n the pl ant characteri sti cs as i t moves away from the nomi nal state (i .e.,
causi ng errors i n the MPCs l i near model ).
Sensi ti vi ty to model i ng error can often be reduced by de-tuningthe control l er.
A common approach i s to i ncrease the magni tudes of the uwt parameters. When
nonl i near effects are severe, however, i t may be i mpossi bl e for any
ti me-i nvari ant, l i near control l er to provi de stabl e, offset-free performance. I n
that case, i f the nonl i near effects are predi ctabl e, one mi ght try MPC based on
a nonl i near model (e.g., Gattu and Zafi ri ou, 1992).
5
Scri pts for thi s purpose can
be devel oped usi ng the functi ons i n thi s tool box.
As a fi nal test, l ets repeat the si mul ati on of Fi gure 3-8 wi th a control l er
sampl i ng peri od of 0.25 mi nutes (recal l that the ori gi nal sampl i ng peri od was
2 mi nutes). Resul ts appear i n Fi gure 3-10. Compared to Fi gure 3-8, whi ch had
no model error (i .e., l i near pl ant), we reduced the di sturbance i n y
3
by a factor
of 3. Thus, a reducti on i n sampl i ng peri od may not l ead to robustness probl ems,
and shoul d be tested more thoroughl y. You can veri fy that i t works wel l for
other combi nati ons of small di sturbances and setpoi nt changes.
5. Gattu, G. and E. Zafi r i ou, Nonl i near Quadr ati c Dynami c Matr i x Contr ol wi th State
Esti mati on, I nd. Eng. Chem. Research, 1992, 31, 10961104.
Appli cati on: Paper M achi ne Headbox C ontrol
3-41
Figure 3-10 As for Figure 3-8, (d = 1) but With Nonlinear Plant, Sampling
Period of 0.25 Minutes
0
-0.05
-0.1
0.05
0.2
0.15
0.1
0.25
-0.15
5 10 15 20 25 0 30
y2
y3
y1
Outputs
Time
Manipulated Variables
Time
5 10 15 20 25 0 30
-0.1
-0.2
0.2
0.1
0
0.3
-0.3
u2
u1
3 M PC Based on State-Space M odels
3-42
4
Command Reference
4 C ommand Reference
4-2
Commands Grouped by Function
Identification
aut os c Automati cal l y scal es a matri x by i ts means and standard
devi ati ons.
i mp2s t e p Combi nes MI SO i mpul se response model s to form MI MO
model s i n MPC step format.
ml r Cal cul ates MI SO i mpul se response model vi a mul ti -
vari abl e l i near regressi on.
pl s r Cal cul ates MI SO i mpul se response model vi a parti al l east
squares regressi on.
r es cal Converts scal ed data back to i ts ori gi nal form.
s cal Scal es a matri x by speci fi ed means and standard
devi ati ons.
v al i dmod Val i dates a MI SO i mpul se response model usi ng new data.
wr t r eg Wri tes data matri ces used for regressi on.
Plotting and Matrix Information
mpci nf o Outputs matri x type and attri butes of system
representati on.
pl ot al l Pl ots outputs and i nputs from a si mul ati on run on one
graph.
pl ot f r s p Pl ots the frequency response of a system as a Bode pl ot.
pl ot eac h Makes separate pl ots of outputs and/or i nputs from a
si mul ati on run.
pl ot s t e p Pl ots the coeffi ci ents of a model i n MPC step form.
C ommands G rouped by Functi on
4-3
Model Conversions
c 2dmp Converts state-space model from conti nuous ti me to
di screte-ti me. (Equi val ent to c2d i n Control System
Tool box)
c p2dp Converts from a conti nuous to a di screte transfer functi on
i n poly format.
d2cmp Converts state-space model from di screte-ti me to
conti nuous ti me. (Equi val ent to d2c i n Control System
Tool box)
mod2mod Changes sampl i ng peri od of a model i n MPC mod format.
mod2s s Converts a model i n MPC mod format to a state-space
model .
mod2s t ep Converts a model i n MPC mod format to MPC step
format.
pol y 2t f d Converts a transfer functi on i n poly format to MPC tf
format.
s s 2mod Converts a state-space model to MPC mod format.
s s 2s t ep Converts a state-space model to MPC step format.
s s 2t f 2 Converts state-space model to transfer functi on.
(Equi val ent to s s 2t f i n Control System Tool box)
t f 2s s m Converts transfer functi on to state-space model .
(Equi val ent to t f 2s s i n Control System Tool box)
t f d2mod Converts a model i n MPC tf for mat to MPC mod format.
t f d2s t ep Converts a model i n MPC tf for mat to MPC step format.
t h2mod Converts a model i n theta format (System I denti fi cati on
Tool box) i nto MPC mod format.
4 C ommand Reference
4-4
Model Building MPC mod format
addmd Adds one or more measured di sturbances to a pl ant model .
addmod Combi nes two model s such that the output of one adds to the
i nput of the other.
addumd Adds one or more unmeasured di sturbances to a pl ant model .
appmod Appends two model s i n an unconnected, paral l el structure.
par amod Puts two model s i n paral l el such that they share a common
output.
s er mod Puts two model s i n seri es.
Controller Design and Simulation MPC step format
cmpc Sol ves the quadrati c programmi ng probl em to si mul ate
performance of a cl osed-l oop system wi th i nput and output
constrai nts.
mpccl Creates a model i n MPC mod format of a cl osed-l oop
system wi th an unconstrai ned MPC control l er.
mpccon Cal cul ates the unconstrai ned control l er gai n matri x for
MPC.
mpcs i m Si mul ates a cl osed-l oop system wi th opti onal saturati on
constrai nts on the mani pul ated vari abl es.
nl cmpc Si mul i nk S-functi on bl ock for MPC control l er wi th i nput
and output constrai nts (sol ves quadrati c program).
nl mpcs i m Si mul i nk S-functi on bl ock for MPC control l er wi th opti onal
saturati on constrai nts.
C ommands G rouped by Functi on
4-5
Controller Design and Simulation MPC mod format
s cmpc Sol ves the quadrati c programmi ng probl em to si mul ate
performance of a cl osed-l oop system wi th i nput and output
constrai nts.
s mpccl Creates a model i n MPC mod format of a cl osed-l oop system
wi th an unconstrai ned MPC control l er.
s mpccon Cal cul ates the unconstrai ned control l er gai n matri x for MPC.
s mpces t Desi gns a state esti mator for use i n MPC.
s mpcs i m Si mul ates a cl osed-l oop system wi th opti onal saturati on
constrai nts on the mani pul ated vari abl es.
Analysis
mod2f r s p Cal cul ates frequency response for a system i n MPC mod
format.
s mpcgai n Cal cul ates steady-state gai n matri x of a system i n MPC mod
format.
s mpcpol e Cal cul ates pol es of a system i n MPC mod format.
s v df r s p Cal cul ates si ngul ar val ues of a frequency response.
4 C ommand Reference
4-6
Utility Functions
abcdchkm Checks di mensi onal consi stency of (A,B,C,D) set.
(Equi val ent to abcdchk i n Control System Tool box)
dant z gmp Sol ves quadrati c programs.
dar ei t e r Sol ves di screte Ri ccati equati on by an i terati ve method.
di mpul s m Generates i mpul se response of di screte-ti me system.
(Equi val ent to di mpul s e i n Control System Tool box)
dl qe2 Cal cul ates state-esti mator gai n matri x for di screte systems.
dl s i mm Si mul ates di screte-ti me systems. (Equi val ent to dl s i mi n
Control System Tool box)
mpcaugs s Augments a state-space model wi th i ts outputs.
mpcpar al Puts two state-space model s i n paral l el .
nar gchkm Checks number of M-fi l e arguments. (Equi val ent to nar gchk
i n Control System Tool box)
mpcs t ai r Creates the stairstep format used to pl ot mani pul ated
vari abl es.
v ec2mat Converts a vector to a matri x.
addmd
4-7
1addmd
Purpose Adds one or more measured di sturbances to a pl ant model i n the MPC mod
format. Used to al l ow for feedforward compensati on i n MPC.
Syntax model = addmd( pmod, dmod)
Description The di sturbance model contai ned i n dmod adds to the pl ant model contai ned i n
pmod to form a composi te, model , wi th the structure gi ven i n the fol l owi ng bl ock
di agram:
pmod, dmod and model are i n the MPC mod format (see mod i n the onl i ne
MATLAB Function Referencefor a detai l ed descri pti on). You woul d normal l y
create pmod and dmod usi ng ei ther the t f d2mod, s s 2mod or t h2mod functi ons.
addmd i s a speci al i zed versi on of par amod. I ts mai n advantage over par amod i s
that i t assumes al l the i nputs to dmod are to be measured di sturbances. Thi s
saves you the troubl e of desi gnati ng the i nput types i n a separate step.
Example See s s 2mod for an exampl e of the use of thi s functi on.
Algorithm addmd converts pmod and dmod i nto thei r state-space form, then uses the
mpcpar al functi on to bui l d the composi te model .
Restrictions pmod and dmod must have been created wi th equal sampl i ng peri ods and
number of output vari abl es.
pmod must not i ncl ude measured di sturbances, i .e., i ts mod format must
speci fy n
d
= 0.
Al l i nputs to dmod must be cl assi fi ed as mani pul ated vari abl es. (They wi l l be
recl assi fi ed automati cal l y as measured di sturbances i n model .) So the mod
format of dmod must speci fy n
d
= n
w
= 0 (whi ch i s the defaul t for al l model
creati on functi ons).
See Also addmod, addumd, appmod, par amod, s er mod
dmod
w
d
model

y
+
+
u
y
d
pmod
w
u
addmod
1-8
1addmod
Purpose Combi nes two model s i n the MPC mod format such that the output of one
combi nes wi th the manipulatedi nputs of the other. Thi s functi on i s speci al i zed
and rarel y needed. I ts mai n purpose i s to bui l d up a model of a compl ex
structure that i ncl udes the si tuati on shown i n the di agram bel ow.
Syntax pmod = addmod( mod1, mod2)
Description The output(s) of mod2 add to the mani pul ated vari abl e(s) of mod1 to form a
composi te system, pmod, wi th the structure gi ven i n the fol l owi ng bl ock
di agram:
pmod, mod1 and mod2 are i n the MPC mod format (see mod i n the onl i ne
MATLAB Function Referencefor a detai l ed descri pti on). You woul d normal l y
create mod1 and mod2 usi ng ei ther the t f d2mod, s s 2mod or t h2mod functi ons.
The di fferent i nput typesassoci ated wi th mod1 and mod2 wi l l be retai ned i n pmod
and wi l l be ordered as shown i n the di agram.
Example See mod2s s for an exampl e of the use of thi s functi on.
Restrictions mod1 and mod2 must have been created wi th equal sampl i ng peri ods.
The number of mani pul ated vari abl es i n mod1 must equal the number of
output vari abl es i n mod2.
See Also addmd, addumd, appmod, par amod, s er mod
mod2
pmod

y
+
+
u
1
y
mod1
u
2
d
1
d
2
w
1
w
2
u
1
u
2
d
1
d
2
w
1
w
2
addumd
4-9
1addumd
Purpose Adds one or more unmeasured di sturbances to a pl ant model i n MPC mod
format. Used for si mul ati on of di sturbances and for desi gn of state esti mators
i n MPC.
Syntax model = addumd( pmod, dmod)
Description The di sturbance model contai ned i n dmod adds to the pl ant model contai ned i n
pmod to form a composi te, model , wi th the structure gi ven i n the fol l owi ng bl ock
di agram:
pmod, dmod and model are i n the MPC mod format (see mod i n the onl i ne
MATLAB Function Referencefor a detai l ed descri pti on). You woul d normal l y
create pmod and dmod usi ng ei ther the t f d2mod, s s 2mod or t h2mod functi ons.
addumd i s a speci al i zed versi on of par amod. I ts mai n advantage over par amod i s
that i t assumes al l the i nputs to dmod are to be unmeasured di sturbances. Thi s
saves you the troubl e of desi gnati ng the i nput types i n a separate step.
Example See s s 2mod for an exampl e of the use of thi s functi on.
Algorithm addumd converts pmod and dmod i nto thei r state-space form, then uses the
mpcpar al functi on to bui l d the composi te model .
Restrictions pmod and dmod must have been created wi th equal sampl i ng peri ods and
number of output vari abl es.
pmod must not i ncl ude unmeasured di sturbances, i .e., i ts mod format must
speci fy n
w
= 0.
Al l i nputs to dmod must be cl assi fi ed as mani pul ated vari abl es. (They wi l l be
recl assi fi ed automati cal l y as unmeasured di sturbances i n model .) So the
mod format of dmod must speci fy n
d
= n
w
= 0 (whi ch i s the defaul t for al l
model creati on functi ons).
See Also addmod, addmd, appmod, par amod, s er mod, s mpces t
dmod
w
d model

y
+
+
u
y
d
pmod
d
u
appmod
1-10
1appmod
Purpose Appends two model s to form a composi te model that retai ns the i nputs and
outputs of the ori gi nal model s. I n other words, for model s i n the MPC mod
format appmod repl aces the append functi on of the Control Tool box.
Syntax pmod = appmod( mod1, mod2)
Description The two i nput model s combi ne as shown i n the fol l owi ng bl ock di agram:
mod1, mod2 and pmod are i n the MPC mod format (see mod i n the onl i ne
MATLAB Function Referencefor a detai l ed descri pti on). You woul d normal l y
create mod1 and mod2 usi ng ei ther the t f d2mod, s s 2mod, or t h2mod functi on.
Restriction mod1 and mod2 must have been created wi th equal sampl i ng peri ods.
See Also addmod, addmd, addumd, par amod, s er mod
mod1
y
2
mod2
u
1
d
1
w
1
u
2
d
2
w
2
y
1
y
2
y
1
pmod
u
1
u
2
d
1
d
2
w
1
w
2
autosc, scal, rescal
4-11
1autosc, scal , rescal
Purpose Scal es a matri x automati cal l y or by speci fi ed mean and standard devi ati on.
Syntax [ ax , mx , s t dx ] = aut os c( x )
s x = s cal ( x , mx )
s x = s cal ( x , mx , s t dx )
r x = r es cal ( x , mx )
r x = r es cal ( x , mx , s t dx )
Description aut os c scal es an i nput matri x or vector x by i ts col umn means (mx ) and
standard devi ati ons (s t dx) automati cal l y and outputs mx and s t dx as opti ons.
By usi ng s cal , the i nput can al so be scal ed by some speci fi ed means and/or
standard devi ati ons. rescal converts scal ed data back to ori gi nal data.
Output mx i s a rowvector contai ni ng the mean val ue for each col umn of x whi l e
s t dx i s a rowvector contai ni ng the standard devi ati on for each col umn.
Outputs ax and s x are obtai ned by di vi di ng the di fference of each col umn of x
and the mean for the col umn by the standard devi ati on for the col umn, i .e.,
ax ( : , i ) = ( x : , i ) mx ( i ) /s t dx ( i ) . Output r x i s determi ned by mul ti pl yi ng
each col umn of x by the correspondi ng standard devi ati on and addi ng the
correspondi ng mean to that product.
I f onl y two arguments are speci fi ed i n s c al or r es cal , x i s scal ed by speci fi ed
means (mx) onl y.
Example See ml r for an exampl e of the use of these functi ons.
See Also ml r , pl s r , wr t r eg
cmpc
1-12
1cmpc
Purpose Si mul ates cl osed-l oop systems wi th hard bounds on mani pul ated vari abl es
and/or outputs usi ng model s i n the MPC step format. Sol ves the MPC
opti mi zati on probl em by quadrati c programmi ng.
Syntax y p = cmpc( pl ant , model , y wt , uwt , M, P, t end, r )
[y p,u,y m] = cmpc (pl ant,model ,y wt ,uwt ,M,P,tend,...
r,ul i m,y l i m,t f i l t er ,dpl ant ,dmodel ,ds t ep)
Description
cmpc si mul ates the performance of the type of system shown i n the above
di agram when there are bounds on the mani pul ated vari abl es and/or outputs.
Measurement noi se can be si mul ated by treati ng i t as an unmeasured
di sturbance.
The requi red i nput vari abl es are as fol l ows:
pl ant
I s a model i n the MPC step format that represents the pl ant.
model
I s a model i n the MPC stepformat that i s to be used for state esti mati on i n the
control l er. I n general , i t can be di fferent from pl ant i f you want to si mul ate the
effect of pl ant/control l er model mi smatch.
y
Disturbance
Model
Controller
Disturbances

u
d
+
+
r
Plant
Plant
Disturbance
Setpoints
Plant
Outputs
d
y
cmpc
4-13
ywt
I s a matri x of wei ghts that wi l l be appl i ed to the setpoi nt tracki ng errors. I f
y wt =[ ] , the defaul t i s equal (uni ty) wei ghti ng of al l out- puts over the enti re
predi cti on hori zon. I f y wt [ ] , i t must have n
y
col umns, where n
y
i s the number
of outputs. Al l wei ghts must be 0.
You may vary the wei ghts at each step i n the predi cti on hori zon by i ncl udi ng
up to Prows i n y wt . Then the fi rst row of n
y
val ues appl i es to the tracki ng errors
i n the fi rst step i n the predi cti on hori zon, the next row appl i es to the next step,
etc. See mpccon for detai l s on the form of the opti mi zati on objecti ve functi on.
I f you suppl y onl y nrowrows, where 1 nrow< P, cmpc wi l l use the l ast row to
fi l l i n any remai ni ng steps. Thus i f you want the wei ghti ng to be the same for
al l P steps, you need onl y speci fy a si ngl e row.
uwt
Same format as y wt , except that uwt appl i es to the changes i n the mani pul ated
vari abl es. I f you use uwt = [ ] , the defaul t i s zero wei ghti ng. I f uwt [ ] , i t
must have n
u
col umns, where n
u
i s the number of mani pul ated vari abl es.
M
There are two ways to speci fy thi s vari abl e:
I f i t i s a scalar, cmpc i nterprets i t as the i nput hori zon (number of moves) as i n
DMC.
I f i t i s a rowvector contai ni ng n
b
el ements, each el ement of the vector i ndi cates
the number of steps over whi ch u = 0 duri ng the opti mi zati on and cmpc
i nterprets i t as a set of n
b
bl ocki ng factors. There may be 1 n
b
P bl ocki ng
factors, and thei r sum must be P
I f you set M=[ ] and P I nf , the defaul t i s M=P, whi ch i s equi val ent to
M=one s ( 1, P) . The defaul t val ue for Mi s 1 i f P=I nf .
P
The number of sampl i ng peri ods i n the predi cti on hori zon. I f P=I nf , the
predi cti on hori zon i s i nfi ni te.
tend
I s the desi red durati on of the si mul ati on (i n ti me uni ts).
cmpc
1-14
r
I s a setpoi nt matri x consi sti ng of N rows and n
y
col umns, where n
y
i s the
number of output vari abl es, y:
where r
i
(k) i s the setpoi nt for output j at ti me t =kT, and T i s the sampl i ng
peri od (as speci fi ed i n the step format of pl ant and model ). I f t end > NT, the
setpoi nts vary for the fi rst N peri ods i n the si mul ati on, as speci fi ed by r , and
are then hel d constant at the val ues gi ven i n the l ast row of r for the remai nder
of the si mul ati on.
I n many si mul ati ons one wants the setpoi nts to be constant for the enti re ti me,
i n whi ch case r need onl y contai n a si ngl e row of n
y
val ues.
I f you set r =[ ] , the defaul t i s a row of n
y
zeros.
The fol l owi ng i nput vari abl es are opti onal . I n general , setti ng one of them
equal to an empty matri x causes cmpc to use the defaul t val ue, whi ch i s gi ven
i n the descri pti on.
r
r
1
1 ( ) r
2
1 ( ) r
n
y
1 ( )
r
1
2 ( ) r
2
2 ( ) r
n
y
2 ( )

r
1
N ( ) r
2
N ( ) r
n
y
N ( )
=

cmpc
4-15
ul i m
I s a matri x gi vi ng the l i mi ts on the mani pul ated vari abl es. I ts format i s as
fol l ows:
Note that i t contai ns three matri ces of N rows. I n thi s case, the l i mi ts on N are
1 N n
b
, where n
b
i s the number of ti mes the mani pul ated vari abl es are to
change over the i nput hori zon. I f you suppl y fewer than n
b
rows, the l ast row
i s repeated automati cal l y.
The fi rst matri x speci fi es the lower bounds on the n
u
mani pul ated vari abl es.
For exampl e, u
min
,
j
(2) i s the l ower bound for mani pul ated vari abl e j for the
second move of the mani pul ated vari abl es (where the fi rst move i s at the start
of the predi cti on hori zon). I f u
min
,
j
(k) = inf, mani pul ated vari abl e j wi l l have
no l ower bound for that move.
The second matri x gi ves the upper bounds on the mani pul ated vari abl es. I f
u
max,j
(k) =inf, mani pul ated vari abl e j wi l l have no upper bound for that move.
, ,
, ,
, ,
,
( )
,
( )
u
max 1 ,
1 ( ) u
max n
u
,
1 ( )
u
max 1 ,
2 ( ) u
max n
u
,
2 ( )

u
max 1 ,
N ( ) u
max n
u
,
N ( )

, ,
, ,
, ,
,
( )
,
( )
ulim
u
mi n 1 ,
1 ( ) u
mi n n
u
,
1 ( )
u
mi n 1 ,
2 ( ) u
mi n n
u
,
2 ( )

u
mi n 1 ,
N ( ) u
mi n n
u
,
N ( )
=
u
max 1 ,
1 ( ) u
max n
u
,
1 ( )
u
max 1 ,
2 ( ) u
max n
u
,
2 ( )

u
max 1 ,
N ( ) u
max n
u
,
N ( )


cmpc
1-16
The l ower and upper bounds may be ei ther posi ti ve or negati ve (or zero) as l ong
as u
min
,
j
(k) u
max,j
(k).
The thi rd matri x gi ves the l i mi ts on the rate of change of the mani pul ated
vari abl es. I n other words, cmpc wi l l force| u
j
(k) u
j
(k 1)| u
max,j
(k). The
l i mi ts on the rate of change must be nonnegati ve and finite. I f you want i t to be
unbounded, set the bound to a l arge number (but not too l arge a val ue of 10
6
shoul d work wel l i n most cases).
The defaul t i s u
min
= inf, u
max
=inf and u
max
= 10
6
yl i m
Same i dea as for ul i m, but for the l ower and upper bounds of the outputs. The
fi rst row appl i es to the fi rst poi nt i n the predi cti on hori zon. The defaul t i s y
min
= inf, and y
max
=inf.
tf i l ter
I s a matri x of ti me constants for the noi se fi l ter and the unmeasured
di sturbances enteri ng at the pl ant output. The fi rst row of n
y
el ements gi ves
the noi se fi l ter ti me constants and the second row of n
y
el ements gi ves the ti me
constants of the l ags through whi ch the unmeasured di sturbance steps pass. I f
t f i l t er onl y contai ns one row, the unmeasured di sturbances are assumed to
be steps. I f you set t f i l t er =[ ] or omi t i t, the defaul t i s no noi se fi l teri ng and
stepl i ke unmeasured di sturbances.
dpl ant
I s a model i n MPC stepformat representi ng al l the di sturbances (measured and
unmeasured) that affect pl ant i n the above di agram. I f dpl ant i s provi ded,
then i nput ds t ep i s al so requi red. For output step di sturbances, set
dpl ant =[ ] . The defaul t i s no di sturbances.
dmodel
I s a model i n MPC step format representi ng the measured di sturbances. I f
dmodel i s provi ded, then i nput ds t ep i s al so requi red. I f there are no measured
di sturbances, set dmodel =[ ] . For output step di sturbances, set dmodel =[ ] . I f
there are both measured and un- measured di sturbances, set the col umns of
dmodel correspondi ng to the unmeasured di sturbances to zero. The defaul t i s no
measured di sturbances.
cmpc
4-17
dstep
I s a matri x of di sturbances to the pl ant. For output step di sturbances
(dpl ant =[ ] and dmodel =[ ] ), the format i s the same as for r . For di sturbances
through step-response model s (dpl ant onl y or both dpl ant and dmodel
nonempty), the format i s the same as for r , except that the number of col umns
i s n
d
rather than n
y
. The defaul t i s a row of zeros.
Notes You may use a di fferent number of rows i n the matri ces r , ul i m, y l i mand
ds t ep, shoul d that be appropri ate for your si mul ati on.
The ul i mconstrai nts used here are fundamental l y di fferent from the us at
constrai nts used i n the mpcs i mfuncti on. The ul i mconstrai nts are defi ned
rel ati ve to the begi nni ng of the predi cti on hori zon, whi ch moves as the
si mul ati on progresses. Thus at each sampl i ng peri od, k, the ul i mconstrai nts
appl y to a bl ock of cal cul ated moves that begi n at sampl i ng peri od k and
extend for the durati on of the i nput hori zon. The us at constrai nts, on the
other hand, are rel ati ve to the fi xed poi nt t = 0, the start of the si mul ati on.
The cal cul ated outputs are as fol l ows (al l but y p are opti onal ):
yp
I s a matri x contai ni ng M rows and n
y
col umns, where M =max(fix(tend=T) +1,
2). The fi rst row wi l l contai n the i ni ti al condi ti on, and row k 1 wi l l gi ve the
val ues of the pl ant outputs, y (see above di agram), at ti me t =kT.
u
I s a matri x contai ni ng the same number of rows as y p and n
u
col umns. The ti me
correspondi ng to each row i s the same as for y p. The el ements i n each row are
the val ues of the mani pul ated vari abl es, u (see above di agram).
ym
I s a matri x of the same structure as y p, contai ni ng the val ues of the predi cted
output from the state esti mator i n the control l er. These wi l l , i n general , di ffer
from those i n y p i f model pl ant and/or there are unmeasured di sturbances.
Theprediction includes theeffect of themost recent measurement, i.e., i t i s
.
For unconstrai ned probl ems, cmpc and mpcs i mshoul d gi ve the same resul ts.
The l atter wi l l be faster because i t uses an anal yti cal sol uti on of the QP
probl em, whereas cmpc sol ves i t by i terati on.
y k k ( )
cmpc
1-18
Examples Consi der the l i near system:
The fol l owi ng statements bui l d the model and set up the control l er i n the same
way as i n the mpcs i mexampl e.
g11=pol y 2t f d( 12. 8, [ 16. 7 1] , 0, 1) ;
g21=pol y 2t f d( 6. 6, [ 10. 9 1] , 0, 7) ;
g12=pol y 2t f d( - 18. 9, [ 21. 0 1] , 0, 3) ;
g22=pol y 2t f d( - 19. 4, [ 14. 4 1] , 0, 3) ;
del t =3; ny =2; t f i nal =90;
model =t f d2s t ep( t f i nal , del t , ny , g11, g21, g12, g22) ;
pl ant =model ;
P=6; M=2; y wt =[ ] ; uwt =[ 1 1] ;
t end=30; r =[ 0 1] ;
Here, however, we wi l l demonstrate the effect of constrai nts. Fi rst we set a
l i mi t of 0.1 on the rate of change of u
1
and a mi ni mum of 0.15 for u
2
.
ul i m=[ - i nf - 0. 15 i nf i nf 0. 1 100] ;
y l i m=[ ] ;
[ y , u] =cmpc( pl ant , model , y wt , uwt , M, P, t end, r , ul i m, y l i m) ;
pl ot al l ( y , u, del t ) , paus e
y
1
s ( )
y
2
s ( )
12.8e
s
16.7s 1 +
------------------------
18.9e
3s
21.0s 1 +
-------------------------
6.6e
7s
10.9s 1 +
------------------------
19.4e
3s
14.4s 1 +
-------------------------
u
1
s ( )
u
2
s ( )
=
cmpc
4-19
Note that u
2
has a l arge (but fi ni te) l i mi t. I t never comes i nto pl ay.
We next appl y a l ower bound of zero to both outputs:
ul i m=[ - i nf - 0. 15 i nf i nf 0. 1 100] ;
y l i m=[ 0 0 i nf i nf ] ;
[ y , u] =cmpc( pl ant , model , y wt , uwt , M, P, t e nd, r , ul i m, y l i m) ;
pl ot al l ( y , u, de l t ) , paus e
0 5 10 15 20 25 30
0.2
0
0.2
0.4
0.6
0.8
1
1.2
Outputs
Time
0 5 10 15 20 25 30
0.2
0.18
0.16
0.14
0.12
0.1
0.08
0.06
Manipulated Variables
Time
cmpc
1-20
The fol l owi ng resul ts show that no constrai nts are vi ol ated.
Restriction I ni ti al condi ti ons of zero are used for al l the vari abl es. Thi s si mul ates the
condi ti on where al l vari abl es represent a devi ati on from a steady-state i ni ti al
condi ti on.
Suggestion Probl ems wi th many i nequal i ty constrai nts can be very ti me consumi ng. You
can mi ni mi ze the number of constrai nts by:
Usi ng smal l val ues for P and/or M.
Leavi ng vari abl es unconstrai ned (l i mi ts at inf) i ntermi ttentl y unl ess you
thi nk the constrai nt i s i mportant.
See Also pl ot al l , pl ot each, mpcc l , mpccon, mpcs i m
0 5 10 15 20 25 30
0.2
0
0.2
0.4
0.6
0.8
1
1.2
Outputs
Time
0 5 10 15 20 25 30
0.2
0.1
0
Manipulated Variables
Time
cp2dp
4-21
1cp2dp
Purpose Converts a si ngl e-i nput-si ngl e-output, conti nuous-ti me transfer functi on i n
standard MATLAB pol ynomi al form (i ncl udi ng an opti onal ti me del ay) to a
sampl ed-data transfer functi on.
Syntax [ numd, dend] = cp2dp( num, den, del t )
[ numd, dend] = cp2dp( num, den, del t , del ay )
Description numand den are the numerator and denomi nator pol ynomi al s of the
conti nuous-ti me system (i n the standard Control Tool box pol ynomi al format),
del t i s the sampl i ng peri od, and del ay i s the (opti onal ) ti me del ay (i n ti me
uni ts). I f you omi t de l ay, cp2dp assumes zero del ay. The cal cul ated resul ts are
numd and dend, the numerator and denomi nator pol ynomi al s of the
correspondi ng di screte-ti me transfer functi on. cp2dp adds a zero-order hol d at
the i nput of the conti nuous-ti me system duri ng the conversi on to di screte-ti me.
cp2dp accounts properl y for the effect of a ti me del ay that i s a noni ntegral
mul ti pl e of the sampl i ng peri od. I f del ay =0, cp2dp i s equi val ent to the
MATLAB commands:
[ a, b, c, d] =t f 2s s ( num, den) ;
[ phi , gam] =c2dmp( a, b, del t ) ;
[ numd, dend] =s s 2t f 2( phi , gam, c, d, 1) ;
Example See pol y 2t f d, pol y f or mat for an exampl e of the use of thi s functi on.
Algorithm cp2dp fi rst converts numand de n to the equi val ent di screte state-space form. I t
then accounts for the fracti onal ti me del ay (i f any) usi ng the formul as i n
strm and Wi ttenmark (1984), pages 4042. Fi nal l y, i t converts the di screte
state-space model to a di screte transfer-functi on model , si mul taneousl y
accounti ng for the whol e peri ods of del ay (i f any).
Reference strm, K. J.; Wi ttenmark, B. Computer Control Systems Theoryand Design,
Prenti ce-Hal l , Engl ewood Cl i ffs, N.J., 1984.
Restriction The order of nummust be that of den.
See Also pol y 2t f d, pol y f or mat
dlqe2
1-22
1dl qe2
Purpose Sol ves the di screte Ri ccati equati on by an i terati ve method to determi ne the
opti mal steady-state gai n (and opti onal covari ance matri ces) for a di screte
Kal man fi l ter or state esti mator.
Syntax k = dl qe2( phi , gamw, c, q, r )
[ k, m, p] = dl qe 2( phi , gamw, c , q, r )
Description Filter form:
Consi der the state-space descri pti on:
where xi s a vector of n state vari abl es, u contai ns n
u
known i nputs, i s a
vector of n
y
measured outputs, yi s the noise-freeoutput, wi s a vector of n
w
unmeasured di sturbance i nputs, z i s a vector of n
y
measurement noi se i nputs,
and ,
u
,
w
,C and D are constant matri ces. We assume that wand z are
stati onary random-normal si gnal s (whi te noi se) wi th covari ances
E{w(k)w
T
(k)}= Q
E{w(k)z
T
(k)}= R
12
= 0
E{z(k)z
T
(k)}= R
The steady-state Kal man fi l ter i s
where i s the esti mate of x(k) based on the measurements avai l abl e at
peri od k, i s that based on the measurements avai l abl e at peri od
x k 1 + ( ) x k ( )
u
u k ( )
d
d k ( )
w
w k ( ) + + + =
y k ( ) y k ( ) z k ( ) + =
Cx k ( ) Du k ( ) z k ( ) + + =
y
x k k ( ) x k k 1 ( ) K y k ( ) Cx k k 1 ( ) Du k ( ) [ ] + =
x k 1 + k ( ) x k k ( )
u
u k ( ) + =
y k k ( ) Cx k k ( ) Du k ( ) + =
x k k ( )
x k k 1 ( )
dlqe2
4-23
k 1, etc. Note that i s an esti mate of the noi se-free output, . The
steady-state Kal man gai n, K, i s the sol uti on of
where M and P may be i nterpreted as the expected covari ance of the errors i n
the state esti mates before and after the measurement update, respecti vel y, i .e.,
where, by defi ni ti on,
The dl qe2 functi on takes ,
u
, C, R, and Qas i nputs and cal cul ates K, M, and
P. The l ast two output arguments are opti onal .
Note that the i nput and output arguments are i denti cal to those for dl qe i n the
Control Tool box. The advantage of dl qe2 i s that i t can handl e a si ngul ar
state-transi ti on matri x (), e.g., for systems wi th ti me del ay.
Predictor form:
y y
K MC
T
R CMC
T
+ [ ]
1
=
M P
T

w
Q
w
T
+ =
P M KCM =
M E x k k 1 ( )x k k 1 ( )
T
{ } =
P E x k k ( )x k k ( )
T
{ } =
x k k ( ) x k ( ) x k k ( ) =
x k k 1 ( ) x k ( ) x k k 1 ( ) =
dlqe2
1-24
You can al so use dl qe2 to cal cul ate a state-esti mator i n the predictor form:
The rel ati onshi p between K
p
, the esti mator gai n for the predi ctor form, and K
as cal cul ated by dl qe2 i s:
The matri x M cal cul ated by dl qe2 i s the expected covari ance of the errors i n
.
Algorithm dl qe2 cal l s dar ei t er
1
, whi ch sol ves the di screte al gebrai c Ri ccati equati on
usi ng an i terati ve doubl i ng al gori thm.
Example Consi der a system represented by the bl ock di agram:
x k 1 + k ( ) x k k 1 ( )
u
u k ( ) K
p
e k ( ) + + =
y k k 1 ( ) Cx k k 1 ( ) Du k ( ) + =
e k ( ) y k ( ) y k k 1 ( ) =
K
p
K =
x k k 1 ( )
1. We gr ateful l y acknowl edge Kjel l Gustafsson, Depar tment of Automati c Contr ol , Lund
I nsti tute of Technol ogy, Lund, Sweden, who provi ded thi s functi on.
y u
+
G
w
G
u
z
y
w

+
+
+
dlqe2
4-25
where G
u
and G
w
are fi rst-order, di screte-ti me transfer functi ons.
and the stati sti cs of the unmeasured i nputs are Q = 2, R = 1.
We use the appropri ate MPC Tool box functi ons to bui l d a model of the system,
then cal cul ate the opti mal gai n:
del t =2; ny =1;
gu=pol y 2t f d( 0. 2, [ 1 - 0. 8] , del t ) ;
Gw=pol y 2t f d( 0. 3, [ 1 - 0. 95] , del t ) ;
[ phi , gam, c, d] =mod2s s ( t f d2mod( del t , ny , gu, Gw) ) ;
k=dl qe2( phi , gam( : , 2) , c, 2, 1)
The resul t i s:
k = 0
1. 0619
Note that the gai n for the fi rst state i s zero si nce thi s corresponds to the state
of G
u
, whi ch i s unaffected by the di sturbance, w. Al so noti ce that i n the
composi te system, the second col umn of gami s
w
. Thi s i s because of the order
i n whi ch gu and G
w
were speci fi ed as i nputs to the t f d2mod functi on.
See Also s mpce s t
G
u
z ( )
0.20
1 0.8z
1

-------------------------- = G
w
z ( )
0.3
1 0.95z
1

----------------------------- =
imp2step
1-26
1i mp2step
Purpose Constructs a mul ti -i nput mul ti -output model i n MPC step format from
mul ti -i nput si ngl e-output i mpul se response matri ces.
Syntax pl ant = i mp2s t ep( del t , nout , t het a1, t he t a2, . . . ,
t het a25)
Description Gi ven the i mpul se response coeffi ci ent matri ces, t het a1, t he t a2, etc., a model
i n MPC step format i s constructed. Each t het ai i s an n-by-n
u
matri x
correspondi ng to the i mpul se response coeffi ci ents for output i. ni s the number
of the coeffi ci ents and n
u
i s the number of i nputs.
del t i s the sampl i ng i nterval used for obtai ni ng the i mpul se response
coeffi ci ents. nout i s the output stabi l i ty i ndi cator. For stabl e systems, thi s
argument i s set equal to number of outputs, n
y
. For systems wi th one or more
i ntegrati ng outputs, thi s argument i s a col umn vector of l ength n
y
wi th
nout ( i ) =0 i ndi cati ng an i ntegrati ng output and nout ( i ) =1 i ndi cati ng a stabl e
output.
Example See ml r and pl s r for exampl es of the use of thi s functi on.
Restriction The l i mi t on the number of i mpul se response matri ces t het ai i s 25.
See Also ml r , pl s r
mlr
4-27
1ml r
Purpose Determi nes i mpul se response coeffi ci ents for a mul ti -i nput si ngl e-output
system vi a Mul ti vari abl e Least Squares Regressi on or Ri dge Regressi on.
Syntax [ t het a, y r es ] = ml r ( x r eg, y r e g, ni nput )
[ t het a, y r es ] = ml r ( x r eg, y r e g, ni nput , pl ot opt , wt het a, . . .
wdel t he t a)
Description x r eg and y r eg are the i nput matri x and output vector produced by routi nes
such as wr t r eg. ni nput i s number of i nputs. Least Squares i s used to determi ne
the i mpul se response coeffi ci ent matri x, t het a. Col umns of t het a correspond
to i mpul se response coeffi ci ents from each i nput. Opti onal output y r es i s the
vector of resi dual s, the di fference between the actual outputs and the predi cted
outputs.
Opti onal i nputs i ncl ude pl ot opt , wt het a, and wde l t het a. No pl ot i s produced
i f pl ot opt i s equal to 0 whi ch i s the defaul t; a pl ot of the actual output and the
predi cted output i s produced i f pl ot opt =1; two pl ots pl ot of actual and
predi cted output, and pl ot of resi dual s are produced for pl ot opt =2. Penal ti es
on the squares of t het a and the changes i n t he t a can be speci fi ed through the
scal ar wei ghts wt het a and wdel t he t a, respecti vel y (defaul ts are 0). t het a i s
cal cul ated as fol l ows:
theta1 =(X
T
X)
1
X
T
Y
where
X
xreg
wtheta I
wdel theta del I
=
Y
yreg
0
0
=

mlr
1-28
where I i s i denti ty matri x of di mensi on n
*
n
u
di mensi on of delI i s n
*
n
u
by n
*
n
u
.
then
Example Consi der the fol l owi ng two-i nput si ngl e-output system:
Load the i nput and output data. The i nput and output data were generated
from the above transfer functi on and random zero-mean noi se was added to the
output. Sampl i ng ti me of 7 mi nutes was used.
l oad ml r dat ;
Determi ne the standard devi ati ons for i nput data usi ng the functi on aut os c .
[ ax , mx , s t dx ] = aut os c( x ) ;
Scal e the i nput data by thei r standard devi ati ons onl y.
mx = [ 0, 0] ;
s x = s cal ( x , mx , s t dx ) ;
Put the i nput and output data i n a form such that they can be used to
determi ne the i mpul se response coeffi ci ents. 35 i mpul se response coeffi ci ents
(n) are used.
del I
1 1 0 0
0 1 1 0
0 0 1 1
0 0 0 1
=

theta [ theta1 1 : n ( ) theta1 n 1 : 2n + ( ) =


theta1 nu n 1 ( ) 1 : nu n + ( ) ]
* *
y s ( )
5.72e
14s
60s 1 +
-------------------------
1.52e
15s
25s 1 +
-------------------------
u
1
s ( )
u
2
s ( )
=
mlr
4-29
n = 35;
[ x r eg, y r eg] = wr t r eg( s x , y , n) ;
Determi ne the i mpul se response coeffi ci ents vi a ml r . By speci fyi ng pl ot opt =2,
two pl ots pl ot of predi cted output and actual output, and pl ot of the output
resi dual (or predi cted error) are produced.
ni nput = 2;
pl ot opt = 2;
[ t het a, y r es ] = ml r ( x r eg, y r eg, ni nput , pl ot opt ) ;
Scal e t het a based on the standard devi ati ons used i n scal i ng the i nput.
t he t a = s cal ( t het a, mx , s t dx ) ;
Convert the i mpul se model to a step model to be used i n MPC desi gn. Recal l
that a sampl i ng ti me of 7 mi nutes was used i n determi ni ng the i mpul se model .
Number of outputs (1 i n thi s case) must be speci fi ed.
nout = 1;
del t = 7;
model = i mp2s t ep( del t , nout , t het a) ;
0 20 40 60 80 100 120 140 160 180
6
4
2
0
2
4
Actual value (o) versus Predicted Value (+)
Sample Number
O
u
t
p
u
t
0 20 40 60 80 100 120 140 160 180
0.4
0.3
0.2
0.1
0
0.1
0.2
0.3
Output Residual or Prediction Error
Sample Number
R
e
s
i
d
u
a
l
mlr
1-30
Pl ot the step response coeffi ci ents.
pl ot s t ep( model )
See Also pl s r , v al i dmod, wr t r eg
0 50 100 150 200 250
0
1
2
3
4
5
6
u1 step response : y1
TIME
0 50 100 150 200 250
0.2
0
0.2
0.4
0.6
0.8
1
1.2
1.4
1.6
1.8
u2 step response : y1
TIME
mod format
4-31
1mod for mat
Purpose The MPC mod format i s a compact way to store the model of a l i near system
for subsequent use i n the MPC Tool box functi ons.
Description
Consi der the process shown i n the above bl ock di agram. I ts discrete-timeLTI
state-space representati on i s:
where x i s a vector of n state vari abl es, u represents the n
u
mani pul ated
vari abl es, d represents n
d
measured but freel y-varyi ng i nputs (i .e., measured
di sturbances), wrepresents n
w
unmeasured di sturbances, yi s a vector of n
y
pl ant outputs, z i s measurement noi se, and ,
u
, etc., are constant matri ces of
appropri ate si ze. The vari abl e (k) represents the pl ant output before the
addi ti on of measurement noi se. Defi ne:
= [
u

w
]
D = [D
u
D
ud
D
w
]
I n some cases one woul d l i ke to i ncl ude n
ym
measured and n
yu
unmeasured
outputs i n y, where n
ym
+ n
yu
= n
y
. I f so, the mod format assumes that the y
vector and the C and D matri ces are arranged such that the measured outputs
come fi rst, fol l owed by the unmeasured outputs.

y y
Unmeasured
Disturbances
Manipulated
Variables
Measured
Disturbances
Measurement
Noise
w
u
d
+ +
z
Plant
Measured
Outputs
x k 1 + ( ) x k ( )
u
u k ( )
d
d k ( )
w
w k ( ) + + + =
y k ( ) y k ( ) z k ( ) + =
Cx k ( ) D
u
u k ( ) D
d
d k ( ) D
w
w k ( ) z k ( ) + + + + =
y
mod format
1-32
The mod format i s a si ngl e matri x that contai ns the , , C, and D matri ces,
pl us some addi ti onal i nformati on. Let M be the mod representati on of the
above system. I ts overal l di mensi ons are:
Number of rows = n + n
y
+ 1
Number of col umns = max(7, 1 + n + n
u
+ n
d
+ n
w
)
The mi nf o vector i s the fi rst seven el ements of the fi rst row i n M. The el ements
of mi nf o are:
The remai nder of M contai ns the di screte state-space matri ces:
Notes Si nce the mi nf o vector requi res seven col umns, thi s i s the mi ni mum possi bl e
number of col umns i n the mod format, regardl ess of the di mensi ons of the
state-space matri ces.
Al so, the fi rst col umn i s reserved for other uses by MPC Tool box routi nes. Thus
the state-space matri ces start i n col umn 2, as descri bed above.
I n order for the mpci nf o routi ne to recogni ze matri ces i n the MPC modformat,
the (2,1) el ement i s set to NaN(Not-a-Number).
mi nf o (1) T, the sampl i ng peri od used to create the model .
(2) n, the number of states.
(3) n
u
, the number of mani pul ated vari abl e i nputs.
(4) n
d
, the number of measured di sturbances.
(5) n
w
, the number of unmeasured di sturbances.
(6) n
ym
, the number of measured outputs.
(7) n
yu
, the number of unmeasured outputs.
i n rows 2 to n + 1 col umns 2 to n + 1
i n rows 2 to n + 1 col umns n + 2 to n + n
u
+n
d
+ n
w
+ 1
C i n rows n + 2 to n + n
y
+ 1 col umns 2 to n + 1
D i n rows n + 2 to n + n
y
+ 1 col umns n + 2 to n + n
u
+n
d
+ n
w
+ 1
mod format
4-33
Example See s s 2mod for a mod format exampl e.
See Also mod2s s , mod2s t e p, s t ep f or mat , mpc i nf o, s s 2mod, s t ep, t f d2mod, t f f or mat ,
t h2mod, t het a f or mat
mod2frsp, varying format
1-34
1mod2fr sp, var yi ng format
Purpose Cal cul ates the compl ex frequency response i n varyingformat of a system i n
MPC mod format.
Syntax f r s p = mod2f r s p( mod, f r eq)
[ f r s p, ey ef r s p] = mod2f r s p( mod, f r eq, out , i n, bal f l g)
Description mod2f r s p cal cul ates the compl ex frequency response of a system (mod) i n MPC
mod format. The desi red frequenci es are gi ven by the i nput f r e q, a rowvector
of 3 el ements speci fyi ng the l ower frequency as a power of 10, the upper
frequency as a power of 10, and the number of frequency poi nts.
Opti onal i nputs out and i n are rowvectors that speci fy the outputs and i nputs
for whi ch the frequency response i s to be generated. I f these vari abl es are
omi tted or empty, the defaul t i s to use al l outputs and i nputs.
Opti onal i nput bal f l g i ndi cates whether the systems matri x shoul d be
bal anced (usi ng the MATLAB bal ance command). I f bal f l g i s nonzero,
bal anci ng i s performed. Bal anci ng i mproves the condi ti oni ng of the probl em,
but may cause errors i n the frequency response. I f bal f l g=[ ] or i s omi tted, no
bal anci ng i s performed.
Output f r s p i s the frequency response matri x gi ven i n varyingformat. Let F()
denote a matri x-val ued functi on of the i ndependent vari abl e . Then the N
sampl ed val ues F(
1
), . . . , F(
N
) are contai ned i n f r s p as fol l ows:
I f the di mensi on of each submatri x F(
i
) i s n by m, then the di mensi ons of f r s p
i s n
.
N + 1 by m+ 1.
frsp
F
1
( )
1
F
i
( )
N
0
F
N
( )
0
00N i nf
=

mod2frsp, varying format


4-35
Opti onal output ey e f r s p i s i n varyingformat and represents I F(
i
) at each
frequency. Thi s output can onl y be speci fi ed for square submatri ces and may
be useful i n computi ng the frequency responses of both the sensi ti vi ty and
compl ementary sensi ti vi ty functi ons.
Example Consi der the l i near system:
See the mpccl exampl e for the commands that bui l d the a cl osed-l oop model for
thi s process usi ng a si mpl e control l er. However for thi s exampl e, del t =6 and
t f i nal =90 are used to reduce the number of step response coeffi ci ents.
y
1
s ( )
y
2
s ( )
12.8e
s
16.7s 1 +
------------------------
18.9e
3s
21.0s 1 +
-------------------------
6.6e
7s
10.9s 1 +
------------------------
19.4e
3s
14.4s 1 +
-------------------------
u
1
s ( )
u
2
s ( )
=
mod2frsp, varying format
1-36
Now we wi l l cal cul ate and pl ot the frequency response of the sensi ti vi ty and
compl ementary sensi ti vi ty functi ons.
f r eq = [ - 3, 0, 30] ;
i n = [ 1: ny ] ; % i nput i s r f or comp. s ens i t i v i t y
out = [ 1: ny ] ; % out put i s y p f or comp. s ens i t i v i t y
[ f r s p, ey ef r s p] = mod2f r s p( cl mod, f r e q, out , i n) ;
pl ot f r s p( ey e f r s p) ; % Se ns i t i v i t y
paus e;
pl ot f r s p( f r s p) ; % Compl ement ar y Sens i t i v i t y paus e;
10
3
10
2
10
1
10
0
10
4
10
2
10
0
10
2
Frequency (radians/time)
L
o
g

M
a
g
n
i
t
u
d
e
BODE PLOTS
10
3
10
2
10
1
10
0
500
400
300
200
100
0
100
Frequency (radians/time)
P
h
a
s
e

(
d
e
g
r
e
e
s
)
mod2frsp, varying format
4-37
10
3
10
2
10
1
10
0
10
4
10
2
10
0
10
2
Frequency (radians/time)
L
o
g

M
a
g
n
i
t
u
d
e
BODE PLOTS
10
3
10
2
10
1
10
0
700
600
500
400
300
200
100
0
Frequency (radians/time)
P
h
a
s
e

(
d
e
g
r
e
e
s
)
mod2frsp, varying format
1-38
Cal cul ate and pl ot the si ngul ar val ues for the sensi ti vi ty functi on response.
[ s i gma, omega] = s v df r s p( ey ef r s p) ;
c l g;
s emi l ogx ( ome ga, s i gma) ;
t i t l e( Si ngul ar Val ues v s . Fr equency ) ;
x l abel ( Fr equency ( r adi ans /t i me) ) ;
y l abel ( Si ngul ar Val ues ) ;
Algorithm The al gori thm to cal cul ate the compl ex frequency response i nvol ves a matri x
i nverse probl em whi ch i s sol ved vi a a Hessenberg matri x.
Reference A.J. Laub, Effi ci ent Mul ti vari abl e Frequency Response Computati ons, I EEE
Transactions on Automatic Control, Vol . AC26, No. 2, pp.407408, Apri l ,
1981.
See Also mod, mpccl , pl ot f r s p, s mpccl , s v df r s p
10
3
10
2
10
1
10
0
0
0.5
1
1.5
2
2.5
Singular Values vs. Frequency
Frequency (radians/time)
S
i
n
g
u
l
a
r

V
a
l
u
e
s
mod2mod
4-39
1mod2mod
Purpose Changes the sampl i ng peri od of a model i n MPC mod format.
Syntax newmod = mod2mod( ol dmod, del t 2)
Description I nput ol dmod i s the exi sti ng model i n MPC modformat. I nput del t 2 i s the new
sampl i ng peri od for the model . mod2mod returns ne wmod, whi ch i s the system i n
mod format converted to the new sampl i ng ti me.
See Also mod, s s 2mod
mod2ss
1-40
1mod2ss
Purpose Extracts the standard di screte-ti me state-space matri ces and other
i nformati on from a model stored i n the MPC mod format.
Syntax [ phi , gam, c, d] = mod2s s ( mod)
[ phi , gam, c, d, mi nf o] = mod2s s ( mod)
Description
Consi der the process shown i n the above bl ock di agram. mod2s s assumes that
mod i s a descri pti on of the above process i n the MPC modformat (see mod i n the
onl i ne MATLAB Function Referencefor more detai l s). An equi val ent
state-space representati on i s:
where xi s a vector of n state vari abl es, u represents the n
u
mani pul ated
vari abl es, d represents n
d
measured but freel y-varyi ng i nputs (i .e., measured
di sturbances), wrepresents n
w
unmeasured di sturbances, y i s a vector of n
y
pl ant outputs, z i s measurement noi se, and ,
u
, etc., are constant matri ces of
appropri ate si ze. The vari abl e (k) represents the pl ant output before the
addi ti on of measurement noi se. Defi ne:
= [
u

w
]
D = [D
u
D
d
D
w
]

y y
Unmeasured
Disturbances
Manipulated
Variables
Measured
Disturbances
Measurement
Noise
w
u
d
+ +
z
Plant
Measured
Outputs
x k 1 + ( ) x k ( )
u
u k ( )
d
d k ( )
w
w k ( ) + + + =
y k ( ) y k ( ) z k ( ) + =
Cx k ( ) D
u
u k ( ) D
d
d k ( ) D
w
w k ( ) z k ( ) + + + + =
y
mod2ss
4-41
mod2s s extracts the , , C, and Dmatri ces from the i nput vari abl e, mod. I t al so
extracts the vector mi nf o, whi ch contai ns addi ti onal i nformati on about the
sampl i ng peri od, number of each type of i nput and output, etc. see mod i n the
onl i ne MATLAB Function Referencefor more detai l s on mi nf o.
Examples 1 See the exampl e i n the descri pti on of dl qe2.
2 Suppose you have a pl ant wi th the structure
where the i nputs and outputs are al l scal ars, and you have constructed mod1
and mod2 usi ng the commands:
phi 1=di ag( [ - 0. 7, 0. 8] ) ; gam1=[ 1, - 1, 0; 0, 0, 1] ;
c1=[ 0. 2 - 0. 4] ; d1=z er os ( 1, 3) ;
mi nf o1=[ 1 2 1 1 1 1 0] ;
mod1=s s 2mod( phi 1, gam1, c1, d1, mi nf o1) ;
phi 2=- 0. 2; gam2=[ 1, - 0. 5, 0. 2] ;
c2=3; d2=[ 0. 2, 0, 0] ;
mi nf o2=[ 1 1 1 1 1 1 0] ;
mod2=s s 2mod( phi 2, gam2, c2, d2, mi nf o2) ;
pmod=addmod( mod1, mod2) ;
Now you want to cal cul ate the response to a step change i n d
2
, whi ch i s the
fourth i nput to the composi te system, pmod. One way to do i t i s:
[ phi , gam, c, d, mi nf o] =mod2s s ( pmod) ;
ns t ep=10;
us t ep=[ z er os ( ns t ep, 3) one s ( ns t ep, 1) z er os ( ns t ep, 2) ] ;
% Def i ne s t ep i n d2
y =dl s i mm( phi , gam, c, d, us t e p) ;
% s i mul at e r es pons e t o s t ep i nput
pl ot ( [ 0: ns t ep- 1] , y )
mod2

y(k)
+
+
mod1
u
1
u
2
d
1
d
2
w
1
w
2
mod2ss
1-42
The resul ts of the mod2s s cal l are:
phi =
- 0. 7000 0 3. 0000
0 0. 8000 0
0 0 - 2. 0000
gam=
1. 0000 2. 2000 - 1. 0000 0 0 0
0
0 0 0 0 1. 0000 0
0 1. 0000 0 - . 5000 0 0. 2000
c =
0. 2000 - 0. 4000 0
d=
0 0 0 0 0 0
mi nf o=
1 3 2 2 2 1 0
And the step response i s:
See Also mod, s s 2mod
0 1 2 3 4 5 6 7 8 9
0.35
0.3
0.25
0.2
0.15
0.1
0.05
0
mod2step, step format
4-43
1mod2step, step for mat
Purpose Uses a model i n the mod format to cal cul ate the step response of a SI SO or
MI MO system i n MPC step format.
Syntax pl ant = mod2s t ep( mod, t f i nal )
[ pl ant ,dpl ant ] = mod2s t ep( mod, t f i nal , del t 2, nout )
Description The i nput vari abl e mod i s assumed to be a model i n the mod format (see mod i n
the onl i ne MATLAB Function Referencefor a descri pti on). You woul d normal l y
create i t usi ng s s 2mod, t f d2mod, or t h2mod. The i nput vari abl e t f i nal i s the
ti me at whi ch you woul d l i ke to end the step response.
The opti onal i nput vari abl e del t 2 i s the desi red sampl i ng peri od for the step
response. I f you use del t 2=[ ] or omi t i t, the defaul t i s equal to the sampl i ng
peri od of mod (contai ned i n the mi nf o vector of mod).
The opti onal i nput vari abl e nout i s the output stabi l i ty i ndi cator. For stabl e
systems, set nout equal to the number of outputs, n
y
. For systems wi th one or
more i ntegrati ng outputs, nout i s a col umn vector of l ength n
y
wi th nout ( i ) =0
i ndi cati ng an i ntegrati ng output and nout ( i ) =1 i ndi cati ng a stabl e output. I f
you use nout =[ ] or omi t i t, the defaul t i s nout =n
y
(onl y stabl e outputs).
pl ant and dpl ant are matri ces i n MPC step format contai ni ng the cal cul ated
step responses. pl ant i s the response to the mani pul ated vari abl es, and dpl ant
i s the response to the di sturbances (i f any), both measured and unmeasured.
The overal l di mensi ons of these matri ces are:
pl ant n-by-n
y
+ n
y
+ 2 rows, n
u
col umns.
dpl ant n-by-n
y
+ n
y
+ 2 rows, n
d
+ n
w
col umns.
where n = r ound ( t f i nal /del t 2)
I t i s assumed that stabl e step responses are nearl y constant after n sampl i ng
peri ods, whi l e i ntegrati ng responses i ncrease wi th a constant sl ope after n 1
sampl i ng peri ods.
Each col umn gi ves the step response wi th respect to the correspondi ng i nput
vari abl e. Wi thi n each col umn, the fi rst n
y
el ements are the response for each
output at ti me t =T, the next n
y
el ements gi ve each output at ti me t =2T, etc.
mod2step, step format
1-44
The l ast n
y
+ 2 rows contai n nout , n
y
and del t 2, respecti vel y (al l i n col umn 1
any remai ni ng el ements i n these rows are set to zero). I n other words, for
pl ant the arrangement i s as fol l ows:
where
S
kji
i s the i
th
step response coeffi ci ent descri bi ng the effect of i nput j on output
k.
The arrangement of dpl ant i s si mi l ar; the onl y di fference i s i n the number of
col umns.
plant
S
1
S
2
S
n
nout(1) 0 0
nout(2) 0 0
nout n
y
( ) 0 0
n
y
0 0
delt2 0 0
n n
y
n
y
2 + + ( ) n
u

S
i
S
1 1 i , ,
S
1 2 i , ,
S
1 n
u
i , ,
S
2 1 i , ,
S
2 2 i , ,
S
2 n
u
i , ,
S
n
y
1 i , ,
S
n
y
2 i , ,
S
n
y
n
u
i , ,
=

mod2step, step format


4-45
Example The fol l owi ng process has 3 i nputs and 4 outputs:
phi =di ag( [ 0. 3, 0. 7, - 0. 7] ) ;
gam=ey e( 3) ;
c=[ 1 0 0; 0 0 1; 0 1 1; 0 1 0] ;
d=[ 1 0 0; z er os ( 3, 3) ] ;
We fi rst cal cul ate i ts step response for 4 sampl es (i ncl udi ng the i ni ti al
condi ti on)wi th respect to each of the i nputs usi ng the Control Tool box functi on,
ds t ep:
ns t ep=4; del t =1. 5;
y u1=ds t ep( phi , gam, c, d, 1, ns t ep)
y u2=ds t ep( phi , gam, c, d, 2, ns t ep)
y u3=ds t ep( phi , gam, c, d, 3, ns t ep)
The resul ts are:
We then use mod2s t ep to do the same job:
pl ant =mod2s t ep( s s 2mod( phi , gam, c, d, del t ) , ( ns t ep- 1) *del t )
Response to u
1
Response to u
2
Response to u
3
Ti me y
1
y
2
y
3
y
4
y
1
y
2
y
3
y
4
y
1
y
2
y
3
y
4
0 1 0 0 0 0 0 0 0 0 0 0 0
T 2 0 0 0 0 0 1 1 0 1 1 0
2T 2.3 0 0 0 0 0 1.7 1.7 0 0.3 0.3 0
3T 2.39 0 0 0 0 0 2.19 2.19 0 0.79 0.79 0
mod2step, step format
1-46
obtai ni ng the resul ts:
pl ant =
2. 0000 0 0
0 0 1. 0000
0 1. 0000 1. 0000
0 1. 0000 0
2. 3000 0 0
0 0 0. 3000
0 1. 7000 0. 3000
0 1. 7000 0
2. 3900 0 0
0 0 0. 7900
0 2. 1900 0. 7900
0 2. 1900 0
1. 0000 0 0
1. 0000 0 0
1. 0000 0 0
1. 0000 0 0
4. 0000 0 0
1. 5000 0 0
See Also pl ot s t ep, s s 2s t ep, t f d2s t ep
mpcaugss
4-47
1mpcaugss
Purpose Di fferences the states of a system and augments them wi th the output
vari abl es. Mai nl y used as a uti l i ty functi on for setti ng up model predi cti ve
control l ers.
Syntax [ phi a, gama, ca] = mpcaugs s ( phi , gam, c)
[ phi a, gama, ca, da, na] = mpcaugs s ( phi , gam, c, d)
Description
Consi der the process shown i n the above bl ock di agram. A state-space
representati on i s:
where x i s a vector of n state vari abl es, u i s a vector of n
u
mani pul ated
vari abl es, d i s a vector of n
d
measured di sturbances, w i s a vector of n
w
unmeasured di sturbances, y i s a vector of n
y
pl ant outputs, z i s measurement
noi se, and ,
u
,
d
,
w
, etc., are constant matri ces of appropri ate si ze. The
vari abl e = Cx(k) represents the pl ant output before the addi ti on of the
di rect contri buti on of the i nputs [D
u
u(k) + D
d
v(k) + D
w
w(k)] and the
measurement noi se [z(k)]. (The vari abl e i s the output before addi ti on of the
measurement noi se). Defi ne:
u(k) = u(k) u(k 1)
x(k) = x(k) x(k 1)

y y
Unmeasured
Disturbances
Manipulated
Variables
Measured
Disturbances
Measurement
Noise
w
u
d
+ +
z
Plant
Measured
Outputs
z k 1 + ( ) x k ( )
u
u k ( )
d
d k ( )
w
w k ( ) + + + =
y k ( ) y k ( ) D
u
u k ( ) D
d
d k ( ) D
w
w k ( ) z k ( ) + + + + =
y k ( ) z k ( ) + =
y k ( )
y
mpcaugss
1-48
etc. Then equati ons 4.28 and 4.29 can be converted to the form
x
a
(k+1) =
a
x
a
(k) +
ua
u(k) +
da
(k) +
wa
w(k)
y(k) = C
a
x
a
(k) + D
u
u(k) + D
d
d(k) + D
w
w(k) + z(k)
where, by defi ni ti on,
The mpcaugs s functi on takes the matri ces , (= [
u

d

w
]), C as i nput, and
creates the augmented matri ces
a
,
a
, C
a
and D
a
i n the form shown above.
The D i nput matri x i s opti onal . I f you i ncl ude i t, mpcaugs s assumes i t has the
form D = [D
u
D
d
D
w
]. I f you omi t i t, the defaul t i s zero. Note that al l MPC
desi gn routi nes requi re D
u
= D
d
= 0.
The l ast output vari abl e, na, i s the order of the augmented system, i .e.,
n
a
= n + n
y
. I t i s opti onal .
Example The fol l owi ng system has 2 states, 3 i nputs, and 2 outputs.
phi =di ag( [ 0. 8, - 0. 2] ) ;
gam=[ 1 - 1 0; 0 2 - 0. 5] ;
c =[ 0. 4 0; 0 1. 5] ;
x
a
k ( )
x k ( )
y

k ( )
=

a
0
C I

a

ua

da

wa
= =

ua

u
C
u

da

d
C
d

wa

w
C
w
= = =
C
a
0 I
D
a
D
u
D
d
D
w
= =
mpcaugss
4-49
Here i s the augmentati on command, fol l owed by the cal cul ated resul ts:
[ phi a, gama, ca, da, na] =mpcaugs s ( phi , gam, c)
phi a =
0. 8000 0 0 0
0 - 0. 2000 0 0
0. 3200 0 1. 0000 0
0 - 0. 3000 0 1. 0000
gama =
1. 0000 - 1. 0000 0
0 2. 0000 - 0. 5000
0. 4000 - 0. 4000 0
0 3. 0000 - 0. 7500
ca =
0 0 1 0
0 0 0 1
da =
0 0 0
0 0 0
na =
4
mpccl
1-50
1mpccl
Purpose Combi nes a pl ant model and a control l er model i n MPC stepformat, yi el di ng a
cl osed-l oop system model i n the MPC modformat. Thi s can be used for stabi l i ty
anal ysi s and l i near si mul ati ons of cl osed-l oop performance.
Syntax [ cl mod] = mpcc l ( pl ant , mode l , Kmpc)
[ cl mod, cmod] = mpccl ( pl ant , model , Kmpc , t f i l t er , . . .
dpl ant , dmodel )
Description
pl ant
I s a model (i n step format) representi ng the pl ant i n the above di agram.
model
I s a model (i n stepformat) that i s to be used to desi gn the MPC control l er bl ock
shown i n the di agram. I t may be the same as pl ant (i n whi ch case there i s no
model error i n the control l er desi gn), or i t may be di fferent.
Kmpc
I s a control l er gai n matri x, whi ch was cal cul ated by the functi on mpc con.
Disturbance
Model
Controller
Disturbances

u
d
+
+
r
Plant
Plant
Disturbance
Setpoints
Noise-free
d
y
Plant
Outputs

Measured
Outputs

w
u
y
p
Measurement
Noise
+
+
+
+
z
mpccl
4-51
tf i l ter
I s a (opti onal ) matri x of ti me constants for the noi se fi l ter and the unmeasured
di sturbances enteri ng at the pl ant output. I f omi tted or set to an empty matri x,
the defaul t i s no noi se fi l teri ng and stepl i ke unmeasured di sturbances. See the
documentati on for the functi on mpcs i mfor more detai l s on the desi gn and
proper format of t f i l t er .
dpl ant
I s a (opti onal ) model (i n step format) representi ng al l the di sturbances
(measured and unmeasured) that affect pl ant i n the above di agram. I f omi tted
or set to an empty matri x, the defaul t i s that there are no di sturbances.
dmodel
I s a (opti onal ) model (i n step format) representi ng the measured di sturbances.
I f omi tted or set to an empty matri x, the defaul t i s that there are no measured
di sturbances. See the documentati on for the functi on mpcs i mfor more detai l s
on how di sturbances are handl ed when usi ng step-response model s.
mpccl
Cal cul ates a model of the cl osed-l oop system, cl mod. I t i s i n the modformat and
can be used, for exampl e, wi th anal ysi s functi ons such as s mpcgai n and
s mpcpol e, and wi th si mul ati on routi nes such as mod2s t ep and dl s i mm. mpcc l
al so cal cul ates (as an opti on) a model of the control l er el ement, cmod.
The cl osed-l oop model , cl mod, has the fol l owi ng state-space representati on:
x
cl
(k + 1) =
cl
x
cl
(k) +
cl
u
cl
(k)
y
cl
(k) = C
cl
x
cl
(k) + D
cl
u
cl
(k)
where x
cl
i s a vector of n state vari abl es, u
cl
i s a vector of i nput vari abl es, y
cl
i s
a vector of outputs, and
cl
,
cl
, C
cl
, and D
cl
are matri ces of appropri ate si ze.
The expert user may want to know the si gni fi cance of the state vari abl es i n x
cl
.
They are (i n the fol l owi ng order):
The n
p
states of the pl ant (as speci fi ed i n pl ant ),
The n
i
state esti mates (based on the model speci fi ed i n model ),
n
d
i ntegr ators that oper ate on the d si gnal to yi el d a d si gnal . I f there are
no di sturbances, these states are omi tted.
mpccl
1-52
n
u
i ntegrators that operate on the w
u
si gnal to yi el d a w
u
si gnal .
n
u
i ntegrators that operate on the u si gnal produced by the standard MPC
formul ati on to yi el d a u si gnal that can be used as i nput to the pl ant and as
a cl osed-l oop output.
The cl osed-l oop i nput and output vari abl es are:
where i s the esti mate of the noi se-free pl ant output at sampl i ng peri od
k based on i nformati on avai l abl e at peri od k. Thi s esti mate i s generated by the
control l er el ement.
The state-space form of the control l er model , cmod, can be wri tten as:
x
c
(k + 1) =
c
x
c
(k) +
c
u
c
(k)
y
c
(k) = C
c
x
c
(k) + D
c
u
c
(k)
where
and the control l er states are the same as those of the cl osed l oop system except
that the n
p
pl ant states are not i ncl uded.
Example Consi der the l i near system:
u
cl
k ( )
r k ( )
z k ( )
w
u
k ( )
d k ( )
and y
cl
k ( )
y
p
k ( )
u k ( )
y k k ( )
= =
y k k ( )
u
c
k ( )
r k ( )
y k ( )
d k 1 ( )
and y
c
k ( ) u k 1 ( ) = =
y
1
s ( )
y
2
s ( )
12.8e
s
16.7s 1 +
------------------------
18.9e
3s
21.0s 1 +
-------------------------
6.6e
7s
10.9s 1 +
------------------------
19.4e
3s
14.4s 1 +
-------------------------
u
1
s ( )
u
2
s ( )
=
mpccl
4-53
We bui l d the step response model usi ng the MPC Tool box functi ons pol y 2t f d
and t f d2s t ep.
g11=pol y 2t f d( 12. 8, [ 16. 7 1] , 0, 1) ;
g21=pol y 2t f d( 6. 6, [ 10. 9 1] , 0, 7) ;
g12=pol y 2t f d( - 18. 9, [ 21. 0 1] , 0, 3) ;
g22=pol y 2t f d( - 19. 4, [ 14. 4 1] , 0, 3) ;
del t =3; ny =2; t f i nal = 60;
model =t f d2s t ep( t f i nal , del t , ny , g11, g21, g12, g22) ;
pl ant =model ; % No pl ant /model mi s mat c h
Now we desi gn the control l er. Si nce there i s del ay, we use M < P: We speci fy
the defaul ts for the other tuni ng parameters, uwt and y wt , then cal cul ate the
control l er gai n:
P=6; % Pr edi ct i on hor i z on.
M=2; % Number of mov es ( i nput hor i z on) .
y wt =[ ] ; % Out put wei ght s ( def aul t - uni t y
% on al l out put s ) . uwt =[ ] ; % Man. Var wei ght s ( def aul t - z er o
% on al l man. v ar s ) .
Kmpc=mpccon( model , y wt , uwt , M, P) ;
Now we can cal cul ate the model of the cl osed-l oop system:
cl mod=mpccl ( pl ant , model , Kmpc) ;
You can use the cl osed-l oop model to cal cul ate and pl ot the step response wi th
respect to al l the i nputs. The appropri ate commands are:
t end=30;
cl s t ep=mod2s t e p( cl mod, t e nd) ;
pl ot s t ep( cl s t e p)
mpccl
1-54
Si nce the cl osed-l oop system has m=6 i nputs and p=6 outputs, onl y one of the
pl ots i s reproduced here. I t shows the response of the fi rst 4 cl osed-l oop outputs
to a uni t step i n the fi rst cl osed-l oop i nput, whi ch i s the setpoi nt for y
1
:
Cl osed-l oop outputs y
1
and y
2
are the true pl ant outputs (noi se-free). Output y
1
goes to the new setpoi nt qui ckl y wi th a smal l overshoot. Thi s causes a smal l ,
short-term di sturbance i n y
2
. The pl ots for y
3
and y
4
show the requi red
vari ati on i n the mani pul ated vari abl es.
Restriction model and pl ant must have been created usi ng the same sampl i ng peri od.
See Also cmpc, mod2s t e p, s t ep f or mat , mpcc on, mpcs i m, s mpcgai n, s mpcpol e
0 10 20 30
0
0.2
0.4
0.6
0.8
1
1.2
1.4
u1 step response : y1
TIME
0 10 20 30
-0.2
-0.15
-0.1
-0.05
0
u1 step response : y2
TIME
0 10 20 30
0
0.05
0.1
0.15
0.2
0.25
u1 step response : y3
TIME
0 10 20 30
0
0.02
0.04
0.06
0.08
0.1
0.12
u1 step response : y4
TIME
mpccon
4-55
1mpccon
Purpose Cal cul ates MPC control l er gai n usi ng a model i n MPC step format.
Syntax Kmpc = mpccon( model )
Kmpc = mpccon( model , y wt , uwt , M, P)
Description Combi nes the fol l owi ng vari abl es (most of whi ch are opti onal and have defaul t
val ues) to cal cul ate the MPC gai n matri x, Kmpc.
model
i s the model of the process to be used i n the control l er desi gn (i n the step
format).
The fol l owi ng i nput vari abl es are opti onal :
ywt
I s a matri x of wei ghts that wi l l be appl i ed to the setpoi nt tracki ng errors. I f you
use y wt =[ ] or omi t i t, the defaul t i s equal (uni ty) wei ghti ng of al l outputs over
the enti re predi cti on hori zon. I f you use y wt [ ] , i t must have n
y
col umns,
where n
y
i s the number of outputs. Al l wei ghts must be 0.
You may vary the wei ghts at each step i n the predi cti on hori zon by i ncl udi ng
up to Prows i n y wt . Then the fi rst row of n
y
val ues appl i es to the tracki ng errors
i n the fi rst step i n the predi cti on hori zon, the next row appl i es to the next step,
etc.
I f you suppl y onl y nrowrows, where 1 nrow< P, mpcc on wi l l use the l ast row
to fi l l i n any remai ni ng steps. Thus i f you wi sh the wei ghti ng to be the same for
al l P steps, you need onl y speci fy a si ngl e row.
uwt
Same format as y wt , except that uwt appl i es to the changes i n the mani pul ated
vari abl es. I f you use uwt = [ ] or omi t i t, the defaul t i s zero wei ghti ng. I f uwt
[ ], i t must have n
u
col umns, where n
u
i s the number of mani pul ated
vari abl es.
M
There are two ways to speci fy thi s vari abl e:
mpccon
1-56
I f i t i s a scalar, mpccon i nterprets i t as the i nput hori zon (number of moves)
as i n DMC.
I f i t i s a rowvector contai ni ng n
b
el ements, each el ement of the vector
i ndi cates the number of steps over whi ch u =0 duri ng the opti mi zati on and
cmpc i nterprets i t as a set of n
b
bl ocki ng factors. There may be 1 n
b
P
bl ocki ng factors, and thei r sum must be P.
I f you set M=[ ] or omi t i t and P I nf , the defaul t i s M=P, whi ch i s equi val ent
to M=ones ( 1, P) . The defaul t val ue for Mi s 1 i f P=I nf .
P
The number of sampl i ng peri ods i n the predi cti on hori zon. I f you set P=I nf or
omi t i t, the defaul t i s P=1. I f P=i nf , the predi cti on hori zon i s i nfi ni te.
I f you take the defaul t val ues for al l the opti onal vari abl es, you get the perfect
control l er, i .e., a model -i nverse control l er. Thi s control l er i s not appl i cabl e
when one or more outputs can not respond to the mani pul ated vari abl es wi thi n
one sampl i ng peri od due to ti me del ay. I n thi s case, the pl ant-i nverse control l er
i s unreal i zabl e. For nonmi ni mum phase di screte pl ants, thi s control l er i s
unstabl e. To counteract thi s you can penal i ze changes i n the mani pul ated
vari abl es (vari abl e uwt ), use bl ocki ng (vari abl e M), and/or make P>>M. The
model -i nverse control l er i s al so rel ati vel y sensi ti ve to model error and i s best
used as a poi nt of reference from whi ch you can progress to a more robust
desi gn.
Algorithm The control l er gai n i s a component of the sol uti on to the opti mi zati on probl em:
wi th respect to (a seri es of current and future moves i n the mani pul ated
vari abl es), where (k + j) i s a predi cti on of output i at a ti me j sampl i ng
peri ods i nto the future (rel ati ve to the current ti me, k), whi ch i s a functi on of
Mi ni mi ze J k ( ) ywt
i
j ( ) r
i
k j + ( ) y
i
k j + ( ) [ ] ( )
2
i 1 =
n
y

j 1 =
p

=
uwt
i
j ( )u
i
j ( ) ( )
2
i 1 =
n
u

j 1 =
n
b

+
u
i
j ( )
y
i
mpccon
4-57
, r
i
(k + j) i s the correspondi ng future setpoi nt, and n
b
i s the number of
bl ocks or moves of the mani pul ated vari abl es.
Example Consi der the l i near system:
See the mpccl exampl e for the commands that bui l d the model and a si mpl e
control l er for thi s process.
Here i s a sl i ghtl y more compl ex desi gn wi th bl ocki ng and ti me-varyi ng wei ghts
on the mani pul ated and output vari abl es:
P=6; M=[ 2 4] ;
uwt =[ 1 0; 0 1] ;
y wt =[ 1 0. 1; 0. 8 0. 1; 0. 1 0. 1] ;
Kmpc=mpccon( model , y wt , uwt , M, P) ;
t end=30; r =[ 1 0] ;
[ y , u] =mpcs i m( pl ant , model , Kmpc, t end, r ) ;
There i s no parti cul ar rati onal e for usi ng ti me varyi ng wei ghts i n thi s case i t i s
onl y for i l l ustrati on. The mani pul ated vari abl es wi l l make 2 moves duri ng the
predi cti on hori zon (see val ue of M, above). The uwt sel ecti on gi ves u
1
a uni ty
wei ght and u
2
a zero wei ght for the fi rst move, then swi tches the wei ghts for
the second move. I f there had been any addi ti onal moves they woul d have had
the same wei ghti ng as the second move.
u
i
j ( )
y
1
s ( )
y
2
s ( )
12.8e
s
16.7s 1 +
------------------------
18.9e
3s
21.0s 1 +
-------------------------
6.6e
7s
10.9s 1 +
------------------------
19.4e
3s
14.4s 1 +
-------------------------
u
1
s ( )
u
2
s ( )
=
mpccon
1-58
The y wt val ue assi gns a constant wei ght of 0.1 to y
2
, and a wei ght that
decreases over the fi rst 3 peri ods to y
1
. The wei ghts for peri ods 4 to 6 are the
same as for peri od 3. The resul ti ng cl osed-l oop (servo) response i s:
See Also cmpc, mpccl , mpcs i m
0 5 10 15 20 25 30
1
0.5
0
0.5
1
Outputs
Time
0 5 10 15 20 25 30
0
0.1
0.2
0.3
0.4
0.5
Manipulated Variables
Time
mpcinfo
4-59
1mpci nfo
Purpose Determi nes the type of a matri x and returns i nformati on about the matri x.
Syntax: mpci nf o( mat )
Description mpci nf o returns i nformati on about the type and si ze of the matri x, mat . The
i nformati on i s determi ned from the matri x structure. The matri x types i ncl ude
MPC step format, MPC mod format, varyingformat and constant. mpci nf o
returns text output to the screen.
I f the matri x i s i n MPC stepformat, the output i ncl udes the sampl i ng ti me used
to create the model , number of i nputs, number of outputs and number of step
response coeffi ci ents; i t al so i ndi cates whi ch outputs are stabl e and whi ch
outputs are i ntegrati ng.
I f the matri x i s i n MPC mod format, the output i ncl udes the sampl i ng ti me
used to create the model , number of states, number of mani pul ated vari abl e
i nputs, number of measured di sturbances, number of unmeasured
di sturbances, number of measured outputs and number of unmeasured
outputs.
For a matri x i n varyingformat, as formed i n mod2f r s p, the number of
i ndependent vari abl e val ues, and the number of rows and number of col umns
of each submatri x are output.
For a constant matri x, the text output consi sts of the number of rows and
number of col umns.
Examples 1 MPC step format: After runni ng the mod2s t ep exampl e mpci nf o( pl ant )
returns:
Thi s i s a mat r i x i n MPC St ep f or mat .
s ampl i ng t i me = 1. 5
number of i nput s = 3
number of out put s = 4
number of s t ep r es pons e c oef f i ci ent s = 3
Al l out put s ar e s t abl e.
mpcinfo
1-60
2 MPC mod format: After runni ng the s s 2mod exampl e mpci nf o(pmod)
returns:
Thi s i s a mat r i x i n MPC Mod f or mat .
mi nf o = [ 2 3 1 1 1 1 0 ]
s ampl i ng t i me = 2
number of s t at es = 3
number of mani pul at ed v ar i abl e i nput s = 1
number of me as ur ed di s t ur bances = 1
number of unmeas ur ed di s t ur bances = 1
number of me as ur ed out put s = 1
number of unmeas ur ed out put s = 0
3 varyingformat: After runni ng the mod2f r s p exampl e mpci nf o(ey ef r s p)
returns:
v ar y i ng: 30 pt s 2 r ows 2 col s
See Also mod, s t ep, mod2f r s p, v ar y i ng f or mat
mpcsim
4-61
1mpcsi m
Purpose Si mul ates cl osed-l oop systems wi th saturati on constraintson the mani pul ated
vari abl es usi ng model s i n the MPC stepformat. Can al so be used for open-l oop
si mul ati ons.
Syntax y p = mpcs i m( pl ant , model , Kmpc , t end, r )
[ y p, u, y m] = mpcs i m( pl ant , model , Kmpc, t end, r , us at , . . .
t f i l t er , dpl ant , dmodel , ds t ep)
Description
mpcs i mprovi des a conveni ent way to si mul ate the performance of the type of
system shown i n the above di agram. Measurement noi se can be si mul ated by
treati ng i t as an unmeasured di sturbance. The requi red i nput vari abl es are as
fol l ows:
pl ant
I s a model i n the MPC step format that i s to represent the pl ant.
model
I s a model i n the MPC stepformat that i s to be used for state esti mati on i n the
control l er. I n general , i t can be di fferent from pl ant i f you want to si mul ate the
effect of pl ant/control l er model mi smatch. Note, however, that model shoul d be
the same as that used to cal cul ate Kmpc.
Kmpc
I s the MPC control l er gai n matri x, usual l y cal cul ated usi ng the functi on
mpccon.
y
Disturbance
Model
Controller
Disturbances

u
d
+
+
r
Plant
Plant
Disturbance
Setpoints
Plant
Outputs
d
y
mpcsim
1-62
I f you set Kmpc to an empty matri x, mpcs i mwi l l do an open-l oop si mul ati on.
Then the i nputs to the pl ant wi l l be r (whi ch must be set to the vector of
mani pul ated vari abl es i n thi s case) and ds t ep.
tend
I s the desi red durati on of the si mul ati on (i n ti me uni ts).
r
I s normal l y a setpoi nt matri x consi sti ng of N rows and n
y
col umns, where n
y
i s
the number of output vari abl es, y:
where r
i
(k) i s the setpoi nt for output j at ti me t =kT, and T i s the sampl i ng
peri od (as speci fi ed i n the step format of pl ant and model ). I f t end > NT, the
setpoi nts vary for the fi rst N peri ods i n the si mul ati on, as speci fi ed by r , and
are then hel d constant at the val ues gi ven i n the l ast row of r for the remai nder
of the si mul ati on.
I n many si mul ati ons one wants the setpoi nts to be constant for the enti re ti me,
i n whi ch case r need onl y contai n a si ngl e row of n
y
val ues.
I f you set r =[ ] , the defaul t i s a row of n
y
zeros.
For open-l oop si mul ati ons, r speci fi es the mani pul ated vari abl es and must
contai n n
u
col umns.
The fol l owi ng i nput vari abl es are opti onal . I n general , setti ng one of them
equal to an empty matri x causes mpcs i mto use the defaul t val ue, whi ch i s gi ven
i n the descri pti on.
r
r
1
1 ( ) r
2
1 ( ) r
n
y
1 ( )
r
1
2 ( ) r
2
2 ( ) r
n
y
2 ( )

r
1
N ( ) r
2
N ( ) r
n
y
N ( )
=

mpcsim
4-63
usat
I s a matri x gi vi ng the l i mi ts on the mani pul ated vari abl es. I ts format i s as
fol l ows:
Note that i t contai ns three matri ces of N rows. N may be di fferent than that for
the setpoi nt matri x, r , but the i dea i s the same: the saturati on l i mi ts wi l l vary
for the fi rst N sampl i ng peri ods of the si mul ati on, then be hel d constant at the
val ues gi ven i n the l ast row of us at for the remai ni ng peri ods (i f any).
The fi rst matri x speci fi es the lower bounds on the n
u
mani pul ated vari abl es.
For exampl e, u
min
,
j
(k) i s the l ower bound for mani pul ated vari abl e j at ti me t =
kT i n the si mul ati on. I f u
min
,
j
(k) = inf, mani pul ated vari abl e j wi l l have no
l ower bound at t =kT.
The second matri x gi ves the upper bounds on the mani pul ated vari abl es. I f
u
max,j
(k) =inf, mani pul ated vari abl e j wi l l have no upper bound at t =kT.
The l ower and upper bounds may be ei ther posi ti ve or negati ve (or zer o) as l ong
as u
min
,
j
(k) u
max,j
(k).
, ,
, ,
, ,
,
( )
,
( )
usat
u
mi n 1 ,
1 ( ) u
mi n n
u
,
1 ( )
u
mi n 1 ,
2 ( ) u
mi n n
u
,
2 ( )

u
mi n 1 ,
N ( ) u
mi n n
u
,
N ( )
=
, ,
, ,
, ,
,
( )
,
( )
u
max 1 ,
1 ( ) u
max n
u
,
1 ( )
u
max 1 ,
2 ( ) u
max n
u
,
2 ( )

u
max 1 ,
N ( ) u
max n
u
,
N ( )

u
max 1 ,
1 ( ) u
max n
u
,
1 ( )
u
max 1 ,
2 ( ) u
max n
u
,
2 ( )

u
max 1 ,
N ( ) u
max n
u
,
N ( )


mpcsim
1-64
The thi rd matri x gi ves the l i mi ts on the rate of change of the mani pul ated
vari abl es. I n other words, mpcs i mwi l l force
| u
j
(k) u
j
(k 1)| u
max,j
(k). The l i mi ts on the rate of change must be
nonnegati ve.
The defaul t i s no saturati on constrai nts, i .e., al l the u
min
val ues wi l l be set to
inf, and al l the u
max
and u
max
val ues wi l l be set to inf.
Note: Saturati on constrai nts i n mpcs i mare enforced by si mpl y clippingthe
mani pul ated vari abl e moves so that they sati sfy al l constrai nts. Thi s i s a
nonopti mal sol uti on that, i n general , wi l l di ffer from the resul ts you woul d get
usi ng the ul i mvari abl e i n cmpc.
tf i l ter
I s a matri x of ti me constants for the noi se fi l ter and the unmeasured
di sturbances enteri ng at the pl ant output. The fi rst row of n
y
el ements gi ves
the noi se fi l ter ti me constants and the second row of n
y
el ements gi ves the ti me
constants of the l ags through whi ch the unmeasured di sturbance steps pass. I f
t f i l t er onl y contai ns one row, the unmeasured di sturbances are assumed to
be steps. I f you set t f i l t er =[ ] or omi t i t, the defaul t i s no noi se fi l teri ng and
stepl i ke unmeasured di sturbances.
dpl ant
I s a model i n MPC stepformat representi ng al l the di sturbances (measured and
unmeasured) that affect pl ant i n the above di agram. I f dpl ant i s provi ded,
then i nput ds t ep i s al so requi red. For output step di sturbances, set
dpl ant =[ ] . The defaul t i s no di sturbances.
dmodel
I s a model i n MPC step format representi ng the measured di sturbances. I f
dmodel i s provi ded, then i nput ds t ep i s al so requi red. I f there are no measured
di sturbances, set dmodel =[ ] . For output step di sturbances, set dmodel =[ ] . I f
there are both measured and un- measured di sturbances, set the col umns of
dmodel correspondi ng to the unmeasured di sturbances to zero. The defaul t i s no
measured di sturbances.
mpcsim
4-65
dstep
I s a matri x of di sturbances to the pl ant. For output step di sturbances
(dpl ant =[ ] and dmodel =[ ] ), the format i s the same as for r . For di sturbances
through step-response model s (dpl ant onl y or both dpl ant and dmodel
nonempty), the format i s the same as for r , except that the number of col umns
i s n
d
rather than n
y
. The defaul t i s a row of zeros.
Note: You may use a di fferent number of rows i n the matri ces r, us at and
ds t ep, shoul d that be appropri ate for your si mul ati on.
The cal cul ated outputs are as fol l ows (al l but y p are opti onal ):
yp
I s a matri x contai ni ng M rows and n
y
col umns, where M =r ound( t end/del t 2)
+ 1 and del t 2 i s the sampl i ng ti me. The fi rst row wi l l contai n the i ni ti al
condi ti on, and row k 1 wi l l gi ve the val ues of the pl ant outputs, y (see above
di agram), at ti me t =kT.
u
I s a matri x contai ni ng the same number of rows as y p and n
u
col umns. The
ti me correspondi ng to each row i s the same as for y p. The el ements i n each row
are the val ues of the mani pul ated vari abl es, u (see above di agram).
ym
I s a matri x of the same structure as y p, contai ni ng the val ues of the predi cted
outputs from the state esti mator i n the control l er. y mwi l l , i n general , di ffer
from y p i f model pl ant and/or there are unmeasured di sturbances. The
predi cti on i ncl udes the effect of the most recent measurement, i .e., . y k k ( )
mpcsim
1-66
Examples Consi der the l i near system:
The fol l owi ng statements bui l d the model and cal cul ate the MPC control l er
gai n:
g11=pol y 2t f d( 12. 8, [ 16. 7 1] , 0, 1) ;
g21=pol y 2t f d( 6. 6, [ 10. 9 1] , 0, 7) ;
g12=pol y 2t f d( - 18. 9, [ 21. 0 1] , 0, 3) ;
g22=pol y 2t f d( - 19. 4, [ 14. 4 1] , 0, 3) ;
del t =3; ny =2; t f i nal =90;
model =t f d2s t ep( t f i nal , del t , ny , g11, g21, g12, g22) ;
pl ant =model ;
P=6; M=2;
y wt =[ ] ; uwt =[ 1 1] ;
Kmpc=mpccon( i mod, y wt , uwt , M, P) ;
y
1
s ( )
y
2
s ( )
12.8e
s
16.7s 1 +
------------------------
18.9e
3s
21.0s 1 +
-------------------------
6.6e
7s
10.9s 1 +
------------------------
19.4e
3s
14.4s 1 +
-------------------------
u
1
s ( )
u
2
s ( )
=
mpcsim
4-67
Si mul ate and pl ot the cl osed-l oop per for mance for a uni t step i n the setpoi nt for
y
2
, occurri ng at t = 0.
t end=30; r =[ 0 1] ;
[ y , u] =mpcs i m( pl ant , model , Kmpc, t end, r ) ;
pl ot al l ( y , u, de l t ) , paus e
0 5 10 15 20 25 30
0.2
0
0.2
0.4
0.6
0.8
1
1.2
Outputs
Time
0 5 10 15 20 25 30
0.24
0.22
0.2
0.18
0.16
0.14
0.12
0.1
Manipulated Variables
Time
mpcsim
1-68
Try a pul se change i n the di sturbance that adds to u
1
:
r =[ ] ; us at =[ ] ; t f i l t e r =[ ] ; dmode l =[ ] ;
dpl ant =pl ant ;
ds t ep=[ 1 0; 0 0] ;
[ y , u] =mpcs i m( pl ant , mode l , Kmpc, t end, r , us at , t f i l t er , . . .
dpl ant , dmodel , ds t ep) ;
pl ot al l ( y , u, del t ) , paus e
For the same di sturbance as i n the previ ous case, l i mi t the rates of change of
both mani pul ated vari abl es.
us at =[ - i nf - i nf i nf i nf 0. 1 0. 05] ;
[ y , u] =mpcs i m( pl ant , mode l , Kmpc, t end, r , us at , t f i l t er , . . .
0 5 10 15 20 25 30
1
0.5
0
0.5
1
1.5
Outputs
Time
0 5 10 15 20 25 30
0.6
0.5
0.4
0.3
0.2
0.1
0
0.1
Manipulated Variables
Time
mpcsim
4-69
dpl ant , dmodel , ds t e p) ;
pl ot al l ( y , u, de l t ) , paus e
Restriction I ni ti al condi ti ons of zero are used for al l the vari abl es. Thi s si mul ates the
condi ti on where al l vari abl es represent a devi ati on from a steady-state i ni ti al
condi ti on.
See Also pl ot al l , pl ot each, cmpc , mpccl , mpccon
0 5 10 15 20 25 30
1
0.5
0
0.5
1
1.5
2
Outputs
Time
0 5 10 15 20 25 30
0.3
0.2
0.1
0
0.1
Manipulated Variables
Time
nlcmpc
1-70
1nl cmpc
Purpose Model predi cti ve control l er for si mul ati ng cl osed-l oop systems wi th hard
bounds on mani pul ated vari abl es and/or control l ed vari abl es usi ng l i near
model s i n the MPC step format for nonlinear pl ants represented as Si mul i nk
S-functi ons.
Description nl c mpc i s a Si mul i nk S-functi on bl ock and can be i nvoked by typi ng nl mpcl i b
at the MATLAB prompt. I ts usage i s i denti cal to other Si mul i nk bl ocks. The
i nput to nl cmpc i ncl udes both the vari abl es control l ed by nl cmpc and measured
di sturbances. The fi rst n
y
el ements of the i nput are treated as the control l ed
vari abl es whi l e the rest i s taken as the measured di sturbances. The output
from nl c mpc are the val ues of the mani pul ated vari abl es. I ni ti al condi ti ons for
the mani pul ated vari abl es and the measured di sturbances must be speci fi ed.
The control l ed vari abl es sent to nl cmpc and the mani pul ated vari abl es
returned by nl cmpc are actual vari abl es; they are not devi ati on vari abl es.
Because of the l i mi t on the number of masked vari abl es that can be speci fi ed
for a Si mul i nk bl ock, model and dmodel are put together as one vari abl e, r ,
y wt , and uwt as one vari abl e, and y l i mand ul i mas one vari abl e. mand p
shoul d be entered as one rowvector. u0 and d0 shoul d al so be entered as one
rowvector. The requi red i nput vari abl es are as fol l ows:
model pd
Equal s [model dmodel ]. model i s a linear model i n the MPC step format that i s
to be used for state esti mati on i n the control l er. I n general , i t i s a l i near
approxi mati on of the nonl i near pl ant. dmodel i s a model i n MPC step format
representi ng the effect of the measured di sturbances. The defaul t i s no
measured di sturbances. Note that the truncati on ti me for model and dmodel
must be the same and the number of outputs for model and dmodel must be the
same.
nlcmpc
4-71
ryuwt
Equal s [ r y wt uwt ] . r i s a setpoi nt matri x consi sti ng of N rows and n
y
col umns, where n
y
i s the number of output vari abl es, y:
Where r
i
(k) i s the setpoi nt for output i at ti me t =kT, and T i s the sampl i ng
peri od (as speci fi ed i n the stepformat of model ). I f the si mul ati on ti me i s l arger
than NT, the setpoi nts vary for the fi rst N peri ods i n the si mul ati on, as
speci fi ed by r , and are then hel d constant at the val ues gi ven i n the l ast row of
r for the remai nder of the si mul ati on. I n many si mul ati ons one wants the
setpoi nts to be constant for the enti re ti me, i n whi ch case r need onl y contai n
a si ngl e row of n
y
val ues.
ywt
Must have n
y
col umns, where n
y
i s the number of outputs. Al l wei ghts must be
0.
You may vary the wei ghts at each step i n the predi cti on hori zon by i ncl udi ng
up to Prows i n y wt . Then the fi rst row of n
y
val ues appl i es to the tracki ng errors
i n the fi rst step i n the predi cti on hori zon, the next row appl i es to the next step,
etc. See mpccon for detai l s on the form of the opti mi zati on objecti ve functi on.
I f you suppl y onl y nrowrows, where 1 nrow< P, nl cmpc wi l l use the l ast row
to fi l l i n any remai ni ng steps. Thus i f you wi sh the wei ghti ng to be the same for
al l P steps, you need onl y speci fy a si ngl e row.
uwt
Has the same format as y wt , except that uwt appl i es to the changes i n the
mani pul ated vari abl es. I f uwt [ ] , i t must have n
u
col umns, where n
u
i s the
number of mani pul ated vari abl es.
Noti ce that the number of rows for r , y wt , and uwt shoul d be the same. I f not,
one can enter the vari abl e as par par t ( r , y wt , uwt ) . The functi on par par t
r
r
1
1 ( ) r
2
1 ( ) r
n
y
1 ( )
r
1
2 ( ) r
2
2 ( ) r
n
y
2 ( )

r
1
N ( ) r
2
N ( ) r
n
y
N ( )
=

nlcmpc
1-72
appends extra rows to r , y wt , and/or uwt so that they have the same number
of rows. The defaul t i s r =y0, where y0 i s the i ni ti al condi ti on for the output,
equal (uni ty) wei ghti ng of al l outputs over the enti re predi cti on hori zon and
zero wei ghti ng of al l i nput.
mp
Equal s [ MP] . Pequal s the l ast el ement of MP. There are two ways to speci fy M:
I f i t i s a scalar, nl c mpc i nterprets i t as the i nput hori zon (number of moves) as
i n DMC; i f i t i s a rowvector contai ni ng n
b
el ements, each el ement of the vector
i ndi cates number of the steps over whi ch u(k) =0 duri ng the opti mi zati on and
nl c mpc i nterprets i t as a set of n
b
bl ocki ng factors. There may be 1 n
b
P
bl ocki ng factors, and thei r sum must be P. I f you set M=[ ] , the defaul t i s
M= P, whi ch i s equi val ent to M=ones ( 1, P) . Pi s the number of sampl i ng peri ods
i n the predi cti on hori zon.
yul i m
Equal s [y l i mul i m]. ul i mi s a matri x gi vi ng the l i mi ts on the mani pul ated
vari abl es. I ts format i s as fol l ows:
, ,
, ,
, ,
,
( )
,
( )
, ,
, ,
, ,
,
( )
,
( )
ulim
u
mi n 1 ,
1 ( ) u
mi n n
u
,
1 ( )
u
mi n 1 ,
2 ( ) u
mi n n
u
,
2 ( )

u
mi n 1 ,
N ( ) u
mi n n
u
,
N ( )
=
u
max 1 ,
1 ( ) u
max n
u
,
1 ( )
u
max 1 ,
2 ( ) u
max n
u
,
2 ( )

u
max 1 ,
N ( ) u
max n
u
,
N ( )
u
max 1 ,
1 ( ) u
max n
u
,
1 ( )
u
max 1 ,
2 ( ) u
max n
u
,
2 ( )

u
max 1 ,
N ( ) u
max n
u
,
N ( )



nlcmpc
4-73
Note that i t contai ns three matri ces of N rows. I n thi s case, the l i mi ts on N are
1 N n
b
, where n
b
i s the number of ti mes the mani pul ated vari abl es are to
change over the i nput hori zon. I f you suppl y fewer than n
b
rows, the l ast row i s
repeated automati cal l y.
The fi rst matri x speci fi es the lower bounds on the n
u
mani pul ated vari abl es.
For exampl e, u
min
,
j
(2) i s the l ower bound for mani pul ated vari abl e j for the
second move of the mani pul ated vari abl es (where the fi rst move i s at the start
of the predi cti on hori zon). I f u
min
,
j
(k) = inf, mani pul ated vari abl e j wi l l have
no l ower bound for that move.
The second matri x gi ves the upper bounds on the mani pul ated vari abl es. I f
u
max,j
(k) =inf, mani pul ated vari abl e j wi l l have no upper bound for that move.
The l ower and upper bounds may be ei ther posi ti ve or negati ve (or zer o) as l ong
as u
min
,
j
(k) u
max,j
(k).
The thi rd matri x gi ves the l i mi ts on the rate of change of the mani pul ated
vari abl es. I n other words, cmpc wi l l force| u
j
(k) u
j
(k 1)| u
max,j
(k). The
l i mi ts on the rate of change must be nonnegati ve and finite. I f you want i t to be
unbounded, set the bound to a l arge number (but not too l arge a val ue of 10
6
shoul d work wel l i n most cases).
y l i m has the same format as ul i m, but for the l ower and upper bounds of the
outputs. The fi rst row appl i es to the fi rst poi nt i n the predi cti on hori zon.
Note that the number of rows for y l i mand ul i mshoul d be the same. I f the
number of rows for y l i mand ul i mdi ffers, one can use par par t ( y l i m, ul i m) .
The functi on par par t appends extra rows to y l i mor ul i mso that they have the
same number of rows. I f you set y ul i m = [ ] , then u
min
=inf, u
max
=inf, u
max
= 10
6
, y
min
= inf and y
max
=inf.
tf i l ter
I s a matri x of ti me constants for the noi se fi l ter and the unmeasured
di sturbances enteri ng at the pl ant output. The fi rst row of n
y
el ements gi ves
the noi se fi l ter ti me constants and the second row of n
y
el ements gi ves the ti me
constants of the l ags through whi ch the unmeasured di sturbance steps pass. I f
t f i l t er onl y contai ns one row, the unmeasured di sturbances are assumed to
be steps. I f you set t f i l t er = [ ] , no noi se fi l teri ng and stepl i ke unmeasured
di sturbances are assumed.
nlcmpc
1-74
ud0
Equal s [ u0 d0] . u0 are i ni ti al val ues of the mani pul ated vari abl es arranged i n
a rowvector havi ng n
u
el ements; n
u
i s the number of the mani pul ated vari abl es
computed by nl cmpc. d0 are i ni ti al val ues of the measured di sturbances
arranged i n a rowvector havi ng n
d
el ements; n
d
i s the number of the measured
di sturbances. The defaul t i s u0 = 0 and d0 = 0.
Notes I ni ti al condi ti ons for the mani pul ated vari abl es that are cal cul ated by
nl cmpc are speci fi ed through nl cmpc whi l e i ni ti al condi ti ons for the
control l ed vari abl es are speci fi ed through the S-functi on for the nonl i near
pl ant.
You may use a di fferent number of rows i n the matri ces r , ul i mand y l i m,
shoul d that be appropri ate for your si mul ati on.
The ul i mconstrai nts used here are fundamental l y di fferent from the us at
constrai nts used i n the nl mpc s i mbl ock. The ul i mconstrai nts are defi ned
rel ati ve to the begi nni ng of the predi cti on hori zon, whi ch moves as the
si mul ati on progresses. Thus at each sampl i ng peri od, k, the ul i mconstrai nts
appl y to a bl ock of cal cul ated moves that begi n at sampl i ng peri od k and
extend for the durati on of the i nput hori zon. The us at constrai nts, on the
other hand, are rel ati ve to the fi xed poi nt t = 0, the start of the si mul ati on.
For unconstrai ned probl ems, nl cmpc and nl mpcs i mshoul d gi ve the same
resul ts. The l atter wi l l be faster because i t uses an anal yti cal sol uti on of the
QP probl em, whereas nl cmpc sol ves i t by i terati on.
Example See the exampl es for nl mpcs i mwi th one modi fi cati on: repl ace the bl ock
nl mpcs i mwi th nl cmpc. Cl earl y, addi ti onal vari abl es shoul d be defi ned
appropri atel y.
See Also cmpc, nl mpcs i m
nlmpcsim
4-75
1nl mpcsi m
Purpose Model predi cti ve control l er for si mul ati ng cl osed-l oop systems wi th saturation
constraints on the mani pul ated vari abl es usi ng l i near model s i n the MPC step
format for nonl i near pl ants represented as Si mul i nk S-functi ons.
Description nl mpc s i mi s a Si mul i nk S-functi on bl ock and can be i nvoked by typi ng
nl mpc l i b at the MATLAB prompt. I ts usage i s i denti cal to other Si mul i nk
bl ocks. The i nput to nl mpcs i mi ncl udes both the vari abl es control l ed by
nl mpc s i mand measured di sturbances. The fi rst n
y
el ements of the i nput are
treated as the control l ed vari abl es whi l e the rest i s taken as the measured
di sturbances. The output from nl mpcs i mare the val ues of the mani pul ated
vari abl es. I ni ti al condi ti ons for the mani pul ated vari abl es and the measured
di sturbances must be speci fi ed. Both the control l ed vari abl es sent to nl mpcs i m
and the mani pul ated vari abl es returned by nl mpcs i mare the actual vari abl es;
they are not devi ati on vari abl es.
Because of the l i mi t on the number of masked vari abl es that can be speci fi ed
for a Si mul i nk bl ock, model and dmodel are put together as one vari abl e. u0 and
d0 shoul d be entered as one rowvector. The requi red i nput vari abl es are as
fol l ows:
model pd
Equal s [mode l dmodel ]. model i s a l i near model i n the MPC step format that i s
to be used for state esti mati on i n the control l er. I n general , i t i s a l i near
approxi mati on for the nonl i near pl ant. Note, however, that model shoul d be the
same as that used to cal cul ate Kmpc. dmodel i s a model i n MPC step format
representi ng the measured di sturbances. I f dmodel = [ ] , the defaul t i s no
measured di sturbances. Note that the truncati on ti me for model and dmodel
shoul d be the same and the number of outputs for model and dmodel shoul d be
the same.
Kmpc
I s the MPC control l er gai n matri x, usual l y cal cul ated usi ng the functi on
mpccon.
nlmpcsim
1-76
r
I s a setpoi nt matri x consi sti ng of N rows and n
y
col umns, where n
y
i s the
number of control l ed vari abl es, y:
Where r
i
(k) i s the setpoi nt for output i at ti me t =kT, and T i s the sampl i ng
peri od (as speci fi ed i n the stepformat of model ). I f the si mul ati on ti me i s l arger
than NT, the setpoi nts vary for the fi rst N peri ods i n the si mul ati on, as
speci fi ed by r , and are then hel d constant at the val ues gi ven i n the l ast row of
r for the remai nder of the si mul ati on.
I n many si mul ati ons one wants the setpoi nts to be constant for the enti re ti me,
i n whi ch case r need onl y contai n a si ngl e row of n
y
val ues.
Note that r i s the actual setpoi nt. I f you set r =[ ] , the defaul t i s y 0.
r
r
1
1 ( ) r
2
1 ( ) r
n
y
1 ( )
r
1
2 ( ) r
2
2 ( ) r
n
y
2 ( )

r
1
N ( ) r
2
N ( ) r
n
y
N ( )
=

nlmpcsim
4-77
usat
I s a matri x gi vi ng the saturati on l i mi ts on the mani pul ated vari abl es. I ts
format i s as fol l ows:
Note that i t contai ns three matri ces of N rows. N may be di fferent from that for
the setpoi nt matri x, r , but the i dea i s the same: the saturati on l i mi ts wi l l vary
for the fi rst N sampl i ng peri ods of the si mul ati on, then be hel d constant at the
val ues gi ven i n the l ast row of us at for the remai ni ng peri ods (i f any).
The fi rst matri x speci fi es the lower bounds on the n
u
mani pul ated vari abl es.
For exampl e, u
min
,
j
(k) i s the l ower bound for mani pul ated vari abl e j at ti me t =
kT i n the si mul ati on. I f u
min
,
j
(k) = inf, mani pul ated vari abl e j wi l l have no
l ower bound at t =kT.
The second matri x gi ves the upper bounds on the mani pul ated vari abl es. I f
u
max,j
(k) =inf, mani pul ated vari abl e j wi l l have no upper bound at t =kT.
The l ower and upper bounds may be ei ther posi ti ve or negati ve (or zer o) as l ong
as u
min
,
j
(k) u
max,j
(k).
, ,
, ,
, ,
,
( )
,
( )
, ,
, ,
, ,
,
( )
,
( )
usat
u
mi n 1 ,
1 ( ) u
mi n n
u
,
1 ( )
u
mi n 1 ,
2 ( ) u
mi n n
u
,
2 ( )

u
mi n 1 ,
N ( ) u
mi n n
u
,
N ( )
=
u
max 1 ,
1 ( ) u
max n
u
,
1 ( )
u
max 1 ,
2 ( ) u
max n
u
,
2 ( )

u
max 1 ,
N ( ) u
max n
u
,
N ( )
u
max 1 ,
1 ( ) u
max n
u
,
1 ( )
u
max 1 ,
2 ( ) u
max n
u
,
2 ( )

u
max 1 ,
N ( ) u
max n
u
,
N ( )



nlmpcsim
1-78
The thi rd matri x gi ves the l i mi ts on the rate of change of the mani pul ated
vari abl es. I n other words, mpcs i mwi l l force| u
j
(k) u
j
(k 1)| u
max,j
(k). The
l i mi ts on the rate of change must be nonnegati ve.
I f us at = [ ] , then al l the u
min
val ues wi l l be set to inf, and al l the u
max
and
u
max
val ues wi l l be set to inf.
Note: Saturati on constrai nts are enforced by si mpl y clippingthe mani pul ated
vari abl e moves so that they sati sfy al l constrai nts. Thi s i s a nonopti mal
sol uti on that, i n general , wi l l di ffer from the resul ts you woul d get usi ng the
ul i mvari abl e i n cmpc or nl c mpc.
tf i l ter
I s a matri x of ti me constants for the noi se fi l ter and the unmeasured
di sturbances enteri ng at the pl ant output. The fi rst row of n
y
el ements gi ves
the noi se fi l ter ti me constants and the second row of n
y
el ements gi ves the ti me
constants of the l ags through whi ch the unmeasured di sturbance steps pass. I f
t f i l t er onl y contai ns one row, the unmeasured di sturbances are assumed to
be steps. I f you set t f i l t er = [ ] , no noi se fi l teri ng and stepl i ke unmeasured
di sturbances are assumed.
ud0
Equal s [u0 d0]. u0 are i ni ti al val ues of the mani pul ated vari abl es arranged i n
a rowvector havi ng n
u
el ements; n
u
i s the number of the mani pul ated vari abl es
computed by nl mpcs i m. d0 are i ni ti al val ues of the measured di sturbances
arranged i n a rowvector havi ng n
d
el ements; n
d
i s the number of the measured
di sturbances. The defaul t i s u0 = 0 and d0 = 0.
Note: You may use a di fferent number of rows i n the matri ces r and us at ,
shoul d that be appropri ate for your si mul ati on.
Examples Let us now demonstrate the use of the control l er nl mpcs i m. Si nce the pl ant
used i n Exampl e 1 i s l i near, usi ng mpcs i mwoul d be much faster. The poi nt,
however, i s to show how masked vari abl es are speci fi ed for nl mpcs i m.
nlmpcsim
4-79
1 The pl ant i s l i near wi th two i nputs and two outputs. I t i s represented by
The Si mul i nk S-functi on for thi s pl ant i s i n mpcpl ant . m. The nomi nal
steady-state operati ng condi ti on i s y 0 = [ 58. 3 1. 5] and u0 = [ 100 1] . The
Si mul i nk bl ock to si mul ate thi s pl ant usi ng nl mpcs i mi s i n nl mpcdm1. mand
shown i n Fi gure 1-1.
Figure 1-1 Simulink Block for Example 1
The fol l owi ng statements bui l d the step response model and speci fy the
parameter val ues. Note that model does not equal the pl ant model stored i n
dx
dt
-------
1.2 0
0
1
1.5
--------
x
0.2
1
u
50
0
+ + =
y x =
y1, y2
nlmpcsim Demo #1
(Double click on the "?" for more info)
nlmpcsim
nlmpcsim
t
Save Time
y
Save Outputs
u
Save Inputs
mpcplant
Sfunction
Plot
Results
?
Load
Data
Clock
nlmpcsim
1-80
mpc pl ant . m. The i mportant thi ng to noti ce i s that both r and us at are actual
vari abl es. They are not devi ati on vari abl es.
g11=pol y ( 0. 4, [ 1 2] ) ;
g21=pol y 2t f d( 0, 1) ;
g12=pol y 2t f d( 0, 1) ;
g22=pol y 2t f d( 1, [ 1 1] ) ;
t f i nal =8;
del t =0. 2;
nout =2;
model =t f d2s t ep( t f i nal , del t , nout , g11, g21, g12, g22) ;
y wt =[ 1 1] ;
uwt =[ 0 0] ;
M=4;
P=10;
r =[ 68. 3 2] ;
us at =[ 100 1 200 3 200 200] ;
t f i l t er =[ ] ;
Kmpc = mpccon( model , y wt , uwt , M, P) ;
dmodel = [ ] ;
There are two ways to si mul ate the cl osed l oop system. We can set the
si mul ati on parameters and cl i ck on Start under Simulation or vi a the
fol l owi ng statements.
pl ant =nl mpcdm1; y 0=[ 58. 3 1. 5] ;
u0=[ 100 1] ;
t f s i m = 2;
t ol =[ 1e- 3] ;
mi ns t ep=[ ] ;
max s t ep=[ ] ;
[ t , y u] =gear ( pl ant , t f s i m, [ y 0 u0] , [ t ol , mi ns t ep, max s t ep] ) ;
Fi gure 1-2 shows the response for the setpoi nt change.
nlmpcsim
4-81
Figure 1-2 Output responses for a setpoint change for Example 1
2 The pl ant i s the paper machi ne headbox di scussed i n the secti on,
Appl i cati on: Paper Machi ne Headbox Control i n Chapter 3. The nonl i near
pl ant model i s represented as a Si mul i nk S-functi on and i s i n pap_mach. m.
The pl ant has two i nputs, three outputs, four states, one measured
di sturbance, and one unmeasured di sturbance. Al l these vari abl es are zero
at the nomi nal steady-state. Si nce the model for nl mpcs i mmust be l i near,
we l i neari ze the nonl i near pl ant at the nomi nal steady-state to obtai n a
l i near model . Si nce the model i s si mpl e, we can l i neari ze i t anal yti cal l y to
obtai n A, B, C, and D.
The Si mul i nk bl ock to si mul ate thi s nonl i near pl ant usi ng nl mpc s i mi s i n
nl mpcdm2. mand shown i n Fi gure 1-3.
nlmpcsim
1-82
Figure 1-3 Simulink Block for Example 2
The fol l owi ng statements bui l d the step response model and speci fy the
parameter val ues.
A=[ - 1. 93 0 0 0; . 394 - . 426 0 0; 0 0 - . 63 0; . 82 - . 784
. 413 - . 426] ;
B=[ 1. 274 1. 274 0; 0 0 0; 1. 34 - . 65 . 203; 0 0 0] ;
C=[ 0 1 0 0; 0 0 1 0; 0 0 0 1] ;
D=z er os ( 3, 3) ;
% Di s cr et i z e t he l i near model and s av e i n MOD f or m.
dt =2;
[ PHI , GAM] =c2dmp( A, B, dt ) ;
mi nf o=[ dt , 4, 2, 1, 0, 3, 0] ;
i mod=s s 2mod( PHI , GAM, C, D, mi nf o) ;
% St or e pl ant model and meas ur ed di s t ur bance model i n MPC
% s t ep f or mat
Gp, Gw
Np
Nw
nlmpcsim Demo #2
(Double click on the "?" for more info)
nlmpcsim
nlmpcsim
Step Fcn1
Step Fcn
t
Save Time
y
Save Outputs
u
Save Inputs
papmach
Sfunction
Plot
Results
Mux
Mux2
Mux
Mux1
?
Load
Data
Clock
nlmpcsim
4-83
[ model , dmodel ] =mod2s t ep( i mod, 20) ;
m=5;
p=20;
y wt =[ 1 0 5] ; % unequal we i ght i ng of y 1 and y 3, no cont r ol
% of y 2
uwt =[ 1 1] ; % Equal wei ght i ng of u1 and u2
ul i m=[ - 10 - 10 10 10 2 2] ; % Cons t r ai nt s on u
y l i m=[ ] ; % No cons t r ai nt s on y
us at =ul i m;
t f i l t er =[ ] ;
y 0=[ 0 0 0] ;
u0=[ 0 0] ;
r =[ 0 0 0] ;
Kmpc=mpccon( model , y wt , uwt , M, P) ;
Fi gure 1-4 shows the output responses for a uni t-step measured di sturbance
Np = 1 and a step unmeasured di sturbance wi th Nw = 5.
Figure 1-4 Output responses for a unit-step measured disturbance Np=1 and
a step unmeasured disturbance Nw = 5
See Also mpcs i m, nl cmpc
-6
-4
2
0
-2
4
5 10 15 20 25 0 30
O
u
t
p
u
t
Time
Solid: y1 (H2)
Dashed: y2 (N1)
Dotted: y3 (N2)
y1
y2
y3
paramod
1-84
1par amod
Purpose Puts two model s i n paral l el by connecti ng thei r outputs. Mi mi cs the uti l i ty
functi on mpcpar al , except that par amod works on model s i n the MPC mod
format.
Syntax pmod = par amod( mod1, mod2)
Description
mod1 and mod2 are model s i n the MPC mod format (see mod i n the onl i ne
MATLAB Function Referenceformat secti on for a detai l ed descri pti on). You
woul d normal l y create them usi ng ei ther the t f d2mod, s s 2mod or t h2mod
functi ons.
par amod combi nes them to form a composi te system, pmod, as shown i n the
above di agram. I t i s al so i n the mod format. Note how the i nputs to mod1 and
mod2 are ordered i n pmod.
Restriction mod1 and mod2 must have been created wi th equal sampl i ng peri ods and they
must have the same number of measured and unmeasured outputs.
See Also addmd, addmod, addumd, appmod, s er mod
mod1
y
2
mod2
u
1
d
1
w
1
u
2
d
2
w
2
y
1
y
pmod
u
1
u
2
d
1
d
2
w
1
w
2
y

+
+
plotall
4-85
1pl otal l
Purpose Pl ots outputs and mani pul ated vari abl es from a si mul ati on, al l on one page.
Syntax pl ot al l ( y , u) pl ot al l ( y , u, t )
Description I nput vari abl es y and u are matri ces of outputs and mani pul ated vari abl es,
respecti vel y. Each row represents a sampl e at a parti cul ar ti me. Each col umn
shows how a parti cul ar output (or mani pul ated) vari abl e changes wi th ti me.
I nput vari abl e t i s opti onal . I f you suppl y i t as a scal ar, pl ot al l i nterprets i s
as the sampl i ng peri od, and cal cul ates the ti me axi s for the pl ots accordi ngl y.
I t can al so be a col umn vector, i n whi ch case i t must have the same number of
rows as y and u and i s i nterpreted as the ti mes at whi ch the sampl es of y and
u were taken. I f you do not suppl y t , pl ot al l uses a sampl i ng peri od of 1 by
defaul t.
pl ot al l pl ots al l the outputs on a si ngl e graph. I f there are mul ti pl e outputs
that have very di fferent numeri cal scal es, thi s may be unsati sfactory. I n that
case, use pl ot each.
pl ot al l pl ots al l the mani pul ated vari abl es i n stai rstep form (i .e., assumi ng
a zero-order hol d) on a si ngl e graph. Agai n, pl ot each may be the better choi ce
i f scal es are very di fferent.
plotall
1-86
Exampl e output: (mpccon exampl e)
See Also pl ot each, pl ot s t ep, pl ot f r s p
0 5 10 15 20 25 30
1
0.5
0
0.5
1
Outputs
Time
0 5 10 15 20 25 30
0
0.1
0.2
0.3
0.4
0.5
Manipulated Variables
Time
ploteach
4-87
1pl oteach
Purpose Pl ots outputs and mani pul ated vari abl es from a si mul ati on on separate
graphs, up to four per page.
Syntax pl ot e ach( y )
pl ot e ach( y , u)
pl ot e ach( [ ] , u)
pl ot e ach( y , [ ] , t )
pl ot e ach( [ ] , u, t )
pl ot e ach( y , u, t )
Description I nput vari abl es y and u are matri ces of outputs and mani pul ated vari abl es,
respecti vel y. Each row represents a sampl e at a parti cul ar ti me. Each col umn
shows how a parti cul ar output (or mani pul ated)vari abl e changes wi th ti me. As
shown above, you may suppl y both y and u, or omi t ei ther one of them.
I nput vari abl e t i s opti onal . I f you suppl y i t as a scal ar , pl ot each i nterprets i s
as the samplingperiod, and cal cul ates the ti me axi s for the pl ots accordi ngl y.
I t can al so be a col umn vector, i n whi ch case i t must have the same number of
rows as y and u and i s i nterpreted as the ti mes at whi ch the sampl es of y and
u were taken. I f you do not suppl y t , pl ot each uses a sampl i ng peri od of 1 by
defaul t.
pl ot e ach pl ots the mani pul ated vari abl es i n stai rstep form (i .e., assumi ng a
zero-order hol d).
ploteach
1-88
Exampl e output: (mpccon exampl e)
See Also pl ot al l , pl ot f r s p, pl ot s t ep
plotfrsp
4-89
1pl otfr sp
Purpose Pl ots the frequency response generated by mod2f r s p as a Bode pl ot.
Syntax pl ot f r s p( v mat )
pl ot f r s p( v mat , out , i n)
Description v mat i s a varyingmatri x whi ch contai ns the data to be pl otted.
Let F() denote the matri x (whose entri es are functi ons of the i ndependent
vari abl e ) whose sampl ed val ues F(
1
), ... , F(
N
) are contai ned i n v mat .
pl ot f r s p( v mat ) wi l l gener ate Bode pl ots of al l el ements of F().
Opti onal i nputs out and i n are rowvectors whi ch speci fy the row and col umn
i ndi ces respecti vel y of a submatri x of F(). pl ot f r s p wi l l then generate Bode
pl ots of the el ements of the speci fi ed submatri x of F().
Exampl e Output: (mod2f r s p exampl e)
See Also mod2f r s p, v ar y i ng f or mat
10
3
10
2
10
1
10
0
10
4
10
2
10
0
10
2
Frequency (radians/time)
L
o
g

M
a
g
n
i
t
u
d
e
BODE PLOTS
10
3
10
2
10
1
10
0
500
400
300
200
100
0
100
Frequency (radians/time)
P
h
a
s
e

(
d
e
g
r
e
e
s
)
plotstep
1-90
1pl otstep
Purpose Pl ots mul ti pl e step responses as cal cul ated by mod2s t ep, s s 2s t ep or t f d2s t ep.
Syntax pl ot s t ep( pl ant )
pl ot s t ep( pl ant , opt )
Description pl ant i s a step-response matri x i n the MPC step format created by mod2s t ep,
s s 2s t ep or t f d2s t ep.
opt i s an opti onal scal ar or rowvector that al l ows you to sel ect the outputs to
be pl otted. I f you omi t opt , pl ot s t ep pl ots every output. I f, for exampl e, pl ant
contai ns resul ts for 6 outputs, setti ng opt =[ 1, 4, 5] woul d cause onl y y
1
, y
4
and
y
5
to be pl otted.
Exampl e output: (t f d2s t ep exampl e)
0 10 20 30 40 50 60 70 80 90
0
2
4
6
8
10
12
14
u1 step response : y1
TIME
0 10 20 30 40 50 60 70 80 90
0
1
2
3
4
5
6
7
u1 step response : y2
TIME
plotstep
4-91
See Also i mp2s t ep, mod2s t ep, s t ep f or mat , pl ot al l , pl ot each, pl ot f r s p, s s 2s t ep,
t f d2s t ep
0 10 20 30 40 50 60 70 80 90
20
15
10
5
0
u2 step response : y1
TIME
0 10 20 30 40 50 60 70 80 90
20
15
10
5
0
u2 step response : y2
TIME
plsr
1-92
1pl sr
Purpose Determi ne the i mpul se response coeffi ci ents for a mul ti -i nput si ngl e-output
system vi a Parti al Least Squares (PLS).
Syntax [ t het a, w, cw, s s qdi f , y r es ] = pl s r ( x r eg, y r eg, ni nput , l v )
[ t het a, w, cw, s s qdi f , y r es ] = pl s r ( x r eg, y r eg, ni nput , l v , pl ot opt )
Description Gi ven a set of regressi on data, x r eg and y r eg, the i mpul se response coeffi ci ent
matri x, t he t a, i s determi ned vi a PLS. Col umn i of t het a corresponds to the
i mpul se response coeffi ci ents for i nput i. Onl y a si ngl e output i s al l owed. The
number of i nputs, ni nput , and the number of l atent vari abl es, l v , must be
speci fi ed.
Opti onal output w i s a matri x of di mensi on n (number of i mpul se response
coeffi ci ents) by l v consi sti ng of orthogonal col umn vectors maxi mi zi ng the
cross vari ance between i nput and output. Col umn vector cw(opti onal ) contai ns
the coeffi ci ents associ ated wi th each orthogonal vector for cal cul ati ng t het a
( t het a=w
*
cw) .
Opti onal output s s qdi f i s an l v -by-2 matri x contai ni ng the percent vari ances
captured by PLS. The fi rst col umn contai ns i nformati on for the i nput; the
second col umn for the output. Rowi of s s qdi f gi ves a measure of the vari ance
captured by usi ng the fi rst i l atent vari abl es.
The output resi dual or predi cti on error (y r es ) i s al so returned (opti onal ).
No pl ot i s produced i f pl ot opt i s equal to 0, whi ch i s the defaul t; a pl ot of the
actual output and the predi cted output i s produced i f pl ot opt =1; two pl ots
pl ot of actual and predi cted output, and pl ot of output resi dual are produced
for pl ot opt =2.
Example Consi der the fol l owi ng two-i nput si ngl e-output system:
Load the i nput and output data. The i nput and output data were generated
from the above transfer functi on and random zero-mean noi se was added to the
output. Sampl i ng ti me of 7 mi nutes was used.
l oad pl s r dat ;
y s ( )
5.72e
14s
60s 1 +
-------------------------
1.52e
15s
25s 1 +
-------------------------
u
1
s ( )
u
2
s ( )
=
plsr
4-93
Put the i nput and output data i n a form such that they can be used to
determi ne the i mpul se response coeffi ci ents. 30 i mpul se response coeffi ci ents
(n) are used.
n = 30;
[ x r eg, y r eg] = wr t r eg( x , y , n) ;
Determi ne the i mpul se response coeffi ci ents vi a pl s r usi ng 10 l atent vari abl es.
By speci fyi ng pl ot opt =2, two pl ots pl ot of predi cted output and actual
output, and pl ot of the output resi dual (or predi cted error) are produced.
ni nput = 2;
l v = 10;
pl ot opt = 2;
t he t a = pl s r ( x r eg, y r eg, ni nput , l v , pl ot opt ) ;
Use a new set of data to val i date the i mpul se model .
[ ne wx r eg, newy r eg] = wr t r e g( newx , newy , n) ;
y r e s = v al i dmod( newx r eg, newy r eg, t het a, pl ot opt ) ;
0 20 40 60 80 100 120
3
2
1
0
1
2
3
Actual value (o) versus Predicted Value (+)
Sample Number
O
u
t
p
u
t
0 20 40 60 80 100 120
0.4
0.3
0.2
0.1
0
0.1
0.2
0.3
Output Residual or Prediction Error
Sample Number
R
e
s
i
d
u
a
l
plsr
1-94
Convert the i mpul se model to a step model to be used i n MPC desi gn. Sampl i ng
ti me of 7 mi nutes was used i n determi ni ng the i mpul se model . Number of
outputs (1 i n thi s case) must be speci fi ed.
nout = 1;
del t = 7;
model = i mp2s t ep( del t , nout , t het a) ;
0 5 10 15 20 25 30
6
4
2
0
2
4
Actual value (o) versus Predicted Value (+)
Sample Number
O
u
t
p
u
t
0 5 10 15 20 25 30
0.6
0.4
0.2
0
0.2
0.4
Output Residual or Prediction Error
Sample Number
R
e
s
i
d
u
a
l
plsr
4-95
Pl ot the step response coeffi ci ents.
pl ot s t ep( model )
See Also ml r , v al i dmod, wr t r eg
0 50 100 150 200 250
1
0
1
2
3
4
5
6
u1 step response : y1
TIME
0 50 100 150 200 250
0.2
0
0.2
0.4
0.6
0.8
1
1.2
1.4
1.6
1.8
u2 step response : y1
TIME
poly2tfd, poly format
1-96
1pol y2tfd, pol y for mat
Purpose pol y 2t f d converts a transfer functi on (conti nuous or di screte) from the
standard MATLAB pol y format i nto the MPC tf format.
Syntax g = pol y 2t f d( num, den)
g = pol y 2t f d( num, den, del t , del ay )
Description Consi der a conti nuous-ti me (Lapl ace domai n) transfer functi on such as
or a di screte-ti me transfer functi on such as
where z i s the forward-shi ft operator. Usi ng the MATLAB poly format, you
woul d represent ei ther of these as a numerator pol ynomi al and a denomi nator
pol ynomi al , gi vi ng the coeffi ci ents of the hi ghest-order terms fi rst:
num = [ b
0
b
1
. . . b
n
] ;
den = [ a
0
a
1
. . . a
n
] ;
I f the numerator contai ns l eadi ng zeros, they may be omi tted, i .e., the number
of el ements i n numcan be the number of el ements i n den.
pol y 2t f d uses numand den as i nput to bui l d a transfer functi on, g, i n the MPC
tf format (see t f secti on for detai l s). Opti onal vari abl es you can i ncl ude are:
del t
The sampl i ng peri od. I f thi s i s zero or you omi t i t, pol y 2t f d assumes that you
are suppl yi ng a conti nuous-ti me transfer functi on. I f you are suppl yi ng a
di screte-ti me transfer functi on you must speci fy del t . Otherwi se gwi l l be
mi si nterpreted when you use i t l ater i n the MPC Tool box functi ons.
del ay
The ti me del ay. For a conti nuous-ti me transfer functi on, del ay shoul d be i n
ti me uni ts. For a di screte-ti me transfer functi on, del ay shoul d be speci fi ed as
G s ( )
b
0
s
n
b
1
s
n 1
b
n
+ + +
a
0
s
n
a
1
s
n 1
a
n
+ + +
---------------------------------------------------------------- =
G z ( )
b
0
b
1
z
1
b
n
z
n
+ + +
a
0
a
1
z
1
a
n
z
n
+ + +
------------------------------------------------------------- =
poly2tfd, poly format
4-97
the i nteger number of sampl i ng peri ods of ti me del ay. I f you omi t i t, pol y 2t f d
assumes a del ay of zero.
Examples Consi der the conti nuous-ti me transfer functi on:
G(s) = 0.5 .
I t has no del ay. The fol l owi ng command creates the MPC tf format:
g=pol y 2t f d( 0. 5*[ 3 - 1] , [ 5 2 1] ) ;
Now suppose there were a del ay of 2.5 ti me uni ts:
G(s) = 0.5 . You coul d use:
g=pol y 2t f d( 0. 5*[ 3 - 1] , [ 5 2 1] , 0, 2. 5) ;
Next l ets get the equi val ent transfer functi on i n di screte form. An easy way i s
to get the correct pol y form usi ng cp2dp, then use pol y 2t f d to get i t i n the tf
form. Here are the commands to do i t usi ng a sampl i ng peri od of 0.75 ti me
uni ts:
del t =0. 75;
[ numd, dend] =cp2dp( 0. 5
*
[ 3 - 1] , [ 5 2 1] , del t , r em( 2. 5, del t ) ) ;
g=pol y 2t f d( numd, dend, del t , f i x ( 2. 5/del t ) ) ;
Note that cp2dp i s used to handl e the fracti onal ti me del ay and the i nteger
number of sampl i ng peri ods of ti me del ay i s an i nput to pol y 2t f d. The resul ts
are:
numd =
0 0. 1232 - 0. 1106 - 0. 0607
dend =
1. 0000 - 1. 6445 0. 7408 0
g =
0 0. 1232 - 0. 1106 - 0. 0607
1. 0000 - 1. 6445 0. 7408 0
0. 7500 3. 0000 0 0
See Also cp2dp, t f , t h2mod, t f d2s t ep
3s 1
5s
2
2s 1 + +
--------------------------------
3s 1
5s
2
2s 1 + +
--------------------------------e
2.5s
scmpc
1-98
1scmpc
Purpose Si mul ates cl osed-l oop systems wi th hard bounds on mani pul ated vari abl es
and/or outputs usi ng model s i n the MPC mod format. Sol ves the MPC
opti mi zati on probl em by quadrati c programmi ng.
Syntax y p = s cmpc( pmod, i mod, y wt , uwt , M, P, t end, r )
[ y p, u, y m] = s c mpc( pmod, i mod, y wt , uwt , M, P, t end, . . .
r , ul i m, y l i m, Kes t , z , d, w, wu)
Description
s cmpc si mul ates the performance of the type of system shown i n the above
di agram when there are bounds on the mani pul ated vari abl es and/or outputs.
The requi red i nput vari abl es are as fol l ows:
pmod
I s a model i n the MPC mod format that i s to represent the pl ant.
i mod
I s a model i n the MPC modformat that i s to be used for state esti mati on i n the
control l er. I n general , i t can be di fferent from pmod i f you want to si mul ate the
effect of pl ant/control l er model mi smatch.
Disturbances
u
d
r Plant
Setpoints
Noise-free
d
y
Plant
Outputs

Measured
Outputs

w
u
y
p
Measurement
Noise
+
+
+
+
z
Measured
Disturbances
Unmeasured
Controller
w
d
scmpc
4-99
ywt
I s a matri x of wei ghts that wi l l be appl i ed to the setpoi nt tracki ng errors
(opti onal ). I f y wt =[ ] , the defaul t i s equal (uni ty) wei ghti ng of al l outputs over
the enti re predi cti on hori zon. I f y wt [ ] , i t must have n
y
col umns, where n
y
i s
the number of outputs. Al l wei ghts must be 0.
You may vary the wei ghts at each step i n the predi cti on hori zon by i ncl udi ng
up to Prows i n y wt . Then the fi rst row of n
y
val ues appl i es to the tracki ng errors
i n the fi rst step i n the predi cti on hori zon, the next row appl i es to the next step,
etc. See s mpccon for detai l s on the form of the opti mi zati on objecti ve functi on.
I f you suppl y onl y nrow rows, where 1 nrow< P, s cmpc wi l l use the l ast row
to fi l l i n any remai ni ng steps. Thus i f you wi sh the wei ghti ng to be the same for
al l P steps, you need onl y speci fy a si ngl e row.
uwt
I s as for y wt , except that uwt appl i es to the changes i n the mani pul ated
vari abl es. I f you use uwt =[ ] , the defaul t i s zero wei ghti ng. I f uwt [ ] , i t must
have n
u
col umns, where n
u
i s the number of mani pul ated vari abl es.
M
There are two ways to speci fy thi s vari abl e:
I f i t i s a scalar, s cmpc i nterprets i t as the i nput hori zon (number of moves) as
i n DMC.
I f i t i s a rowvector contai ni ng n
b
el ements, each el ement of the vector i ndi cates
the number of steps over whi ch u = 0 duri ng the opti mi zati on and s cmpc
i nterprets i t as a set of n
b
bl ocki ng factors. There may be 1 n
b
P bl ocki ng
factors, and thei r sum must be P.
I f you set M=[ ] , the defaul t i s M=P, whi ch i s equi val ent to M=ones ( 1, P) .
P
The number of sampl i ng peri ods i n the predi cti on hori zon.
tend
I s the desi red durati on of the si mul ati on (i n ti me uni ts).
scmpc
1-100
r
I s a setpoi nt matri x consi sti ng of N rows and n
y
col umns, where n
y
i s the
number of output vari abl es, y:
where r
i
(k) i s the setpoi nt for output j at ti me t =kT, and T i s the sampl i ng
peri od (as speci fi ed by the mi nf o vector i n the modformat of pmod and i mod). I f
t end > NT, the setpoi nts vary for the fi rst N peri ods i n the si mul ati on, as
speci fi ed by r , and are then hel d constant at the val ues gi ven i n the l ast row of
r for the remai nder of the si mul ati on.
I n many si mul ati ons one wants the setpoi nts to be constant for the enti re ti me,
i n whi ch case r need onl y contai n a si ngl e row of n
y
val ues.
I f you set r =[ ] , the defaul t i s a row of n
y
zeros.
The fol l owi ng i nput vari abl es are opti onal . I n general , setti ng one of them
equal to an empty matri x causes s cmpc to use the defaul t val ue, whi ch i s gi ven
i n the descri pti on.
r
r
1
1 ( ) r
2
1 ( ) r
n
y
1 ( )
r
1
2 ( ) r
2
2 ( ) r
n
y
2 ( )

r
1
N ( ) r
2
N ( ) r
n
y
N ( )
=

scmpc
4-101
ul i m
I s a matri x gi vi ng the l i mi ts on the mani pul ated vari abl es. I ts format i s as
fol l ows:
Note that i t contai ns three matri ces of N rows. I n thi s case, the l i mi ts on N are
1 N n
b
, where n
b
i s the number of ti mes the mani pul ated vari abl es are to
change over the i nput hori zon. I f you suppl y fewer than n
b
rows, the l ast row
i s repeated automati cal l y.
The fi rst matri x speci fi es the lower bounds on the n
u
mani pul ated vari abl es.
For exampl e, u
min
,
j
(2) i s the l ower bound for mani pul ated vari abl e j for the
second move of the mani pul ated vari abl es (where the fi rst move i s at the start
of the predi cti on hori zon). I f u
min
,
j
(k) = inf, mani pul ated vari abl e j wi l l have
no l ower bound for that move.
The second matri x gi ves the upper bounds on the mani pul ated vari abl es. I f
u
max,j
(k) =inf, mani pul ated vari abl e j wi l l have no upper bound for that move.
The l ower and upper bounds may be ei ther posi ti ve or negati ve (or zer o) as l ong
as u
min
,
j
(k) u
max,j
(k).
, ,
, ,
, ,
,
( )
,
( )
u
max 1 ,
1 ( ) u
max n
u
,
1 ( )
u
max 1 ,
2 ( ) u
max n
u
,
2 ( )

u
max 1 ,
N ( ) u
max n
u
,
N ( )

, ,
, ,
, ,
,
( )
,
( )
ulim
u
mi n 1 ,
1 ( ) u
mi n n
u
,
1 ( )
u
mi n 1 ,
2 ( ) u
mi n n
u
,
2 ( )

u
mi n 1 ,
N ( ) u
mi n n
u
,
N ( )
=
u
max 1 ,
1 ( ) u
max n
u
,
1 ( )
u
max 1 ,
2 ( ) u
max n
u
,
2 ( )

u
max 1 ,
N ( ) u
max n
u
,
N ( )


scmpc
1-102
The thi rd matri x gi ves the l i mi ts on the rate of change of the mani pul ated
vari abl es. I n other words, cmpc wi l l force| u
j
(k) u
j
(k 1)| u
max,j
(k). The
l i mi ts on the rate of change must be nonnegati ve and finite. I f you want i t to be
unbounded, set the bound to a l arge number (but not too l arge a val ue of 10
6
shoul d work wel l i n most cases).
The defaul t i s u
min
= inf, u
max
=inf and u
max
= 10
6
yl i m
Same format as for ul i m, but for the l ower and upper bounds of the outputs.
The fi rst row appl i es to the fi rst poi nt i n the predi cti on hori zon. The defaul t i s
y
min
= inf, and y
max
=inf.
Kest
I s the esti mator gai n matri x. The defaul t i s the DMC esti mator. See s mpces t
for more detai l s.
z
I s measurement noi se that wi l l be added to the outputs (see above di agram).
The format i s the same as for r . The defaul t i s a row of n
y
zeros.
d
I s a matri x of measured di sturbances (see above di agram). The format i s the
same as for r , except that the number of col umns i s n
d
rather than n
y
. The
defaul t i s a row of n
d
zeros.s
w
I s a matri x of unmeasured di sturbances (see above di agram). The format i s the
same as for r , except that the number of col umns i s n
w
rather than n
y
.The
defaul t i s a row of n
w
zeros.
wu
I s a matri x of unmeasured di sturbances that are added to the mani pul ated
vari abl es (see above di agram). The format i s the same as for r , except that the
number of col umns i s n
u
rather than n
y
. The defaul t i s a row of n
u
zeros.
Notes You may use a di fferent number of rows i n the matri ces r , z , d, w and wu,
shoul d that be appropri ate for your si mul ati on.
scmpc
4-103
The ul i mconstrai nts used here are fundamental l y di fferent from the us at
constrai nts used i n the s mpcs i mfuncti on. The ul i mconstrai nts are defi ned
rel ati ve to the begi nni ng of the predi cti on hori zon, whi ch moves as the
si mul ati on progresses. Thus at each sampl i ng peri od, k, the ul i mconstrai nts
appl y to a bl ock of cal cul ated moves that begi n at sampl i ng peri od k and
extend for the durati on of the i nput hori zon. The us at constrai nts, on the
other hand, are rel ati ve to the fi xed poi nt t = 0, the start of the si mul ati on.
The cal cul ated outputs are as fol l ows (al l but y p are opti onal ):
yp
I s a matri x contai ni ng M rows and n
y
col umns, where M = max(fix(tend/T) + 1,
2). The fi rst row wi l l contai n the i ni ti al condi ti on, and row k 1 wi l l gi ve the
val ues of the noi se-free pl ant outputs, (see above di agram), at ti me t =kT.
u
I s a matri x contai ni ng the same number of rows as y p and n
u
col umns. The ti me
correspondi ng to each row i s the same as for y p. The el ements i n each row are
the val ues of the mani pul ated vari abl es, u (see above di agram).
Note The u val ues are those comi ng from the control l er before the addi ti on of
the unmeasured di sturbance, w
u
.
ym
I s a matri x of the same structure as y p, contai ni ng the val ues of the predi cted
output from the state esti mator i n the control l er. These wi l l , i n general , di ffer
from those i n y p i f i mod pmod and/or there are unmeasured di sturbances. The
prediction includes theeffect of themost recent measurement, i.e., i t i s .
For unconstrai ned probl ems, s cmpc and s mpcs i mshoul d gi ve the same resul ts.
The l atter wi l l be faster because i t uses an anal yti cal sol uti on of the QP
probl em, whereas s cmpc sol ves i t by i terati on.
y
p
y k k ( )
scmpc
1-104
Examples Consi der the l i near system:
The fol l owi ng statements bui l d the model and set up the control l er i n the same
way as i n the s mpcs i mexampl e.
g11=pol y 2t f d( 12. 8, [ 16. 7 1] , 0, 1) ;
g21=pol y 2t f d( 6. 6, [ 10. 9 1] , 0, 7) ;
g12=pol y 2t f d( - 18. 9, [ 21. 0 1] , 0, 3) ;
g22=pol y 2t f d( - 19. 4, [ 14. 4 1] , 0, 3) ;
del t =3; ny =2;
i mod=t f d2mod( del t , ny , g11, g21, g12, g22) ;
pmod=i mod; P=6; M=2; y wt =[ ] ; uwt =[ 1 1] ;
t end=30; r =[ 0 1] ;
Here, however, we wi l l demonstrate the effect of constrai nts. Fi rst we set a
l i mi t of 0.1 on the rate of change of u
1
and a mi ni mum of 0.15 for u
2
.
ul i m=[ - i nf - 0. 15 i nf i nf 0. 1 100] ;
y l i m=[ ] ;
[ y , u] =s cmpc( pmod, i mod, y wt , uwt , M, P, t end, r , ul i m, y l i m) ;
pl ot al l ( y , u, del t ) , paus e
y
1
s ( )
y
2
s ( )
12.8e
s
16.7s 1 +
------------------------
18.9e
3s
21.0s 1 +
-------------------------
6.6e
7s
10.9s 1 +
------------------------
19.4e
3s
14.4s 1 +
-------------------------
u
1
s ( )
u
2
s ( )
=
scmpc
4-105
Note that u
2
has a l arge (but fi ni te) l i mi t. I t never comes i nto pl ay.
We next appl y a l ower bound of zero to both outputs:
ul i m=[ -inf - 0. 15 i nf i nf 0. 1 100] ;
y l i m=[ 0 0 i nf i nf ] ;
[ y , u] =s cmpc( pmod, i mod, y wt , uwt , M, P, t end, r , ul i m, y l i m) ;
pl ot al l ( y , u, de l t ) ,
paus e
The fol l owi ng resul ts show that no constrai nts are vi ol ated.
0 5 10 15 20 25 30
0.2
0
0.2
0.4
0.6
0.8
1
1.2
Outputs
Time
0 5 10 15 20 25 30
0.2
0.18
0.16
0.14
0.12
0.1
0.08
0.06
Manipulated Variables
Time
scmpc
1-106
Restrictions I ni ti al condi ti ons of zero are used for al l states i n i mod and pmod. Thi s
si mul ates the condi ti on where al l vari abl es represent a devi ati on from a
steady-state i ni ti al condi ti on.
The fi rst n
u
+ n
d
col umns of the D matri ces i n i mod and pmod must be zero.
I n other words, nei ther u nor d may have an i mmedi ate effect on the outputs.
Suggestions Probl ems wi th many i nequal i ty constrai nts can be very ti me consumi ng. You
can mi ni mi ze the number of constrai nts by:
Usi ng smal l val ues for P and/or M.
Leavi ng vari abl es unconstrai ned (l i mi ts at inf) i ntermi ttentl y unl ess you
thi nk the constrai nt i s i mportant.
See Also pl ot al l , pl ot each, s mpc cl , s mpccon, s mpces t , s mpcs i m
0 5 10 15 20 25 30
0.2
0
0.2
0.4
0.6
0.8
1
1.2
Outputs
Time
0 5 10 15 20 25 30
0.2
0.1
0
Manipulated Variables
Time
sermod
4-107
1ser mod
Purpose Puts two model s i n seri es by connecti ng the output of one to the i nput of the
other. Mi mi cs the s er i es functi on of the Control System Tool box, except that
s er mod works on model s i n the MPC mod format.
Syntax pmod = s er mod( mod1, mod2)
Description
mod1 and mod2 are model s i n the MPC mod format (see mod i n the onl i ne
MATLAB Function Referencefor a detai l ed descri pti on). You woul d normal l y
create them usi ng ei ther the t f d2mod, s s 2mod or t h2mod functi ons.
s er mod combi nes them to form a composi te system, pmod, as shown i n the above
di agram. I t i s al so i n the mod format. Note how the i nputs to mod1 and mod2
are ordered i n pmod.
Restrictions mod1 and mod2 must have been created wi th equal sampl i ng peri ods.
The number of measured outputs i n mod1 must equal the number of
mani pul ated vari abl es i n mod2.
See Also addmd, addmod, addumd, appmod, par amod
mod2
pmod
y
1
= u
2
u
1
y
mod1
u
2
d
1
d
2
w
1
w
2
u
1
d
1
d
2
w
1
w
2
y
smpccl
1-108
1smpccl
Purpose Combi nes a pl ant model and a control l er model i n the MPC mod format,
yi el di ng a cl osed-l oop system model i n the MPC format. Thi s can be used for
stabi l i ty anal ysi s and l i near si mul ati ons of cl osed-l oop performance.
Syntax [ cl mod, cmod] = s mpccl ( pmod, i mod, Ks )
[ cl mod, cmod] = s mpccl ( pmod, i mod, Ks , Kes t )
Description
pmod
I s a model (i n the mod format) representi ng the pl ant i n the above di agram.
i mod
I s a model (i n the same format) that i s to be used to desi gn the MPC control l er
bl ock shown i n the di agram. I t may be the same as pmod (i n whi ch case there i s
no model error i n the control l er desi gn), or i t may be di ffer ent.
Ks
I s a control l er gai n matri x, whi ch must have been cal cul ated by the functi on
s mpccon.
Disturbances
u
d
r Plant
Setpoints
Noise-free
d
y
Plant
Outputs

Measured
Outputs

w
u
y
p
Measurement
Noise
+
+
+
+
z
Measured
Disturbances
Unmeasured
Controller
w
d
smpccl
4-109
Kest
I s an (opti onal ) esti mator gai n matri x. I f omi tted or set to an empty matri x, the
defaul t i s to use the DMC estimator i ndex DMC esti mator. See the
documentati on for the functi on s mpces t for more detai l s on the desi gn and
proper format of Kes t .
smpccl
Cal cul ates a model of the cl osed-l oop system, cl mod. I t i s i n the modformat and
can be used, for exampl e, wi th anal ysi s functi ons such as s mpcgai n and
s mpcpol e, and wi th si mul ati on routi nes such as mod2s t ep and dl s i mm. s mpccl
al so cal cul ates a model of the control l er el ement, cmod.
The cl osed-l oop model , cl mod, has the fol l owi ng state-space representati on:
x
cl
(k + 1) =
cl
x
cl
(k) +
cl
u
cl
(k)
y
cl
(k) = C
cl
x
cl
(k) + D
cl
u
cl
(k)
where x
cl
i s a vector of n state vari abl es, u
cl
i s a vector of i nput vari abl es, y
cl
i s
a vector of outputs, and
cl
,
cl
, C
cl
, and D
cl
are matri ces of appropri ate si ze.
The expert user may want to know the si gni fi cance of the state vari abl es i n x
cl
.
They are (i n the fol l owi ng order):
The n
p
states of the pl ant (as speci fi ed i n pmod),
The n
i
changes i n the state esti mates (based on the model speci fi ed i n i mod
and the esti mator gai n, Kes t ),
The n
y
esti mates of the noise-freepl ant output (from the state
esti mator),
n
u
i ntegrators that operate on the u si gnal produced by the standard MPC
formul ati on to yi el d a u si gnal that can be used as i nput to the pl ant and as
a cl osed-l oop output, and
n
d
di fferenci ng el ements that operate on the dsi gnal to produce the dsi gnal
requi red i n the standard MPC formul ati on. I f there are no measured
di sturbances, these states are omi tted.
y k k 1 ( ) =
smpccl
1-110
The cl osed-l oop i nput and output vari abl es are:
where i s the esti mate of the noi se-free pl ant output at sampl i ng
peri od k based on i nformati on avai l abl e at peri od k. Thi s esti mate i s generated
by the control l er el ement.
Note that u
cl
wi l l i ncl ude d and/or wautomati cal l y whenever pmod i ncl udes
measured di sturbances and/or unmeasured di sturbances. Thus the l ength of
the u
cl
vector wi l l depend on the i nputs you have defi ned i n pmod and i mod.
Si mi l arl y, y cl depends on the number of outputs and mani pul ated vari abl es.
Let mand p be the l engths of u
cl
and y
cl
, respecti vel y. Then
m=2n
y
+n
u
+n
d
+n
w
p =2n
y
+n
u
The state-space form of the control l er model , cmod, can be wri tten as:
x
c
(k + 1) =
c
x
c
(k) +
cl
u
c
(k)
y
c
(k) = C
c
x
c
(k) + D
c
u
c
(k)
where
and the control l er states are the same as those of the cl osed l oop system except
that the n
p
pl ant states are not i ncl uded.
u
cl
k ( )
r k ( )
z k ( )
w
u
k ( )
d k ( )
w k ( )
and y
cl
k ( )
y
p
k ( )
u k ( )
y k k ( )
= =
y k k ( ) =
u
c
k ( )
r k ( )
y k ( )
d k ( )
and y
c
k ( ) u k ( ) = =
smpccl
4-111
Examples Consi der the l i near system:
We bui l d thi s model usi ng the MPC Tool box functi ons pol y 2t f d and t f d2mod.
g11=pol y 2t f d( 12. 8, [ 16. 7 1] , 0, 1) ;
g21=pol y 2t f d( 6. 6, [ 10. 9 1] , 0, 7) ;
g12=pol y 2t f d( - 18. 9, [ 21. 0 1] , 0, 3) ;
g22=pol y 2t f d( - 19. 4, [ 14. 4 1] , 0, 3) ;
del t =3; ny =2;
i mod=t f d2mod( del t , ny , g11, g21, g12, g22) ;
pmod=i mod; % No pl ant /model mi s mat ch
Now we desi gn the control l er. Si nce there i s del ay, we use M < P: We speci fy
the defaul ts for the other tuni ng parameters, uwt and y wt , then cal cul ate the
control l er gai n:
P=6; % Pr edi ct i on hor i z on.
M=2; % Number of mov es ( i nput hor i z on) .
y wt =[ ] ; % Out put wei ght s ( def aul t - uni t y on
% al l out put s ) .
uwt =[ ] ; % Man. Var wei ght s ( def aul t - z er o on
% al l man. v ar s ) .
Ks =s mpccon( i mod, y wt , uwt , M, P) ;
Now we can cal cul ate the model of the cl osed-l oop system and check i ts pol es
for stabi l i ty:
cl mod=s mpccl ( pmod, i mod, Ks ) ;
max pol e=max ( abs ( s mpcpol e ( cl mod) ) )
The resul t i s:
max pol e = 0. 8869
Si nce thi s i s l ess than 1, the pl ant and control l er combi nati on wi l l be
cl osed-l oop stabl e. (The cl osed-l oop system has 20 states i n thi s exampl e).
y
1
s ( )
y
2
s ( )
12.8e
s
16.7s 1 +
------------------------
18.9e
3s
21.0s 1 +
-------------------------
6.6e
7s
10.9s 1 +
------------------------
19.4e
3s
14.4s 1 +
-------------------------
u
1
s ( )
u
2
s ( )
=
smpccl
1-112
You can al so use the cl osed-l oop model to cal cul ate and pl ot the step response
wi th respect to all the i nputs. The appropri ate commands are:
t end=30;
c l s t ep=mod2s t ep( cl mod, t end) ;
pl ot s t ep( cl s t ep)
Si nce the cl osed-l oop system has m=6 i nputs and p=6 outputs, onl y one of the
pl ots i s reproduced here. I t shows the response of the fi rst 4 cl osed-l oop outputs
to a step i n the fi rst cl osed-l oop i nput, whi ch i s the setpoi nt for y
1
:
Cl osed-l oop outputs y
1
and y
2
are the true pl ant outputs (noi se-free). Output y
1
goes to the new setpoi nt qui ckl y wi th a smal l overshoot. Thi s causes a smal l ,
short-term di sturbance i n y
2
. The pl ots for y
3
and y
4
show the requi red
vari ati on i n the mani pul ated vari abl es.
0 10 20 30
0
0.2
0.4
0.6
0.8
1
1.2
1.4
u1 step response : y1
TIME
0 10 20 30
0.2
0.15
0.1
0.05
0
u1 step response : y2
TIME
0 10 20 30
0
0.05
0.1
0.15
0.2
0.25
u1 step response : y3
TIME
0 10 20 30
0
0.02
0.04
0.06
0.08
0.1
0.12
u1 step response : y4
TIME
smpccl
4-113
The fol l owi ng commands show how you coul d use dl s i mmto cal cul ate the
response of the cl osed-l oop system to a step i n the setpoi nt for y
1
, wi th added
random measurement noi se.
r =[ ones ( 11, 1) z er os ( 11, 1) ] ;
z =0. 1*r and( 11, 2) ;
wu=z er os ( 11, 2) ;
d=[ ] ;
w=[ ] ;
ucl =[ r z wu d w] ;
[ phi cl , gamcl , c cl , dcl ] =mod2s s ( cl mods ) ;
y cl =dl s i mm( phi cl , gamcl , cc l , dcl , ucl ) ;
y =y cl ( : , 1: 2) ; u=y cl ( : , 3: 4) ; y m=y cl ( : , 5: 6) ;
Restrictions i mod and pmod must have been created usi ng the same sampl i ng peri od, and
an equal number of outputs, measured di sturbances, and mani pul ated
vari abl es.
Both i mod and pmod must be stri ctl y proper, i .e., the D matri ces i n thei r
state-space descri pti ons must be zero. Exception: the l ast n
w
col umns of the
D matri ces may be nonzero, i .e., the unmeasured di sturbance may have an
i mmedi ate effect on the outputs.
See Also mod2s t ep, s cmpc , s mpccon, s mpces t , s mpcgai n, s mpcpol e , s mpcs i m
smpccon
1-114
1smpccon
Purpose Cal cul ates MPC control l er gai n usi ng a model i n MPC mod format.
Syntax Ks = s mpccon( i mod)
Ks = s mpccon( i mod, y wt , uwt , M, P)
Description Combi nes the fol l owi ng vari abl es (most of whi ch are opti onal and have defaul t
val ues) to cal cul ate the state-space MPC gai n matri x, Ks .
i mod i s the model of the process to be used i n the control l er desi gn (i n the
mod format).
The fol l owi ng i nput vari abl es are opti onal :
ywt
I s a matri x of wei ghts that wi l l be appl i ed to the setpoi nt tracki ng errors. I f you
use y wt =[ ] or omi t i t, the defaul t i s equal (uni ty) wei ghti ng of al l outputs over
the enti re predi cti on hori zon. I f y wt [ ] , i t must have n
y
col umns, where n
y
i s
the number of outputs. Al l wei ghts must be 0.
You may vary the wei ghts at each step i n the predi cti on hori zon by i ncl udi ng
up to Prows i n y wt . Then the fi rst row of n
y
val ues appl i es to the tracki ng errors
i n the fi rst step i n the predi cti on hori zon, the next row appl i es to the next step,
etc.
I f you suppl y onl y nrowrows, where 1 nrow< P, s mpcc on wi l l use the l ast row
to fi l l i n any remai ni ng steps. Thus i f you wi sh the wei ghti ng to be the same for
al l P steps, you need onl y speci fy a si ngl e row.
uwt
Same for mat as y wt , except that uwt appl i es to the changes i n the
mani pul ated var i abl es. I f you use uwt =[ ] or omi t i t, the defaul t i s zer o
wei ghti ng. I f uwt [ ] , i t must have n
u
col umns, wher e n
u
i s the number of
mani pul ated var i abl es.
M
There are two ways to speci fy thi s vari abl e:
I f i t i s a scalar, s mpccon i nterprets i t as the i nput hori zon (number of moves) as
i n DMC.
smpccon
4-115
I f i t i s a rowvector contai ni ng n
b
el ements, each el ement of the vector i ndi cates
the number of steps over whi ch u = 0 duri ng the opti mi zati on and s mpccon
i nterprets i t as a set of n
b
bl ocki ng factors. There may be 1 n
b
P bl ocki ng
factors, and thei r sum must be P.
I f you set M=[ ] or omi t i t, the defaul t i s M=P, whi ch i s equi val ent to
M=one s ( 1, P) .
P
The number of sampl i ng peri ods i n the predi cti on hori zon. I f you set P=[ ] or
omi t i t, the defaul t i s P=1.
I f you take the defaul t val ues for al l the opti onal vari abl es, you get the perfect
control l er, i .e., a model -i nverse control l er. Thi s control l er i s not appl i cabl e i n
the fol l owi ng si tuati ons:
When one or more outputs cannot respond to the mani pul ated vari abl es
wi thi n 1 sampl i ng peri od due to ti me del ay, the pl ant-i nverse control l er i s
unreal i zabl e. To counteract thi s you can penal i ze changes i n the
mani pul ated vari abl es (vari abl e uwt ), use bl ocki ng (vari abl e M), and/or make
P>>M.
When i mod contai ns transmi ssi on zeros outsi de the uni t ci rcl e the
pl ant-i nverse control l er wi l l be unstabl e. To counteract thi s, you can use
bl ocki ng (vari abl e M), restri ct the i nput hori zon (vari abl e M), and/or penal i ze
changes i n the mani pul ated vari abl es (vari abl e uwt ).
The model -i nverse control l er i s al so rel ati vel y sensi ti ve to model error and i s
best used as a poi nt of reference from whi ch you can progress to a more robust
desi gn.
Algorithm The control l er gai n i s a component of the sol uti on to the opti mi zati on probl em:
Mi ni mi ze
wi th respect to (a seri es of current and future moves i n the mani pul ated
vari abl es), where (k + j) i s a predi cti on of output i at a ti me j sampl i ng
peri ods i nto the future (rel ati ve to the current ti me, k), whi ch i s a functi on of
J k ( ) ywt
i
j ( ) r
i
k j + ( ) y
i
k j + ( ) [ ] ( )
2
i 1 =
n
y

j 1 =
p

=
uwt
i
j ( )u
i
j ( ) ( )
2
i 1 =
n
u

j 1 =
n
b

+
u
i
j ( )
y
i
smpccon
1-116
(j), r
i
(k + j) i s the correspondi ng future setpoi nt, and n
b
i s the number of
bl ocks or moves of the mani pul ated vari abl es.
References Ri cker, N. L. Use of Quadrati c Programmi ng for Constrai ned I nternal Model
Control , I nd. Eng. Chem. Process Des. Dev., 1985, 24, 925936.
Ri cker, N. L. Model -predi cti ve control wi th state esti mati on, I & EC Res.,
1990, 29, 374.
Example Consi der the l i near system:
See the s mpccl exampl e for the commands that bui l d the model and a si mpl e
control l er for thi s process.
Here i s a sl i ghtl y more compl ex desi gn wi th bl ocki ng and ti me-varyi ng wei ghts
on the mani pul ated and output vari abl es:
P=6; M=[ 2 4] ;
uwt =[ 1 0; 0 1] ;
y wt =[ 1 0. 1; 0. 8 0. 1; 0. 1 0. 1] ;
Ks =s mpccon( i mod, y wt , uwt , M, P) ;
t end=30; r =[ 1 0] ;
[ y , u] =s mpcs i m( pmod, i mod, Ks , t end, r ) ;
There i s no parti cul ar rati onal e for usi ng ti me varyi ng wei ghts i n thi s case
i t i s onl y for i l l ustrati on. The mani pul ated vari abl es wi l l make 2 moves duri ng
the predi cti on hori zon (see val ue of M, above). The uwt sel ecti on gi ves u
1
a uni ty
wei ght and u
2
a zero wei ght for the fi rst move, then swi tches the wei ghts for
the second move. I f there had been any addi ti onal moves they woul d have had
the same wei ghti ng as the second move.
u
i
y
1
s ( )
y
2
s ( )
12.8e
s
16.7s 1 +
------------------------
18.9e
3s
21.0s 1 +
-------------------------
6.6e
7s
10.9s 1 +
------------------------
19.4e
3s
14.4s 1 +
-------------------------
u
1
s ( )
u
2
s ( )
=
smpccon
4-117
The y wt val ue assi gns a constant wei ght of 0.1 to y
2
, and a wei ght that
decreases over the fi rst 3 peri ods to y
1
. The wei ghts for peri ods 4 to 6 are the
same as for peri od 3. The resul ti ng cl osed-l oop (servo) response i s:
See Also s cmpc , s mpccl , s mpcs i m
0 5 10 15 20 25 30
1
0.5
0
0.5
1
Outputs
Time
0 5 10 15 20 25 30
0
0.1
0.2
0.3
0.4
0.5
Manipulated Variables
Time
smpcest
1-118
1smpcest
Purpose Sets up a state-esti mator gai n matri x for use wi th MPC control l er desi gn and
si mul ati on routi nes usi ng model s i n MPC mod format. Can use ei ther a
di sturbance/noi se model that you speci fy, or a si mpl i fi ed form i n whi ch each
output i s affected by an i ndependent di sturbance (pl us measurement noi se).
Syntax For thegeneral case:
[ Kes t ] = s mpces t ( i mod, Q, R)
For simplified disturbancemodeling:
[ Ke s t , newmod] = s mpces t ( i mod)
[ Ke s t , newmod] = s mpces t ( i mod, t au, s i gnoi s e)
Description
I n the above bl ock di agram, u i s a vector of n
u
mani pul ated vari abl es (n
u
1),
d i s a vector of n
d
measured di sturbances (n
d
0), wi s a vector of unmeasured
di sturbances, zi s measurement noi se, yi s a vector of outputs, and represents
these outputs before the addi ti on of measurement noi se. The objecti ve of the
state esti mator i n MPC i s to esti mate the present and future val ues of ,
rejecti ng as much of the measurement noi se as possi bl e. The i nputs uand d are
assumed perfectl y measurabl e, whereas wand z are unknown and must be
i nferred from the measurements. G
w
i s a transfer functi on matri x representi ng
the effect of each el ement of won each output i n y.
General Case i mod
I s the model (i n mod format) to be used as the basi s for the state esti mator. I t
shoul d be the same as that used to cal cul ate the control l er gai n (see s mpccon).
I t must includea model of thedisturbances, i .e., the G
w
el ement i n the above
y
u
+
G
w
Plant
z
y
w

+
+
+
d
y
y
smpcest
4-119
di agram. You coul d, for exampl e, use addumd to combi ne a pl ant and
di sturbance model , yi el di ng a composi te model i n the proper form.
Q
I s a symmetri c, posi ti ve semi -defi ni te matri x gi vi ng the covari ances of the
di sturbances i n w. I t must be n
w
by n
w
, where n
w
( 1) i s the number of
unmeasured di sturbances i n i mod (i .e., the l ength of w).
R
I s a symmetri c, posi ti ve-defi ni te matri x gi vi ng the covari ances of the
measurement noi se, z. I t must be n
ym
by n
ym
, where n
ym
( 1) i s the number of
measured outputs i n i mod.
The cal cul ated output vari abl e i s:
Kest
The esti mator gai n matri x. I t wi l l contai n n + n
y
rows and n
ym
col umns, where
n i s the number of states i n i mod, and n
y
i s the total number of outputs
(measured pl us unmeasured).
Simplified
disturbance
modeling
For the simplified disturbance/ noisemodel we make the fol l owi ng
assumpti ons:
The vectors w, z, y and are al l l ength n
y
.
G
w
i s di agonal . Thus each el ement of waffects one (and onl y one) el ement of
y. Di agonal el ement G
wi
has the di screte (sampl ed-data) form:
where a
i
= e
T/

i
, 0
i
, and T i s the sampl i ng peri od.
As , Gwi(q) approaches a uni ty gai n, whi l e as , G
wi
becomes an
i ntegrator.
El ement i of wi s a stati onary whi te-noi se si gnal wi th zero mean and
standard devi ati on
wi
(where w
i
(k) = w
i
(k) w
i
(k 1)).
El ement i of zi s a stati onary whi te-noi se si gnal wi th zero mean and standard
devi ati on
zi
.
y
G
wi
q ( )
1
q a
i

-------------- =

i
0
i

smpcest
1-120
The i nput vari abl es are then as fol l ows:
i mod
I s the model (i n mod format) to be used as the basi s for the state esti mator. I t
shoul d be the same as that used to cal cul ate the control l er gai n (see s mpccon).
tau
I s a rowvector, l ength n
y
, gi vi ng the val ues of
i
to be used i n eq. 1. Each el ement
must sati sfy: 0
i
. I f you use tau=[ ] , s mpces t uses the defaul t, whi ch i s
n
y
zeros.
si gnoi se
I s a rowvector, l ength n
y
, gi vi ng the si gnal -to-noi se rati o for the each
di sturbance, defi ned as
i
=
wi
=
zi
. Each el ement must be nonnegati ve. I f
omi tted, s mpcs i muses an i nfi ni te si gnal -to-noi se rati o for each output.
The cal cul ated output vari abl es are:
Kest
The esti mator gai n matri x.
newmod
The modi fi ed versi on of i mod, whi ch must be used i n pl ace of i mod i n any
si mul ati on/anal ysi s functi ons that requi re Kes t (e.g., s mpc cl , s mpcs i m, s cmpc ).
I f i mod contai ns n states, and there are n
1
outputs for whi ch
i
> 0, then
newmod wi l l have n + n
1
states. The opti mal gai n matri x, Kes t , wi l l have n +
n
1
+ n
y
rows and n
ym
col umns. The fi rst n rows wi l l be zero, the next n
1
rows
wi l l have the gai ns for the esti mates of the n
1
added states (i f any), and the l ast
n
y
rows wi l l have the gai ns for esti mati ng the noi se-free outputs, .
Examples Consi der the l i near system:
y
y
1
s ( )
y
2
s ( )
12.8e
s
16.7s 1 +
------------------------
18.9e
3s
21.0s 1 +
-------------------------
6.6e
7s
10.9s 1 +
------------------------
19.4e
3s
14.4s 1 +
-------------------------
u
1
s ( )
u
2
s ( )
3.8e
8 s
14.9s 1 +
------------------------
4.9e
3s
13.2s 1 +
------------------------
w s ( ) + =
smpcest
4-121
The fol l owi ng statements bui l d two model s: pmod, whi ch contai ns the model of
the di sturbance, w, and i mod, whi ch does not.
g11=pol y 2t f d( 12. 8, [ 16. 7 1] , 0, 1) ;
g21=pol y 2t f d( 6. 6, [ 10. 9 1] , 0, 7) ;
g12=pol y 2t f d( - 18. 9, [ 21. 0 1] , 0, 3) ;
g22=pol y 2t f d( - 19. 4, [ 14. 4 1] , 0, 3) ;
del t =1; ny =2;
i mod=t f d2mod( del t , ny , g11, g21, g12, g22) ;
gw1=pol y 2t f d( 3. 8, [ 14. 9 1] , 0, 8) ;
gw2=pol y 2t f d( 4. 9, [ 13. 2 1] , 0, 3) ;
pmod=addumd( i mod, t f d2mod( del t , ny , gw1, gw2) ) ;
Cal cul ate the gai n for a typi cal MPC (unconstrai ned) control l er
P=6; M=2;
y wt =[ ] ; uwt =[ 1 1] ;
Ks =s mpccon( i mod, y wt , uwt , M, P) ;
Next desi gn an esti mator usi ng the G
w
model i n pmod. The choi ces of Q and R
are arbi trary. R was made rel ati vel y smal l (si nce measurement noi se wi l l be
negl i gi bl e i n the si mul ati ons).
Kes t 1=s mpces t ( pmod, 1, 0. 001*ey e( ny ) ) ;
Ks 1=s mpccon( pmod, y wt , uwt , M, P) ;
Now desi gn another esti mator usi ng a si mpl i fi ed di sturbance model i n whi ch
each output i s affected by a di sturbance wi th a fi rst-order ti me constant of 10
and a si gnal -to-noi se rati o of 3.
t au=[ 10 10] ; s i gnoi s e=[ 3 3] ;
[ Ke s t 2, newmod] =s mpces t ( i mod, t au, s i gnoi s e) ;
Ks 2=s mpccon( ne wmod, y wt , uwt , M, P) ;
Compare the performance of these two esti mators to the defaul t (DMC)
esti mator when there i s a uni t step i n w:
r =[ ] ; ul i m=[ ] ; z =[ ] ; d=[ ] ; w=[ 1] ; wu=[ ] ; t e nd=30;
[ y
1
, u
1
] =s mpcs i m( pmod, pmod, Ks 1, t end, r , ul i m, Kes t 1, z , d, w, wu) ;
[ y
2
, u
2
] =s mpcs i m( pmod, newmod, Ks 2, t end, r , ul i m, Kes t 2, z , d, w, wu) ;
[ y
3
, u3] =s mpcs i m( pmod, i mod, Ks , t e nd, r , ul i m, [ ] , z , d, w, wu) ;
smpcest
1-122
The sol i d l i nes i n the fol l owi ng pl ots are for y
1
(or u
1
) and the dashed l i nes are
for y
2
(or u
2
). Both outputs have setpoi nts at zero. You can see that the defaul t
esti mator i s much more sl uggi sh than the others i n counteracti ng thi s type of
di sturbance. The si mpl i fi ed di sturbance desi gn does nearl y as wel l as that
usi ng the exact model of the di sturbances. The mai n di fference i s that i t al l ows
more error i n y
1
fol l owi ng the di sturbance i n y
2
.
The fi rst 14 states i n both i mod and pmod are for the response of the outputs to
u. Si nce the unmeasured di sturbance has no effect on them, thei r gai ns are
2
1
0
-1
0 10 20 30
Time
Outputs using general estimator
2
1
0
-1
0 10 20 30
Time
Outputs using simplified estimator
2
1
0
-1
0 10 20 30
Time
Outputs using default estimator
1
0.5
0
0 10 20 30
Time
Man.vars. using general estimator
smpcest
4-123
zero. pmod contai ns 10 addi ti onal di sturbance states and there are 2 outputs,
so the l ast 12 rows of Kes t 1 are nonzero:
Kes t 1( 15: 26, : ) =
- 0. 0556 8. 8659
- 0. 0594 7. 1499
- 0. 0635 5. 1314
- 0. 0679 2. 7748
- 0. 0725 0. 0411
- 0. 0781 - 0. 0182
- 0. 0915 - 0. 0008
- 0. 0520 0. 0001
1. 2663 0. 0000
0. 0281 - 0. 0000
0. 3137 0. 0000
0. 0000 0. 9925
and the l ast 4 rows of Kes t 2 are nonzero:
Kes t 2( 15: 18, : ) =
0. 7274 0
0 0. 7274
0. 9261 0
0 0. 9261
Algorithm I n the general case, s mpces t uses dl qe2 to cal cul ate the opti mal esti mator
gai n, Kes t . I n the si mpl i fi ed case, i t uses an anal yti cal sol uti on of the di screte
Ri ccati equati on (whi ch i s possi bl e to obtai n i n thi s case because the
di sturbances are i ndependent wi th l ow-order dynami cs).
The number of rows i n Kes t i s l arger than that i n newmod because the MPC
anal ysi s and si mul ati on functi ons augment the model states wi th the outputs
(see mpcaugs s ), and Kes t must be set up to account for thi s.
I f al l
i
= 0 and al l
i
= , we get the DMC estimator, whi ch has n rows of zeros
fol l owed by an i denti ty matri x of di mensi on n
y
. Thi s i s the defaul t for al l of the
MPC anal ysi s and si mul ati on routi nes that requi re an esti mator gai n as i nput.
smpcest
1-124
Important note: s mpces t deci des whether you are usi ng the general case or
the si mpl i fi ed approach by checki ng the number of output arguments you
have suppl i ed. I f there i s onl y one, i t assumes you want the general case.
Otherwi se, i t proceeds as for the si mpl i fi ed case. I t checks the di mensi ons of
your i nput arguments to make sure they are consi stent wi th thi s deci si on.
I f you get unexpected r esul ts or an er r or message, make sur e you have speci fi ed
the correct number of output arguments.
See Also s c mpc, s mpcc l , s mpccon, s mpcs i m
smpcgain, smpcpole
4-125
1smpcgai n, smpcpol e
Purpose Cal cul ates steady-state gai n matri x or pol es for a system i n the MPC mod
format.
Syntax g = s mpcgai n( mod)
pol es = s mpcpol e ( mod)
Description mod i s a dynami c model i n the MPC mod format. s mpcgai n and s mpcpol e
convert i t to i ts equi val ent state-space form:
x(k + 1) = x(k) + v (k)
y(k) = Cx(k) + Dv(k)
where i ncl udes al l of the i nputs i n mod. s mpc gai n then cal cul ates the gai n
matri x:
G = C(I )
1
+ D
whi ch contai ns n
y
rows, correspondi ng to each of the outputs i n mod, and n
u
+
n
d
+ n
w
col umns, correspondi ng to each of the i nputs.
s mpcpol e cal cul ates the pol es, i .e., the ei genval ues of the matri x.
Example See s mpccl for an exampl e of the use of s mpcpol e.
Restriction I f mod i s not asymptoti cal l y stabl e, s mpcgai n termi nates wi th an error message.
See Also mod
smpcsim
1-126
1smpcsi m
Purpose Si mul ates cl osed-l oop systems wi th saturation constraints on the mani pul ated
vari abl es usi ng model s i n the MPC modformat. Can al so be used for open-l oop
si mul ati ons.
Syntax y p = s mpcs i m( pmod, i mod, Ks , t end, r )
[ y p, u, y m] = s mpcs i m( pmod, i mod, Ks , t end, r , us at , . . .
Kes t , z , d, w, wu)
Description
s mpcs i mprovi des a conveni ent way to si mul ate the performance of the type of
system shown i n the above di agram. The requi red i nput vari abl es are as
fol l ows:
pmod
I s a model i n the MPC mod format that i s to represent the pl ant.
i mod
I s a model i n the MPC modformat that i s to be used for state esti mati on i n the
control l er. I n general , i t can be di fferent from pmod i f you wi sh to si mul ate the
effect of pl ant/control l er model mi smatch. Note, however, that i mod shoul d be
the same as that used to cal cul ate Ks .
Disturbances
u
d
r Plant
Setpoints
Noise-free
d
y
Plant
Outputs

Measured
Outputs

w
u
y
p
Measurement
Noise
+
+
+
+
z
Measured
Disturbances
Unmeasured
Controller
w
d
smpcsim
4-127
Ks
I s the MPC control l er gai n matri x, usual l y cal cul ated usi ng the functi on
s mpcc on.
I f you set Ks to an empty matri x, s mpcs i mwi l l do an open-l oop si mul ati on. Then
the i nputs to the pl ant wi l l be r (whi ch must be set to the vector of mani pul ated
vari abl es i n thi s case), d, w, and wu. The measurement noi se i nput, z , wi l l be
i gnored.
tend
I s the desi red durati on of the si mul ati on (i n ti me uni ts).
r
I s normallya setpoi nt matri x consi sti ng of N rows and n
y
col umns, where n
y
i s
the number of output vari abl es, y:
where r
i
(k) i s the setpoi nt for output j at ti me t =kT, and T i s the sampl i ng
peri od (as speci fi ed by the mi nf o vector i n the modformat of pmod and i mod). I f
t end > NT, the setpoi nts vary for the fi rst N peri ods i n the si mul ati on, as
speci fi ed by r , and are then hel d constant at the val ues gi ven i n the l ast row of
r for the remai nder of the si mul ati on.
I n many si mul ati ons one wants the setpoi nts to be constant for the enti re ti me,
i n whi ch case r need onl y contai n a si ngl e row of n
y
val ues.
I f you set r =[ ] , the defaul t i s a row of n
y
zeros.
For open-loop si mul ati ons, r speci fi es the manipulated variables and must
contai n n
u
col umns.
The fol l owi ng i nput vari abl es are opti onal . I n general , setti ng one of them
equal to an empty matri x causes s mpcs i mto use the defaul t val ue, whi ch i s
gi ven i n the descri pti on.
r
r
1
1 ( ) r
2
1 ( ) r
n
y
1 ( )
r
1
2 ( ) r
2
2 ( ) r
n
y
2 ( )

r
1
N ( ) r
2
N ( ) r
n
y
N ( )
=

smpcsim
1-128
usat
I s a matri x gi vi ng the saturati on l i mi ts on the mani pul ated vari abl es. I ts
format i s as fol l ows:
Note that i t contai ns three matri ces of N rows. N may be di fferent than that for
the setpoi nt matri x, r , but the i dea i s the same: the saturati on l i mi ts wi l l vary
for the fi rst N sampl i ng peri ods of the si mul ati on, then be hel d constant at the
val ues gi ven i n the l ast row of us at for the remai ni ng peri ods (i f any).
The fi rst matri x speci fi es the lower bounds on the n
u
mani pul ated vari abl es.
For exampl e, u
min
,
j
(k) i s the l ower bound for mani pul ated vari abl e j at ti me t =
kT i n the si mul ati on. I f u
min
,
j
(k) = inf, mani pul ated vari abl e j wi l l have no
l ower bound at t =kT.
The second matri x gi ves the upper bounds on the mani pul ated vari abl es. I f
u
max,j
(k) =inf, mani pul ated vari abl e j wi l l have no upper bound at t =kT.
The l ower and upper bounds may be ei ther posi ti ve or negati ve (or zero) as l ong
as u
min
,
j
(k) u
max,j
(k).
, ,
, ,
, ,
,
( )
,
( )
, ,
, ,
, ,
,
( )
,
( )
usat
u
mi n 1 ,
1 ( ) u
mi n n
u
,
1 ( )
u
mi n 1 ,
2 ( ) u
mi n n
u
,
2 ( )

u
mi n 1 ,
N ( ) u
mi n n
u
,
N ( )
=
u
max 1 ,
1 ( ) u
max n
u
,
1 ( )
u
max 1 ,
2 ( ) u
max n
u
,
2 ( )

u
max 1 ,
N ( ) u
max n
u
,
N ( )
u
max 1 ,
1 ( ) u
max n
u
,
1 ( )
u
max 1 ,
2 ( ) u
max n
u
,
2 ( )

u
max 1 ,
N ( ) u
max n
u
,
N ( )



smpcsim
4-129
The thi rd matri x gi ves the l i mi ts on the rate of change of the mani pul ated
vari abl es. I n other words, s mpc s i mwi l l force| u
j
(k) u
j
(k 1)| u
max,j
(k). The
l i mi ts on the rate of change must be nonnegati ve.
The defaul t i s no saturati on constrai nts, i .e., al l the umi n val ues wi l l be set to
inf, and al l the u
max
and u
max
val ues wi l l be set to inf.
Note: Saturati on constrai nts are enforced by si mpl y cl i ppi ng the
mani pul ated vari abl e moves so that they sati sfy al l constrai nts. Thi s i s a
nonopti mal sol uti on that, i n general , wi l l di ffer from the resul ts you woul d get
usi ng the ul i mvari abl e i n s c mpc.
Kest
I s the esti mator gai n matri x. The defaul t i s the DMC esti mator. See s mpces t
for more detai l s.
z
I s measurement noi se that wi l l be added to the outputs (see above di agram).
The format i s the same as for r . The defaul t i s a row of n
y
zeros.
d
I s a matri x of measured di sturbances (see above di agram). The format i s the
same as for r , except that the number of col umns i s n
d
rather than n
y
. The
defaul t i s a row of n
d
zeros.
w
I s a matri x of unmeasured di sturbances (see above di agram). The format i s the
same as for r , except that the number of col umns i s n
w
rather than n
y
. The
defaul t i s a row of n
w
zeros.I
wu
I s a matri x of unmeasured di sturbances that are added to the mani pul ated
vari abl es (see above di agram). The format i s the same as for r , except that the
number of col umns i s n
u
rather than n
y
. The defaul t i s a row of n
u
zeros.
smpcsim
1-130
Note: You may use a di fferent number of rows i n the matri ces r , us at , z , d, w
and wu, shoul d that be appropri ate for your si mul ati on.
The cal cul ated outputs are as fol l ows (al l but y p are opti onal ):
yp
I s a matri x contai ni ng M rows and n
y
col umns, where
M =max(fix(tend=T) +1, 2). The fi rst row wi l l contai n the i ni ti al condi ti on, and
row k 1 wi l l gi ve the val ues of the pl ant outputs, y (see above di agram), at
ti me t =kT.
u
I s a matri x contai ni ng the same number of rows as y p and n
u
col umns. The ti me
correspondi ng to each row i s the same as for y p. The el ements i n each row are
the val ues of the mani pul ated vari abl es, u (see above di agram).
Note: The u val ues are those comi ng from the control l er beforethe addi ti on
of the unmeasured di sturbance, w
u
.
ym
I s a matri x of the same structure as y p, contai ni ng the val ues of the predi cted
output from the state esti mator i n the control l er. These wi l l , i n general , di ffer
from those i n y p i f i mod pmod and/or there are unmeasured di sturbances. The
prediction includes theeffect of themost recent measurement, i.e., i t i s .
Examples Consi der the l i near system:
y k k ( )
y
1
s ( )
y
2
s ( )
12.8e
s
16.7s 1 +
------------------------
18.9e
3s
21.0s 1 +
-------------------------
6.6e
7s
10.9s 1 +
------------------------
19.4e
3s
14.4s 1 +
-------------------------
u
1
s ( )
u
2
s ( )
=
smpcsim
4-131
The fol l owi ng statements bui l d the model and cal cul ate the MPC control l er
gai n:
g11=pol y 2t f d( 12. 8, [ 16. 7 1] , 0, 1) ;
g21=pol y 2t f d( 6. 6, [ 10. 9 1] , 0, 7) ;
g12=pol y 2t f d( - 18. 9, [ 21. 0 1] , 0, 3) ;
g22=pol y 2t f d( - 19. 4, [ 14. 4 1] , 0, 3) ;
del t =3; ny =2;
i mod=t f d2mod( del t , ny , g11, g21, g12, g22) ;
pmod=i mod;
P=6; M=2;
y wt =[ ] ; uwt =[ 1 1] ;
Ks =s mpccon( i mod, y wt , uwt , M, P) ;
Si mul ate and pl ot the cl osed-l oop per for mance for a uni t step i n the setpoi nt for
y
2
, occurri ng at t = 0.
t end=30; r =[ 0 1] ;
[ y , u] =s mpcs i m( pmod, i mod, Ks , t end, r ) ;
pl ot al l ( y , u, de l t ) , paus e
0 5 10 15 20 25 30
0.2
0
0.2
0.4
0.6
0.8
1
1.2
Outputs
Time
0 5 10 15 20 25 30
0.24
0.22
0.2
0.18
0.16
0.14
0.12
0.1
Manipulated Variables
Time
smpcsim
1-132
Try a pul se change i n the di sturbance that adds to u
1
:
r =[ ] ; us at =[ ] ; Kes t =[ ] ; z =[ ] ; d=[ ] ; w=[ ] ;
wu=[ 1 0; 0 0] ;
[ y , u] =s mpcs i m( pmod, i mod, Ks , t end, r , us at , Kes t , z , d, w, wu) ;
pl ot al l ( y , u, del t ) , paus e
0 5 10 15 20 25 30
1
0.5
0
0.5
1
1.5
Outputs
Time
0 5 10 15 20 25 30
0.6
0.5
0.4
0.3
0.2
0.1
0
0.1
Manipulated Variables
Time
smpcsim
4-133
For the same di sturbance as i n the previ ous case, l i mi t the rates of change of
both mani pul ated vari abl es.
us at =[ - i nf - i nf i nf i nf 0. 1 0. 05] ;
[ y , u] =s mpcs i m( pmod, i mod, Ks , t end, r , us at , Kes t , z , d, w, wu) ;
pl ot al l ( y , u, de l t ) , paus e
Restrictions I ni ti al condi ti ons of zer o ar e used for al l states i n i mod and pmod. Thi s
si mul ates the condi ti on where al l vari abl es represent a devi ati on from a
steady-state i ni ti al condi ti on.
The fi rst n
u
+ n
d
col umns of the D matri ces i n pmod and i mod must be zero.
I n other words, nei ther u nor d may have an i mmedi ate effect on the outputs.
See Also pl ot al l , pl ot each, s cmpc , s mpccl , s mpccon, s mpces t
0 5 10 15 20 25 30
1
0.5
0
0.5
1
1.5
2
Outputs
Time
0 5 10 15 20 25 30
0.3
0.2
0.1
0
0.1
Manipulated Variables
Time
ss2mod
1-134
1ss2mod
Purpose Converts a di screte-ti me state-space system model i nto the MPC mod format.
Syntax pmod = s s 2mod( phi , gam, c, d)
pmod = s s 2mod( phi , gam, c, d, mi nf o)
Description
Consi der the process shown i n the above bl ock di agram. s s 2mod assumes the
fol l owi ng state-space representati on:
where xi s a vector of n state vari abl es, u represents n
u
mani pul ated vari abl es,
d represents n
d
measured di sturbances, wrepresents n
w
unmeasured
di sturbances, yi s a vector of n
y
pl ant outputs, z i s measurement noi se, and ,

u
, etc., are constant matri ces of appropri ate si ze. The vari abl e (k) represents
the pl ant output before the addi ti on of measurement noi se. We further defi ne:
D = [D
u
D
d
D
w
]
= [
u

d

w
]
s s 2mod uses the , , C, and D matri ces you suppl y to bui l d a model , pmod, i n
the MPC mod format. See the mod secti on for more detai l s.

y y
Unmeasured
Disturbances
Manipulated
Variables
Measured
Disturbances
Measurement
Noise
w
u
d
+ +
z
Plant
Measured
Outputs
x k 1 + ( ) x k ( )
u
u k ( )
d
d k ( )
w
w k ( ) + + + =
y k ( ) y k ( ) z k ( ) + =
Cx k ( ) D
u
u k ( ) D
d
d k ( ) D
w
w k ( ) z k ( ) + + + + =
y
ss2mod
4-135
You can al so di vi de the outputs i nto n
ym
measured outputs and n
yu
unmeasured outputs, where n
ym
+ n
yu
= n
y
. Then the fi rst n
ym
el ements i n y
and the fi rst n
ym
rows i n C and D are assumed to be for the measured outputs,
and the rest are for the unmeasured outputs.
mi nf o i s an opti onal vari abl e that al l ows you to speci fy certai n characteri sti cs
of the system. The general form i s a rowvector wi th 7 el ements, the
i nterpretati on of whi ch i s as fol l ows:
I f you speci fy mi nf o as a scal ar, s s 2mod takes i t as the sampl i ng peri od and sets
the remai ni ng el ements of mi nf o as fol l ows:
mi nf o( 2) = # r ows i n phi , mi nf o( 3) = # col umns i n gam,
mi nf o( 4) = mi nf o( 5) = 0, mi nf o( 6) = # r ows i n c, mi nf o( 7) = 0.
I n other words, thedefault is toassumethat all inputs aremanipulated
variables and all outputs aremeasured. I f you omi t mi nf o, s s 2mod sets the
sampl i ng peri od to 1 and uses the defaul ts for the remai ni ng el ements.
mi nf o (1) T, the sampl i ng peri od used to create the model .
(2) n, the number of states.
(3) n
u
, the number of mani pul ated vari abl e i nputs.
(4) n
d
, the number of measured di sturbances.
(5) n
w
, the number of unmeasured di sturbances.
(6) n
ym
, the number of measured outputs.
(7) n
yu
, the number of unmeasured outputs.
ss2mod
1-136
Example
Suppose you have the si tuati on shown i n the above di agram wher e u, d, w, and
y are scal ar si gnal s, and the three transfer functi ons are fi rst-order:
The sampl i ng peri od i s T = 2.
One way to bui l d the model of the compl ete system i s to convert these to
state-space form and use s s 2mod:
[ phi u, gamu, c u, du] =t f 2s s ( 0. 7, [ 1 - 0. 9] ) ;
[ phi d, gamd, c d, dd] =t f 2s s ( - 1. 5, [ 1 - 0. 85] ) ;
[ phi w, gamw, c w, dw] =t f 2s s ( 1, [ 1 0. 6] ) ;
[ phi , gam, c, d] =mpcpar al ( phi u, gamu, cu, du, phi d, gamd, cd, dd) ;
[ phi , gam, c, d] =mpcpar al ( phi , gam, c, d, phi w, gamw, c w, dw) ;
del t =2;
mi nf o=[ del t 3 1 1 1 1 0] ;
pmod=s s 2mod( phi , gam, c, d, mi nf o)
You must be careful to bui l d up the paral l el structure i n the correct order. For
exampl e, the col umns correspondi ng to
u
must al ways come fi rst i n .
y
u
+
G
d
G
u
y
d

+
+
+
G
w
w
G
d
z ( )
1.5
1 0.85z
1

----------------------------- = G
u
z ( )
0.7
1 0.9z
1

-------------------------- =
G
w
z ( )
1
1 0.6z
1
+
-------------------------- =
ss2mod
4-137
Another, more fool proof way i s to use the addmd and addumd functi ons:
ny =1;
gu=pol y 2t f d( 0. 7, [ 1 - 0. 9] , del t ) ;
gd=pol y 2t f d( - 1. 5, [ 1 - 0. 85] , del t ) ;
gw=pol y 2t f d( 1, [ 1 0. 6] , del t ) ;
pmod=t f d2mod( del t , ny , gu) ;
pmod=addmd( pmod, t f d2mod( del t , ny , gd) ) ;
pmod=addumd( pmod, t f d2mod( del t , ny , gw) )
Usi ng ei ther approach, the resul t i s:
pmod =
2. 0000 3. 0000 1. 0000 1. 0000 1. 0000 1. 0000 0
NaN 0. 9000 0 0 1. 0000 0 0
0 0 0. 8500 0 0 1. 0000 0
0 0 0 - 0. 6000 0 0 1. 0000
0 0. 7000 - 1. 5000 1. 0000 0 0 0
See Also mod f or mat , mod2s s
ss2step
1-138
1ss2step
Purpose Uses a model i n state-space format to cal cul ate the step response of a SI SO or
MI MO system, i n MPC step format.
Syntax pl ant = s s 2s t e p( phi , gam, c, d, t f i nal )
pl ant = s s 2s t e p( phi , gam, c, d, t f i nal , de l t 1, del t 2, nout )
Description The i nput vari abl es phi, gam, c, and d are assumed to be a state-space model
of a process. The model can be ei ther conti nuous ti me:
or di screte ti me:
x(k + 1) = x(k) + u(k)
y(k) = Cx(k) + Du(k)
where xi s a vector of n state vari abl es, u i s a vector of n
u
i nputs (usual l y but
not necessari l y mani pul ated vari abl es), yi s a vector of n
y
pl ant outputs, and ,
, etc., are constant matri ces of appropri ate si ze. The s s 2s t ep functi on
cal cul ates the step responses of al l the outputs of thi s process with respect to
all theinputs in u, and puts thi s i nformati on i nto the vari abl e pl ant i n MPC
step format. The secti on for mod2s t ep descri bes the step format i n detai l .
The i nput vari abl e t f i nal i s the ti me at whi ch you woul d l i ke to end the step
response cal cul ati on, and del t 1 i s the sampl i ng peri od. For conti nuous
systems, use de l t 1=0. I f you do not speci fy del t 1, the defaul t i s del t 1=0.
The opti onal i nput vari abl e del t 2 i s the desi red sampl i ng peri od for the step
response model . I f you use del t 2=[ ] or omi t i t, the defaul t i s del t 2=del t 1 i f
del t1 i s speci fi ed and del t 1 neq 0; otherwi se, the defaul t i s del t 2=1.
The opti onal i nput vari abl e nout i s the output stabi l i ty i ndi cator. For stabl e
systems, set nout equal to the number of outputs, n
y
. For systems wi th one or
more i ntegrati ng outputs, nout i s a col umn vector of l ength n
y
wi th nout ( i ) =0
i ndi cati ng an i ntegrati ng output and nout ( i ) =1 i ndi cati ng a stabl e output. I f
you use nout =[ ] or omi t i t, the defaul t i s nout =n
y
(onl y stabl e outputs).
x

t ( ) x t ( ) u t ( ) + =
y t ( ) Cx t ( ) Du t ( ) + =
ss2step
4-139
Example The fol l owi ng process has 3 i nputs and 4 outputs (and i s the same one used for
the exampl e i n the mod2s t ep secti on):
phi =di ag( [ 0. 3, 0. 7, - 0. 7] ) ;
gam=ey e( 3) ;
c=[ 1 0 0; 0 0 1; 0 1 1; 0 1 0] ;
d=[ 1 0 0; z er os ( 3, 3) ] ;
The fol l owi ng command dupl i cates the resul ts obtai ned wi th mod2s t ep:
del t 1=1. 5; t f i nal =3
*
1. 5;
pl ant =s s 2s t ep( phi , gam, c, d, t f i nal , del t 1)
See Also pl ot s t ep, mod2s t ep, t f d2s t ep
svdfrsp
1-140
1svdfr sp
Purpose Cal cul ates the si ngul ar val ues of a varyi ng matri x, for exampl e, the frequency
response generated by mod2f r s p.
Syntax [ s i gma, omega] = s v df r s p( v mat )
Description v mat i s a varyingmatri x whi ch contai ns the sampl ed val ues F(
1
), ... , F(
N
) of
a matri x functi on F().
I f the smal l er di mensi on of F(
i
) i s m, and i f
1
(
i
), . . . ,
m
(
i
) are the si ngul ar
val ues of F(
i
), i n decreasi ng magni tude, then the output si gma i s a matri x of
si ngul ar val ues arranged as fol l ows:
The output omega i s a col umn vector contai ni ng the frequenci es
1
, . . . ,
N
.
Example See mod2f r s p, v ar y i ng f or mat for an exampl e of the use of thi s functi on.
See Also mod2f r s p
sigma

1

1
( )
2

1
( )
m

1
( )

1

2
( )
2

2
( )
m

2
( )

1

N
( )
2

N
( )
m

N
( )
=

tfd2mod, tf format
4-141
1tfd2mod, tf for mat
Purpose t f d2mod converts a transfer functi on (conti nuous or di screte) from the MPC tf
format i nto the MPC mod format, converti ng to di screte ti me i f necessary.
Syntax model = t f d2mod( del t 2, n
y
, g1, g2, g3, . . . , g25)
Description Consi der a transfer functi on such as
or
The MPC tf format i s a matri x consi sti ng of three rows:
The tf matri x wi l l al ways have at l east two col umns, si nce that i s the mi ni mum
wi dth of the thi rd row.
The i nput arguments for t f d2mod are:
row 1 The n coeffi ci ents of the numerator pol ynomi al , b
0
to b
n
.
row 2 The n coeffi ci ents of the denomi nator pol ynomi al , a
0
to a
n
.
row 3 col umn 1: The sampl i ng peri od. Thi s must be zero i f the
coeffi ci ents i n the above rows are for a conti nuous system. I t
must be posi ti ve otherwi se.
col umn 2: The ti me del ay. For a conti nuous-ti me transfer
functi on, i t i s i n ti me uni ts. For a di screte-ti me transfer
functi on, i t i s the i nteger number of sampl i ng peri ods of ti me
del ay.
G s ( )
b
0
s
n
b
1
s
n 1
b
n
+ + +
a
0
s
n
a
1
s
n 1
a
n
+ + +
---------------------------------------------------------------- =
G z ( )
b
0
b
1
z
1
b
n
z
n
+ + +
a
0
a
1
z
1
a
n
z
n
+ + +
------------------------------------------------------------- =
tfd2mod, tf format
1-142
del t2
The sampl i ng peri od for the system. I f any of the transfer functi ons g1, . . . ,
gN are conti nuous-ti me or di screte-ti me wi th sampl i ng peri od not equal to
del t 2, t f d2mod wi l l convert them to di screte-ti me wi th thi s sampl i ng peri od.
ny
The number of output vari abl es i n the pl ant you are model i ng.
g1, g2, . . . gN
A sequence of N transfer functi ons i n the tf format descri bed above, where N
1. These are assumed to be the i ndi vi dual el ements of a transfer-functi on
matri x:
Thus i t shoul d be cl ear that N must be an i nteger mul ti pl e (n
u
) of the number
of outputs, n
y
.
Al so, t f d2mod assumes that you are suppl yi ng the transfer functi ons i n a
column-wiseorder. I n other words, you shoul d fi rst gi ve the n
y
transfer
functi ons for i nput 1 (g
1,1
to g
ny
, 1), then the n
y
transfer functi ons for i nput 2
(g
1,2
to g
ny
, 2), etc.
t f d2mod converts the transfer functi ons to di screte-ti me, i f necessary, and
combi nes them to form the output vari abl e, model , whi ch i s a composi te system
i n the MPC mod form.
Example Consi der the l i near system:
g
1 1 ,
g
1 2 ,
g
1 n
u
,
g
2 1 ,
g
2 2 ,
g
2 n
u
,
g
n
y
1 ,
g
n
y
2 ,
g
n
y
n
u
,

.
.
y
1
s ( )
y
2
s ( )
12.8e
s
16.7s 1 +
------------------------
18.9e
3s
21.0s 1 +
-------------------------
6.6e
7s
10.9s 1 +
------------------------
19.4e
3s
14.4s 1 +
-------------------------
u
1
s ( )
u
2
s ( )
3.8e
8 s
14.9s 1 +
------------------------
4.9e
3s
13.2s 1 +
------------------------
w s ( ) + =
tfd2mod, tf format
4-143
The fol l owi ng commands bui l d separate model s of the response to the
mani pul ated vari abl es, u, and the unmeasured di sturbance, w, al l for a
sampl i ng peri od T = 3 then combi nes them usi ng addumd to get a model of the
enti re system (the pmod vari abl e):
g11=pol y 2t f d( 12. 8, [ 16. 7 1] , 0, 1) ;
g21=pol y 2t f d( 6. 6, [ 10. 9 1] , 0, 7) ;
g12=pol y 2t f d( - 18. 9, [ 21. 0 1] , 0, 3) ;
g22=pol y 2t f d( - 19. 4, [ 14. 4 1] , 0, 3) ;
del t =3; ny =2;
umod=t f d2mod( del t , ny , g11, g21, g12, g22) ;
gw1=pol y 2t f d( 3. 8, [ 14. 9 1] , 0, 8) ;
gw2=pol y 2t f d( 4. 9, [ 13. 2 1] , 0, 3) ;
wmod=t f d2mod( del t , ny , gw1, gw2) ;
pmod=addumd( umod, wmod) ;
Restriction The current l i mi t on the number of i nput transfer functi ons i s N = 25.
See Also mod, pol y 2t f d, t f d2s t ep
tfd2step
1-144
1tfd2step
Purpose Cal cul ates the MI MO step response of a model i n the MPC tf format. The
resul ti ng step response i s i n the MPC step format.
Syntax pl ant = t f d2s t ep( t f i nal , de l t 2, nout , g1)
pl ant = t f d2s t ep( t f i nal , de l t 2, nout , g1, . . . , g25)
Description The i nput vari abl es are as fol l ows:
tf i nal
Truncati on ti me for step response.
del t2
Desi red sampl i ng peri od for step response.
nout
Output stabi l i ty i ndi cator. For stabl e systems, thi s argument i s set equal to the
number of outputs, n
y
. For systems wi th one or more i ntegrati ng outputs, thi s
argument i s a col umn vector of l ength n
y
wi th nout ( i ) =0 i ndi cati ng an
i ntegrati ng output and nout ( i ) =1 i ndi cati ng a stabl e output.
g1, g2, . . . gN
A sequence of N transfer functi ons i n the tf format (see t f format secti on),
where N 1. These are assumed to be the i ndi vi dual el ements of a
transfer-functi on matri x:
Thus i t shoul d be cl ear that N must be an i nteger mul ti pl e (n
u
) of the number
of outputs, n
y
.
t f d2s t ep assumes that you are suppl yi ng the transfer functi ons i n a
column-wiseorder. I n other words, you shoul d fi rst gi ve the n
y
transfer
functi ons for i nput 1 (g
1,1
to g
ny
, 1), then the n
y
transfer functi ons for i nput 2
(g
1,2
to g
ny
, 2), etc.
g
1 1 ,
g
1 2 ,
g
1 n
u
,
g
2 1 ,
g
2 2 ,
g
2 n
u
,
g
n
y
1 ,
g
n
y
2 ,
g
n
y
n
u
,

.
.
tfd2step
4-145
The output vari abl e pl ant i s the cal cul ated step response of the n
y
outputs wi th
respect to all i nputs. The format i s as descri bed i n the step secti on.
Example Consi der the l i near system:
whi ch i s the same as that consi dered i n the mpcs i mexampl e. We bui l d the
i ndi vi dual tf format model s, then cal cul ate and pl ot the MI MO step response.
g11=pol y 2t f d( 12. 8, [ 16. 7 1] , 0, 1) ;
g21=pol y 2t f d( 6. 6, [ 10. 9 1] , 0, 7) ;
g12=pol y 2t f d( - 18. 9, [ 21. 0 1] , 0, 3) ;
g22=pol y 2t f d( - 19. 4, [ 14. 4 1] , 0, 3) ;
del t =3; ny =2; t f i nal =90;
pl ant =t f d2s t ep( t f i nal , del t , ny , g11, g21, g12, g22, gw1, gw2) ;
pl ot s t ep( pl ant )
The pl ots shoul d match the exampl e output i n the pl ot s t ep descri pti on.
Restriction The current l i mi t on the number of i nput transfer functi ons i s N = 25.
See Also mod2s t ep, pl ot s t ep, s s 2s t ep
y
1
s ( )
y
2
s ( )
12.8e
s
16.7s 1 +
------------------------
18.9e
3s
21.0s 1 +
-------------------------
6.6e
7s
10.9s 1 +
------------------------
19.4e
3s
14.4s 1 +
-------------------------
u
1
s ( )
u
2
s ( )
=
th2mod, theta format
1-146
1th2mod, theta for mat
Purpose Converts a SI SO or MI SO model from the theta format (as used i n the System
I denti fi cati on Tool box) to one i n the MPC mod format. Can al so combi ne such
model s to form a MI MO system.
Syntax umod = t h2mod( t h)
[ umod, emod] = t h2mod( t h1, t h2, . . . , t hN)
Description The System I denti fi cati on Tool box al l ows you to i denti fy si ngl e-i nput,
si ngl e-output (SI SO) and mul ti -i nput, si ngl e-output (MI SO) transfer functi ons
from data. The MI SO form rel ati ng an output, y, to mi nputs, u
1
to u
m
, and a
noi se i nput, e, i s:
where A, B
i
, C, D, and F
i
are pol ynomi al s i n the forward-shi ft operator, z.
The System I denti fi cati on Tool box automati cal l y stores such model s i n a
speci al format, the theta format. See the SystemI dentification Toolbox Users
Guidefor detai l s.
t h2mod converts one or more MI SO theta model s i nto the MPC mod format,
whi ch you can then use wi th the MPC Tool box functi ons. I f you suppl y a si ngl e
i nput argument, t h, and a si ngl e output argument, umod, then umod wi l l model
the response of a si ngl e output, y, to mi nputs, u
1
to u
m
, where m 1. The val ue
of mdepends on the number of i nputs i ncl uded i n the i nput model , t h. Note
that umod wi l l refl ect the val ues of the A(z), B(z), and F(z) pol ynomi al s i n eq. 1.
I f you suppl y a second output argument, emod, i t wi l l model the response of yto
the noi se, e, i .e., the A(z), C(z) and D(z) pol ynomi al s i n eq. 1.
I f you suppl y p i nput model s (1 p 8), t f d2mod assumes that they defi ne a
MI MO system i n the fol l owi ng form:
A z ( )y k ( )
B
1
z ( )
F
1
z ( )
---------------u
1
k ( )
B
2
z ( )
F
2
z ( )
---------------u
2
k ( )
B
m
z ( )
F
m
z ( )
----------------u
m
k ( )
C z ( )
D z ( )
------------e k ( ) + + + + =
A
1
z ( )y
1
k ( )
B
11
z ( )
F
11
z ( )
-----------------u
1
k ( )
B
1m
z ( )
F
1m
z ( )
-------------------u
m
k ( )
C
1
z ( )
D
1
z ( )
---------------e
1
k ( ) + + + =
A
p
z ( )y
p
k ( )
B
p1
z ( )
F
p1
z ( )
------------------u
1
k ( )
B
pm
z ( )
F
pm
z ( )
-------------------u
m
k ( )
C
p
z ( )
D
p
z ( )
---------------e
p
k ( ) + + + =

th2mod, theta format


4-147
The poutput vari abl es have i ndependent noi se i nputs. I n thi s case, each of the
p i nput model s must i ncl ude the same number of i nputs, m. The p outputs are
arranged i n paral l el i n the resul ti ng umod output model (and the emod model , i f
used).
I f the t h model s are auto-regressi ve (i .e., m= 0), then umod wi l l be set to an
empty matri x and onl y emod wi l l be nonempty.
Example The fol l owi ng commands create three SI SO theta model s usi ng the mkt het a
command (System I denti fi cati on Tool box), then converts them to the
equi val ent mod form:
t h1=mkt het a( [ 1 0 - . 2] , [ 0 0 - 1] ) ;
t h2=mkt het a( [ 1 - . 8 . 1] , [ 0 - . 5 . 3] , 1, 1, 1) ;
t h3=mkt het a( [ 1 - . 2] , [ 0 1] , [ 1 2 0] , [ 1 - 1. 2 . 3] , 1) ;
[ umod, emod] =t h2mod( t h1, t h2, t h3)
th2mod, theta format
1-148
The resul ts are:
umod =
1. 0000 5. 0000 1. 0000 0 0 3. 0000 0
NaN 0 0. 2000 0 0 0 1. 0000
0 1. 0000 0 0 0 0 0
0 0 0 0. 8000 - 0. 1000 0 1. 0000
0 0 0 1. 0000 0 0 0
0 0 0 0 0 2. 0000 1. 0000
0 0 - 1. 0000 0 0 0 0
0 0 0 - 0. 5000 0. 3000 0 0
0 0 0 0 0 1. 0000
e mod =
Col umns 1 t hr ough 7
1. 0000 7. 0000 3. 0000 0 0 3. 0000 0
NaN 0 0. 2000 0 0 0 0
0 1. 0000 0 0 0 0 0
0 0 0 0. 8000 - 0. 1000 0 0
0 0 0 1. 0000 0 0 0
0 0 0 0 0 1. 4000 - 0. 5400
0 0 0 0 0 1. 0000 0
0 0 0 0 0 0 1. 0000
0 0 0. 2000 0 0 0 0
0 0 0 0. 8000 - 0. 1000 0 0
0 0 0 0 0 3. 4000 - 0. 5400
Col umns 8 t hr ough 11
0 0 0 0
0 1. 0000 0 0
0 0 0 0
0 0 1. 0000 0
0 0 0 0
0. 0600 0 0 1. 0000
0 0 0 0
0 0 0 0
0 1. 0000 0 0
0 0 1. 0000 0
0. 0600 0 0 1. 0000
th2mod, theta format
4-149
Restriction The System I denti fi cati on Tool box must be i nstal l ed to use thi s functi on.
See Also mod
validmod
1-150
1val i dmod
Purpose Val i dates an i mpul se response model for a new set of data.
Syntax y r e s = v al i dmod( x r eg, y r eg, t het a)
y r e s = v al i dmod( x r eg, y r eg, t het a, pl ot opt )
Description Model val i dati on i s a very i mportant part of bui l di ng a model . For a new set of
data, x r eg and y r eg, the i mpul se response model i s tested by cal cul ati ng the
output resi dual , y r es . t het a consi sts of i mpul se response coeffi ci ents as
determi ned by routi nes such as pl s r or ml r .
Opti onal i nput, pl ot opt , can be suppl i ed to produce vari ous pl ots. No pl ot i s
pr oduced i f pl ot opt i s equal to 0 whi ch i s the defaul t; a pl ot of the actual output
and the predi cted output i s produced i f pl ot opt =1; two pl ots pl ot of actual
and predi cted output, and pl ot of output resi dual are produced for
pl ot opt =2.
Example See pl s r for an exampl e of the use of thi s functi on.
See Also ml r , pl s r
wrtreg
4-151
1wrtr eg
Purpose Wri tes i nput and output data matri ces for a mul ti -i nput si ngl e-output system
such that they can be used i n regressi on routi nes ml r and pl s for determi ni ng
i mpul se response coeffi ci ents.
Syntax [ x r eg, y r eg] = wr t r eg( x , y , n)
Description x i s the i nput data of di mensi on N by n
u
where N i s number of data poi nts and
n
u
i s number of i nputs. y i s the output of di mensi on N by 1. n i s number of
i mpul se response coeffi ci ents for al l i nputs. x i s rearranged to produce x r eg of
di mensi on (N n 1) by n
*
n
u
whi l e y r eg i s produced by del eti ng the fi rst n
rows of y. Thi s operati on i s i l l ustrated as fol l ows:
then
A si ngl e sampl i ng del ay i s assumed for al l i nputs. y must be a col umn vector,
i .e., onl y one output can be speci fi ed.
x
x
1
1 ( ) x
n
u
1 ( )
x
1
2 ( ) x
n
u
2 ( )
x
1
N ( ) x
n
u
N ( )
=

y
y 1 ( )
y N ( )
=

xreg
x
1
n ( ) x
1
1 ( ) x
n
u
n ( ) x
n
u
1 ( )
x
1
n 1 + ( ) x
1
2 ( ) x
n
u
n 1 + ( ) x
n
u
2 ( )
x
1
N 1 ( ) x
1
N n ( ) x
n
u
N 1 ( ) x
n
u
N n ( )
=

yreg
y n 1 + ( )
y N ( )
=

wrtreg
1-152
Example See ml r and pl s r for exampl es of the use of thi s functi on.
See Also ml r , pl s r
I-1
I ndex
A
abc dchk 4-6
abc dchkm4-6
addmd 4-4, 4-9, 4-149
addmod 4-4, 4-10
addumd 4-4, 4-11, 4-131, 4-149, 4-155
append 4-13
appmod 4-4, 4-13
associ ated vari abl e 2-36
aut os c 2-7, 2-8, 4-2, 4-14, 4-31
B
bal ance 4-38
bi l i near 3-26
bl ocki ng 3-15, 4-60
bl ocki ng factor 3-15, 4-76, 4-109
Bode pl ot 4-97
bound, see constrai nt
output 4-120
bound, seeconstrai nt
mani pul ated vari abl e 4-97, 4-107, 4-108, 4-110,
4-112
output 4-113, 4-117, 4-120, 4-123, 4-125, 4-128
C
c2d 4-3
c2dmp 4-3, 4-24, 4-89
cl osed-l oop
model i n mod format 4-107
system model 4-56
cmpc 2-21, 2-24, 2-29, 4-4, 4-15
compl ementary sensi ti vi ty functi on 2-18, 4-39
constrai nt, seebound 2-20, 2-22, 3-12, 3-20
hard 2-20
conti nuous 3-9
control l er gai n 4-59, 4-66, 4-81, 4-137
for model i n mod format 4-124
covari ance 4-25
covari ance matri x 4-129
cp2dp 4-3, 4-24
D
d2c 4-3
d2cmp 4-3
dant z gmp 4-6, 4-15, 4-107, 4-126
dar ei t er 4-6, 4-27
demo fi l e 1-3
di mpul s e 4-6
di mpul s m4-6
di screte 3-9
di sturbance
measured 3-10, 3-17, 3-26, 3-33, 4-35
ti me constant 4-17, 4-66, 4-75, 4-79
unmeasur ed 3-13, 3-17, 3-20, 3-23, 4-35
di sturbance model 4-128, 4-129
di sturbance ti me constant 2-12, 4-131
dl qe2 4- 6, 4-254-28, 4-133
dl s i mm4-6, 4-119
DMC esti mator 4-132, 4-133
DMC, 1, seedynami c matri x control 2-12, 3-18,
3-20, 4-60, 4-76, 4-109, 4-125
dynami c matri x control , 1, seeDMC 2-12
E
esti mator 4-70
esti mator gai n 4-112, 4-120, 4-129, 4-130, 4-141
for model s i n mod format 4-128
Index
I-2
F
f cc_demo. m2-34
feedfor ward compensati on 4-9
feedfor ward contr ol 3-33
fi l ter 4-25
fl ui d catal yti c cracki ng 2-312-38
forward-shi ft operator 3-6
frequency resoponse 2-18
frequency response 4-38, 4-41
pl ot 4-97
G
gai n matri x
for model i n mod format 4-135
H
Hessenberg matr i x 4-41
hori zon 2-11, 2-12
control 3-20, 3-30
movi ng 2-11
predi cti on 3-22, 3-30
reci di ng 2-11
I
I DCOM 1-2
i denti fi cati on 2-6
i dl e speed control 2-222-30
i dl ect r . m2-24
i mp2s t ep 4-2, 4-29, 4-102
i mpul se response coeffi ci ent 2-6, 4-29
i nfeasi bi l i ty 3-23
i ni ti al condi ti on 4-79
i nput hori zon 4-60, 4-78, 4-109, 4-125
i ntegrati ng process 2-7, 2-34
i ntegrati ng processes 2-2
i nver se response 3-29
L
l east squares regressi on 4-30
l i near quadrati c opti mal control 1-2
M
mani pul ated var i abl e
bound 4-18, 4-68
rate l i mi t 4-68, 4-84, 4-140
saturati on l i mi t 4-68, 4-82, 4-140
matri x type 4-63
mean 4-14
measurement noi se 2-13, 4-15, 4-25, 4-35, 4-51
mi nf o 3-29, 4-44, 4-147
mi nf o vector 4-37
mkt het a 4-159
ml r 4-2, 4-14, 4-30, 4-35, 4-37, 4-162, 4-163
mod format 4-35, 4-38, 4-63, 4-107
from di screte-ti me state-space model 4-146
from model i n t f for mat 4-153
from model i n theta format 4-158
matri x type i nfomati on 4-63
mod2f r s p 2-18, 3-12, 4-5, 4-38??, 4-63, 4-152
v ar y i ng f or mat 4-38
mod2mod 4-3, 4- 42
mod2s s 3-10, 4-3, 4-10, 4-28, 4- 43, 4-43??
mod2s t ep 3-29, 4-3, 4-47??, 4-90
s t ep f or mat 4-47
model al gori thmi c control 1-2
model -i nverse control l er 4-60, 4-125
mpcaugs s 4-6, 4-51, 4-514-53, 4-133
mpcc l 4-4, 4-54, 4-544-58, 4-61
Index
I-3
mpc con 2-13, 2-15, 2-29, 2-36, 4-4, 4-54, 4-57, 4-59,
4-594-62
mpc i nf o 4-2, 4-37, 4-63
mpc par al 4-6, 4-9, 4-11, 4-92, 4-148
mpc s i m2-14, 2-29, 2-36, 4-4, 4-65
mpc s t ai r 4-6
mpc t ut . m2-3
mpc t ut i d 2-7
mpc t ut s s . m3-12, 3- 20
N
nar gchk 4-6
nar gchkm4-6
nl c mpc 4-4, 4-74, 4-74??
nl mpcdm1. m4-86
nl mpcl i b 4-74, 4-81
nl mpcs i m4-4, 4-81
noi se fi l ter
ti me constant 2-12, 4-19, 4-69, 4-79, 4-85
noi se model 4-128
nonl i near pl ant 4-74
O
operati ng condi ti ons
dri ve posi ti ons 2-22
transmi ssi on i n neutral 2-22
output
bound 4-19, 4-78, 4-107, 4-108
measured 2-11, 4-25, 4-36, 4-43
unmeasured 2-12, 4-36
output stabi l i ty i ndi cator 4-29, 4-47, 4-151, 4-156
P
pap_mach. m3-37, 4-88
paper machi ne headbox control 3-26
par amod 3-10, 4-4, 4-9, 4-92
par par t 4- 78
par ti al l east squares 4-100
perfect control l er 3-13, 4-60, 4-125
pl ot al l 2-14, 2-15, 3-12, 4-2, 4-93
pl ot each 3-12, 4-2, 4-93, 4-95
pl ot f r s p 2-18, 3-12, 4-2, 4-97
pl ot s t ep 2-4, 2-9, 4-2, 4-98
PLS 4-100
pl s 4-163
pl s r 2- 7, 4-2, 4-100, 4-162
pm_l i n. m3-27
pm_nonl . m3-37
pol e
for model i n mod format 2-18, 4-135
pol y format
conversi on to t f format 4-104
pol y 2t f d 2- 3, 2- 13, 3- 6, 3- 7, 3- 13, 3- 20, 4-3,
4- 21, 4-28, 4-57, 4-104, 4-121, 4-131,
4-142, 4-155, 4- 157
pr edi cti on hori zon 4-59, 4-75, 4-108, 4-125
pr edi ctor 4-27
Q
QP 4-21, 4-79, 4-114
quadrati c program 4-6, 4-15, 4-107, 4-126
Index
I-4
R
ramp 2-13
rate l i mi t 4-68, 4-82, 4-138
reference val ue 2-11
regressi on 4-163
l east squar es 4-30
parti al l east squares 4-100
ri dge 4-30
r es cal 4-2, 4-14
ri dge regressi on 4-30
ri ngi ng 3-14
robust 2-22
robustness 2-12
S
sampl i ng peri od
change i n mod format 4-42
satur ati on constr ai nt 4-65, 4-136
satur ati on l i mi t 4-68, 4-84, 4-138
s cal 2-9, 4-2, 4-14, 4-31
scal i ng 4-14
s cmpc 3-21, 3-24, 3-30, 3-31, 3-32, 3-34, 4-5,
4- 107, 4-140
s cmpcnl 3-37
sensi ti vi ty functi on 2-18, 4-41
s er mod 3-10, 4-4, 4- 117
setpoi nt 2-11
si gnal -to-noi se rati o 3-37, 4-130
Si mul i nk 1-3, 3-37, 4-4, 4-81, 4-85, 4-88, 4-89
si ngul ar val ue 2-18, 4-41
of varyi ng mati ri x 4-152
s mpccl 3-12, 3-14, 4-5, 4- 118, 4-126
s mpccon 3-12, 3-13, 4-5, 4-108, 4- 118, 4- 124,
4-129, 4-131, 4-134, 4-137, 4-142
s mpces t 3-12, 3-18, 4-5, 4-119, 4- 128, 4-141
s mpcgai n 3-12, 4-5, 4- 135
s mpc pol e 3-12, 4-5, 4-121, 4- 135
s mpc s i m3-12, 3-14, 3-16, 3-18, 3-21, 4- 5, 4-113
s s 2mod 3-9, 3-29, 4-37, 4- 146
s s 2moda 4-3
s s 2s t ep 2-5, 4-3, 4- 150
s s 2t f 3-11, 4-3
s s 2t f 2 4-3
stabi l i ty 2-12
stabi l i ty anal ysi s 4-54
stai r step 4-6, 4-93, 4-95
standard devi ati on 4-14
state esti mati on 4-15, 4-126
state esti mator 3-35, 4-25
state space 2-18, 4-25
s t ep for mat 4-15, 4-17, 4-29, 4-47??, 4-55, 4-65
matri x type i nformati on 4-63
step response
from mod format 4-47
from state-space model 4-150
from t f format 4-156
pl ot 4-98
step response coeffi ci ent 2-2
step response model 2-2
s v df r s p 3-12, 4-5, 4- 152
System I denti fi cati on Tool box 3-9, 4-158
system requi r ement 1-3
T
t f format 4-153
t f 2s s 2-5, 4-3
t f 2s s m4-3
t f d2mod 3-4, 3-5, 3-6, 3-7, 3-13, 3-20, 4-3, 4-28,
4-121, 4-142, 4-153, 4- 153, 4-159
Index
I-5
t f d2s t ep 2-4, 2-13, 2-24, 4-3, 4-21, 4-57, 4- 156
t h2mod 3-9, 4-3, 4-9
t he t a 4- 158
t he t a format 3-9, 4-158
ti me constant
noi se fi l ter 4-19, 4-79
unmeasured di sturbance 4-69, 4-85, 4-90,
4-113, 4-123
tutori al 1-3
U
usage di spl ay 1-3
V
val i dati on 4-162
v al i dmod 4-2, 4-101, 4- 162
var yi ng format
matri x type i nformati on 4-63, 4-97
varyingmatri x 4-152
v ec2mat 4-6
W
wei ght 4-16, 4-59, 4-75, 4-108, 4-124
ti me varyi ng 4-61, 4-126
wei ghti ng matri x 2-11, 2-12
whi te noi se 4-25, 4-130
wr t r eg 2-7, 2-8, 4-2, 4- 163
Index
I-6

You might also like