EE4C04
MPC Exercise Session
Ton van den Boom (
[email protected])
Delft Center for Systems and Control, TU Delft
MPC Exercise Session – EE4C04
1. Computation of predicted output
Given a system
1 a 0
x(k + 1) = x(k) + u(k)
0 1 2
y(k) = 1 0 x(k)
1
with x(k) = and
1
(
1 for j = 20
u(k + j|k) =
0 elsewhere
1. Compute ŷ(k + 25|k).
Solution:
1 a
A=
0 1
1 pa
Ap =
0 1
Use the formula
for p(k + j) = y(k + 25):
ŷ(k + 25|k) = C A25 x(k) + C A4 B u(k + 20|k)
1 25 a 1 1 4a 0
= 1 0 + 1 0
0 1 1 0 1 2
= 1 + 25a + 8a
= 1 + 33a
MPC Exercise Session – EE4C04 1
2. Standard formulation
Consider the IO model
xo (k + 1) = Ao xo (k) + Ko eo (k) + Lo do (k) + Bo u(k)
y(k) = Co xo (k) + eo (k)
where Ao ∈ IRna ×na , Ko ∈ IRna ×1 , Lo ∈ IRna ×1 , Bo ∈ IRna ×1 and
Co ∈ IR1×na . The state is xo (k), do (k) is the known disturbance, u(k) is the input
signal and eo (k) is zero-mean white noise. Note that this is a SISO model.
A performance index J(k) is given by:
XN
T T
J(u, k) = x̂o (k+j|k)Qx̂o (k+j|k) + u (k+j −1|k)Ru(k+j −1|k)
j=1
T
+ ŷ (k+j|k)S ŷ(k+j|k) (1)
where ˆ denotes prediction, and Q, R, S are positive definite matrices.
Consider the following constraint:
u(k + j) = u(k + j − 1) , for j ≥ Nc (2)
1. Describe the problem of finding the control-law that minimizes performance index (1)
subject to (2) as a standard predictive control problem, and give the corresponding
system matrices and the selection matrices Γ(j).
Solution:
Define the performance signal
S 1/2 y(k + 1)
z(k) = Q1/2 x (k + 1)
o
R 1/2 , u(k)
MPC Exercise Session – EE4C04 2
and selection matrix
1 0 0
Γ(j) = 0 1 0
0 0 1
Then it easy to see that
NX−1
J(v, k) = ẑ T (k + j)Γ(j)ẑ(k + j) =
j=0
XN
= ŷ T (k+j|k)S ŷ(k+j|k) + x̂T
o (k+j|k)Qx̂o (k+j|k)
j=1
+uT (k+j −1|k)Ru(k+j −1|k)
MPC Exercise Session – EE4C04 3
For z(k) we obtain:
S 1/2 y(k + 1)
z(k) = 1/2 x (k + 1)
Q o
R 1/2 u(k)
S 1/2 Co Ao xo (k)+Co Ko eo (k)+Co Lo do (k)+Co Bo u(k)
= Q1/2 Ao xo (k)+Ko eo (k)+Lo do (k)+Bo u(k)
R1/2 , u(k)
S 1/2 Co Ao S 1/2 Co Ko
= Q1/2 Ao xo (k) + Q1/2 Ko eo (k)
0 0
1/2 S 1/2 Co Bo
S Co Lo
+ Q1/2 Lo do (k) + 1/2 u(k)
Q Bo
0 R 1/2
= C2 x(k) + D21 e(k) + D22 w(k) + D23 v(k)
for
S 1/2 Co Ao S 1/2 Co Ko
C2 = Q1/2 Ao D21 = Q1/2 Ko
0 0
S 1/2 Co Lo S 1/2 Co Bo
D22 = Q1/2 Lo
D23 = Q 1/2 B
o
0 R 1/2
x(k) = xo (k), e(k) = eo (k), w(k) = do (k), v(k) = u(k)
Finally by choosing
A = Ao , B1 = Ko , B2 = Lo , B3 = Bo
MPC Exercise Session – EE4C04 4
we obtain the state equation
xo (k + 1)
x(k + 1) =
xu (k + 1)
Ao xo (k) + Ko eo (k) + Lo do (k) + Bo u(k)
=
Au xu (k) + Bu u(k)
= A x(k) + B1 e(k) + B2 w(k) + B3 v(k)
Define
v(k|k)
v(k + 1|k)
ṽ(k) = ..
.
v(k + N − 1|k)
with v(k) = u(k) we obtain the constraint:
u(k + Nc ) = u(k + Nc − 1)
u(k + Nc + 1) = u(k + Nc )
..
.
u(k + N − 1) = u(k + N − 2)
0 ··· 0 1 −1 0 ... 0
0 0 0 1 −1 0
= .. .. .. .. ṽ(k)
. 0 . . .
..
0 . 0 0 0 ··· 1 −1
| {z }
D̃33
= C̃3 x(k) + D̃31 e(k) + D̃32 w̃(k) + D̃33 ṽ(k)
where C̃3 = 0, D̃31 = 0, and D̃32 = 0. ✷
MPC Exercise Session – EE4C04 5
3. Compute v(k)
Consider a LTI system given in the state space description
x(k + 1) = A x(k) + B3 v(k)
z(k) = C2 x(k) + D23 v(k)
3 1
where A = −2, B3 = 1, C2 = and D23 = . Note that there is no noise
0 1
(so e = 0) and there is no external input (w = 0). A performance index is defined as
NX−1
T
min J(ṽ, k) = min ẑ (k + j|k)ẑ(k + j|k) (3)
ṽ(k) ṽ(k) j=0
for N = 1 and x(0) = −10.
1. Compute v(k) for k = 0, . . . , 2.
Solution:
1 3
Compute Ev = 1, Γ̄ = 1, D̃23 = D23 = , C̃2 = C2 = ,
1 0
1 0
and Γ̄ = . The optimal control law is given by
0 1
v(k) = −F x(k)
T −1 T
= −Ev (D̃23 Γ̄D̃23 ) D̃23 Γ̄C̃2 x(k)
1 −1 3
= 1( 1 1 · I ) 1 1 I = −1.5 · x(k)
1 0
MPC Exercise Session – EE4C04 6
We find
v(0) = −F x(0) = −1.5 · (−10) = 15
x(1) = A x(0) + B3 v(0) = (−2)(−10) + 15 = 35
v(1) = −F x(1) = −1.5 · (35) = −52.5
x(2) = A x(1) + B3 v(1) = −2 (35) − 52.5 = −122.5
v(2) = −F x(2) = −1.5 · (−122.5) = 183.75
x(3) = A x(2) + B3 v(2) = −2 (−122.5) + 183.75 = 428.75
MPC Exercise Session – EE4C04 7
4. Solution of the SPCP
system
x(k + 1) = A x(k) + B1 e(k) + B2 w(k) + B3 v(k)
y(k) = C1 x(k) + D11 e(k) + D12 w(k)
z(k) = C2 x(k) + D21 e(k) + D22 w(k) + D23 v(k)
with v = ∆u (so we have an IIO system) and a steady-state
(vss , xss , wss , zss ) = (vss , xss , wss , 0)
at time k with state x(k), external signal w̃(k) and ZMWN signal e(k).
1. Define
J ∗ (k) = min J(k)
ṽ
Describe how the optimized performance index J ∗ (k) of the SPCP changes when
• the prediction horizon is increased (decreased),
• the minimum cost horizon is increased (decreased), (but Nm < N )
• the control horizon is increased (decreased), (but Nc < N ),
• an inequality constraint is introduced (removed).
2. Define the optimized performance indices
∗
Ji (k) = min Ji (k) , i = 1, . . . , 6
ṽ
• J1 is the performance index for the SPCP with infinite prediction horizon (N = ∞),
minimum cost horizon Nm = 4 and control horizon Nc = 20 subject to inequality
constraints ψ(k) ≤ Ψ(k).
• J2 is the performance index for the SPCP with prediction horizon N = 50,
minimum cost horizon Nm = 1 and control horizon Nc = 20.
MPC Exercise Session – EE4C04 8
• J3 is the performance index for the unconstrained SPCP with infinite prediction
horizon (N = ∞), minimum cost horizon Nm = 4 and infinite control horizon
(Nc = ∞).
• J4 is the performance index for the SPCP with infinite prediction horizon (N = ∞),
minimum cost horizon Nm = 1 and control horizon Nc = 20 subject to inequality
constraints ψ(k) ≤ Ψ(k).
• J5 is the performance index for the SPCP with infinite prediction horizon (N = ∞),
minimum cost horizon Nm = 1 and infinite control horizon (Nc = ∞)
• J6 is the performance index for the SPCP with prediction horizon N = 50,
minimum cost horizon Nm = 1 and finite control horizon Nc = 20, subject to
inequality constraints ψ(k) ≤ Ψ(k).
Find a ranking in magnitude Ji∗ ≤ Jj∗ for all combinations i = 1, . . . , 6, j = 1, . . . , 6.
(For example, four fictive performance indices J7∗ , J8∗ , J9∗ and J10 ∗ give a ranking:
J7∗ ≤ J8∗ ≤ J9∗ and J7∗ ≤ J10 ∗ ≤ J ∗ if J ∗ is the smallest, J ∗ is the largest, but the
9 7 9
order in J8∗ and J10
∗ is indefinite). Comment on your choices.
Solution:
1. Define
J ∗ (k) = min J(k)
ṽ
• Increasing (Decreasing) the prediction horizon means that more (less)
terms are taken into account, so performance index J(k) will increase
(decrease).
• Increasing (Decreasing) the minimum cost horizon means that less
(more) terms are taken into account, so performance index J(k) will
decrease (increase).
• Increasing (Decreasing) the control horizon means that we obtain more
(less) degrees of freedom for the optimization, so performance index
J(k) will decrease (increase).
• Introducing (removing) an inequality constraint means that we obtain
less (more) degrees of freedom for the optimization, so performance
MPC Exercise Session – EE4C04 9
index J(k) will increase (decrease).
2. Define the optimized performance indices
Ji∗ (k) = min Ji (k) , i = 1, . . . , 6
ṽ
PI N Nm Nc ψ
J1∗ ∞ 4 20 Yes
J2∗ 50 1 20 No
J3∗ ∞ 4 ∞ No
J4∗ ∞ 1 20 Yes
J5∗ ∞ 1 ∞ No
J6∗ 50 1 20 Yes
We find the following inequalities
J1∗ ≥ J3∗ J1∗ ≤ J4∗ J2∗ ≤ J4∗
J3∗ ≤ J4∗ J3∗ ≤ J5∗ J4∗ ≥ J5∗ J2∗ ≤ J6∗
∗ ∗
J4 ≥ J6
Based on the inequalities we obtain:
J3∗ ≤ J1∗ ≤ J4∗
J2∗ ≤ J6∗ ≤ J4∗
J3∗ ≤ J5∗ ≤ J4∗
MPC Exercise Session – EE4C04 10
5.Computation of MPC controller
Consider a LTI system given in the state space description
x(k + 1) = A x(k) + B1 e(k) + B3 v(k)
y(k) = C1 x(k) + D11 e(k)
z(k) = C2 x(k) + D21 e(k) + D23 v(k)
where A = −2, B1 = 2, B3 = 1, C1 = −1, D11 = 1, C2 = 3, D21 = 1, and
D23 = 1. Note that there is no external input (w = 0). A performance index is defined as
NX−1
T
min J(ṽ, k) = min ẑ (k + j|k)ẑ(k + j|k) . (4)
ṽ(k) ṽ(k) j=0
There are no constraints.
1. Compute the poles of the closed loop for N = 1. Is the closed loop stable?
2. Using MATLAB, compute the poles of the closed loop for N = 3. Is the closed loop
stable?
3. Using MATLAB, compute the poles of the closed loop for N = 3 with a control horizon
Nc = 1. Is the closed loop stable?
Solution:
T =D
1. For N = 1 we obtain: Ev = 1, Γ̄ = 1, D̃23 23 = 1
and C̃2 = C2 = 3. The optimal control law is given by
T Γ̄D̃ )−1 D̃ T Γ̄C̃ = 3
F = Ev (D̃23 23 23 2
And so
A − B3 F = −2 − 1 · 3 = −5
−1
A − B1 D11 C1 = −2 − 2 · 1 · (−1) = 0
MPC Exercise Session – EE4C04 11
There is a closed-loop pole in −5 (outside the unit circle), so system is
unstable.
2. For N = 3 we obtain: Ev = 1 0 0 , Γ̄ = I ,
C2 3
C̃2 = C2 A = −6
C2 A2 12
D21 1
D̃21 = C2 B1 = 6
C2 AB1 −12
D23 0 0
D̃23 = C2 B3 D23 0
C2 AB3 C2 B3 D23
1 0 0
= 3 1 0
−6 3 1
The optimal control law is given by
T −1 T
F = Ev (D̃23 Γ̄D̃23 ) D̃23 Γ̄C̃2
T −1
1 0 0 1 0 0
= 1 0 0 3 1 0 3 1 0
−6 3 1 −6 3 1
T
1 0 0 3
× 3 1 0 −6
−6 3 1 12
MPC Exercise Session – EE4C04 12
−1
46 −15 −6 −87
= 1 0 0 −15 10 3 30
−6 3 1 12
3
= 1 0 0 −15
75
=3
A − B3 F = −2 − 1 · 3 = −5
−1 C = −2 − 2 · 1 · (−1)0
A − B1 D11 1
3. For Nc = 1 we obtain the constraint
0 1 0
ṽ = D̃33 ṽ = 0
0 0 1
and so
0
C̃3 = D̃31 =
0
(In this example there is no D̃32 ). First we compute:
0 0 1
r r⊥
D̃33 = 1 0 , D̃33 = 0
0 1 0
r = I and D̃ D̃ r⊥ = 0.)
(check that D̃33 D̃33 33 33
MPC Exercise Session – EE4C04 13
Now
r⊥ )T D̃ T Γ̄D̃ D̃ r⊥ −1 (D̃ r⊥ )T D̃ T Γ̄
Ξ= (D̃33 23 23 33 33 23
−1
1 3 −6 1 0 0 1
= 1 0 0 0 1 3 3 1 0 0
0 0 1 −6 3 1 0
1 3 −6
× 1 0 0 0 1 3
0 0 1
= (46)−1
1 3 −6
F = −Ev D̃33 r⊥ ΞD̃ D̃ r C̃ − D̃ r⊥ ΞC̃ − D̃ r C̃
23 33 3 33 2 33 3
r⊥ ΞC̃
= Ev D̃33 2
1 3
=− 1 0 0 0 1/46 3/46 −6/46 −6
0 12
= 3/46 − 18/46 − 71/46
= −85/46
= −1.8478
A − B3 F = −2 − 1 · (−1.8478) = −0.1522
The system is stable.
✷
MPC Exercise Session – EE4C04 14
6. Tuning
We design a GPC controller for the following system:
y(k) − 0.6 y(k − 1) + 0.05 y(k − 2) = 3u(k) − 1.1 u(k − 1) + e(k) − 0.5 e(k − 1)
Find the initial setting for the tuning parameters N , Nm and Nc .
Solution:
The transfer function is given by
3 z 2 − 1.1z
G(z) =
(z − 0.6z + 0.05)
Step response:
−1 z
s(k) = Z (G(z) )
z−1
3z 3 − 1.1z 2
= Z −1 (
z 3 − 1.6z 2 + 0.65z − 0.05
38 −1 z 1 z 2 −1 z
= Z ( ) − Z −1 ( )− Z ( )
9 z−1 2 z−1 90 z−1
= 4.2222 − 0.5 · 0.5k − 0.0222 · 0.1k
The settling time ts is the smallest number k for which holds
|0.5 · 0.5k + 0.022 · 0.1k | ≤ 0.05 ∗ 4.222 .
We find ts = 2. This means that the initial setting for the prediction horizon
is: 3 ≤ N ≤ 4. There is no delay or inverse response, so with d = 0 we find
Nm = d + 1 = 1. Finally the IIO system will be a third-order system, so
Nc = 3.
✷
MPC Exercise Session – EE4C04 15