Intro Control
Intro Control
[Link]/~bemporad/intro_control_course.html
throttle engine
position torque
thrusters attitude
reactant
concentration/
temperature
motor vertical
vessel voltage position
concentration/
temperature
asset portfolio
quantities wealth task quality
allocation of service
raw items
materials sold
• The way the system evolves over time is called the dynamics of the system.
4. Control (“How to make the system behave autonomously the way I want ?”)
(
ẋ1 (t) = x2 (t) velocity = derivative of traveled space
By inspection, the nth -order ODE = 1st -order linear system of ODEs
Z t
At
x(t) = e x0 + eA(t−τ ) Bu(τ )dτ
| {z }
natural response | {z }
0
forced response
MATLAB
A2 t 2 An t n E=expm(A*t)
e At
≜ I + At + + ... + + ...
2 n!
(Moler, Van Loan, 2003) Python
from [Link] import expm
E=expm(A*t)
©2021 A. Bemporad - ``Identification, Analysis, and Control of Dynamical Systems'' 9
State vector
• Given x(0) and u(t), ∀t ∈ [0, T ], Lagrange’s formula allows us to compute x(t)
and y(t), ∀t ∈ [0, T ]
• Therefore, by knowing the initial state x(0) we can neglect all past history
u(−t), x(−t), ∀t ≥ 0
• The dimension n of the state x(t) ∈ Rn is called the order of the system
• Characteristic equation of A:
det(λI − A) = 0
• Characteristic polynomial of A:
• Nonlinear systems (
ẋ(t) = f (x(t), u(t))
y(t) = g(x(t), u(t))
where f : Rn+m → Rn , g : Rn+m → Rp are (arbitrary) nonlinear functions
Definition
A state xr ∈ Rn and an input ur ∈ Rm are an equilibrium pair if for initial
condition x(0) = xr and constant input u(t) ≡ ur the state remains constant:
x(t) ≡ xr , ∀t ≥ 0.
Definition
The equilibrium state xr is stable if for each initial conditions x(0) “close
enough” to xr , the corresponding trajectory x(t) remains near xr for all t ≥ 0.
Math definition: ∀ϵ > 0 ∃δ > 0 : ∀x(0) such that ∥x(0) − xr ∥ < δ ⇒ ∥x(t) − xr ∥ < ϵ, ∀t ≥ 0.
x2(t)
0.2
0
x2(t)
0.2
x (t)
0
0 −0.2
2
−0.2
−0.2 −0.4
−0.4
−0.4 −0.6
−0.6
−0.6 −0.8
−0.8
−0.8 −1
−1
−1 −1 −0.8 −0.6 −0.4 −0.2 0 0.2 0.4 0.6 0.8 1
−1 −0.8 −0.6 −0.4 −0.2 0 0.2 0.4 0.6 0.8 1 x1(t)
−1 −0.8 −0.6 −0.4 −0.2 0 0.2 0.4 0.6 0.8 1 x1(t)
x1(t)
unstable
stable equilibrium asymptotically
equilibrium
stable equilibrium
1
0.6
x1 2
0.5 0.4 x1
x2 0.2 0
0
x2
0 −2
−0.2
−4
−0.5
−0.4
−6 x1
−0.6
−1
0 0.5 1 1.5 2 2.5 3 3.5 4
−0.8
−8 x2
0 0.5 1 1.5 2 2.5 3 3.5 4
−10
0 0.2 0.4 0.6 0.8 1 1.2 1.4 1.6 1.8 2
dx −2x1 (t) − 4x2 (t) dx −x1 (t) − 2x2 (t)
= = dx 2x1 (t) − 2x2 (t)
dt 2x1 (t) + 2x2 (t) dt 2x1 (t) − x2 (t) =
dt x1 (t)
– stable if a ≤ 0
4
3.5
a>0
x(t)
2.5
1.5
x0
1
a=0
0.5
xr a<0
0
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
t
The stability properties of a linear system only depend on the real part of
the eigenvalues of matrix A
□
1 If A is not diagonalizable, it can be transformed to Jordan form. In this case the natural response
x(t) contains modes tj eλt , j = 0, 1, . . . , alg. multiplicity - geom. multiplicity
˙
∆x(t) = ẋ(t) − ẋr = f (x(t), u(t))
= f (∆x(t) + xr , ∆u(t) + ur )
∂f ∂f
≈ (xr , ur ) ∆x(t) + (xr , ur ) ∆u(t)
∂x
| {z } |∂u {z }
A B
• Similarly
∂g ∂g
∆y(t) ≈ (xr , ur ) ∆x(t) + (xr , ur ) ∆u(t)
|∂x {z } |∂u {z }
C D
where ∆y(t) ≜ y(t) − g(xr , ur ) is the perturbation of the output from its
equilibrium
• The perturbations ∆x(t), ∆y(t), and ∆u(t) are (approximately) ruled by the
linearized system
(
˙
∆x(t) = A∆x(t) + B∆u(t)
∆y(t) = C∆x(t) + D∆u(t)
u(t) = mg
h
m
h
m
u(t) = mg
1
• <λ1,2 < 0 ⇒ ẋ = Ax asymptotically
0.5
stable
y(t)
0
xr = [ 00 ] is also an asymptotically −1
2
• λ1 < 0, λ2 > 0 ⇒ ẋ = Ax unstable 1
y(t)
0
• by Lyapunov’s indirect method −1
xr = [ π0 ] is also an unstable −2
−4
0 2 4 6 8 10
t
– V (x) = x41 + sin2 (x2 ) is locally positive definite and globally positive semi-definite
• It is easy to check that V̇ (x1 , x2 ) is negative definite if kxk22 = x21 + x22 < 2
√
• Since for any Bϵ with 0 < ϵ < 2 the hypotheses of Lyapunov’s theorem are
satisfied, x = 0 is an asymptotically stable equilibrium
√
• Any Bϵ with 0 < ϵ < 2 is a also a domain of attraction
A′ P + P A = −Q
Python
MATLAB
import control as ctrl
P=lyap(A’,Q)
P=lyap([Link](),Q)
(note transposition of matrix A !)
3.5
3
3
2.5 2.5
2
2
1.5
1.5 1
0 1 2 3 4 5 0 1 2 3 4 5
time t time t
2.5
a>1
2
x(k)
1.5
a=1
1
0.5
0<a<1
0
0 1 2 3 4 5 6 7 8 9 10
k
• The solution is
X
k−1
x(k) = Ak x 0 + Ai Bu(k − 1 − i)
| {z }
i=0
natural response | {z }
forced response
• If matrix A is diagonalizable, A = T ΛT −1
λ1 λk 0 ... 0
0 ... 0 1
0 λ2 ... 0 0 λk2 ... 0
Λ = .. .. . . .. ⇒ Ak = T . . . . T −1
. . . . . . .
. . . ..
0 0 ... λn 0 0 ... λk
n
X
n
x(k) = Ak x0 = T Λk T −1 x0 = αi λki vi
i=1
where
– λi = eigenvalues of A
– vi = eigenvectors of A
– αi = coefficients that depend on the initial condition x(0)
" α1 #
α= .. = T −1 x(0), T = [v1 . . . vn ]
.
αn
• k = year counter
• ρ= interest rate
• x(k)= wealth at the beginning of year k
• u(k)= money saved at the end of year k
• x0 = initial wealth in bank account
(
Discrete-time model: x(k + 1) = (1 + ρ)x(k) + u(k)
x(0) = x0
Stored amount of money (keur)
x0 10 ke 50
45
u(k) 5 ke 40
35
ρ 10 % 30
x(k)
25
20
15
1 − (1.1) k 10
1 − 1.1 0
0 0.5 1 1.5 2 2.5
k (years)
3 3.5 4 4.5 5
• Problem statement:
– At each month k , S purchases the quantity u(k) of raw material
– A fraction δ1 of raw material is discarded, a fraction α1 is shipped to producer P
– A fraction α2 of product is sold by P to retailer R, a fraction δ2 is discarded
– Retailer R returns a fraction β3 of defective products every month
and sells a fraction γ3 to customers
• Mathematical model:
k month counter
x1 (k + 1) = (1 − α1 − δ1 )x1 (k) + u(k)
x1 (k) raw material in S
x2 (k + 1) = α1 x1 (k) + (1 − α2 − δ2 )x2 (k) x2 (k) products in P
+β3 x3 (k) x3 (k) products in R
x3 (k + 1) = α2 x2 (k) + (1 − β3 − γ3 )x3 (k) u(k) raw material purchased by S
y(k) = γ3 x3 (k) y(k) products sold to customers
k Year
xi (k) Number of students enrolled in year i at year k, i = 1, 2, 3
u(k) Number of freshmen at year k
y(k) Number of graduates at year k
αi promotion rate during year i, 0 ≤ αi ≤ 1
βi failure rate during year i, 0 ≤ βi ≤ 1
γi dropout rate during year i, γi = 1 − αi − βi ≥ 0
• Simulation
80
α1 = .60 β1 = .20 60
40
α2 = .80 β2 = .15 20
α3 = .90 β3 = .08 0
2020 2022 2024 2026 2028 2030 2032 2034 2036 2038 2040
110
100
k→∞ 90
2020 2022 2024 2026 2028 2030 2032 2034 2036 2038 2040
MATLAB Python
• There are infinitely many state-space realizations
tf2ss ctrl.tf2ss
• nth -order difference equations are very useful for digital filters, digital
controllers, and to reconstruct models from data (system identification)
• We will see later that (A, B) in controllable canonical form is a reachable pair,
(A, C) in observable canonical form is an observable pair
• From a given initial condition x(0) and input sequence {u(k)}∞k=0 one can
predict the entire sequence of states x(k) and outputs y(k), ∀k ∈ N
• The state x(0) summarizes all the past history of the system
• The dimension n of the state x(k) ∈ Rn is called the order of the system
• The system is called proper (or strictly causal) if D = 0
• General multivariable case:
A ∈ Rn×n
x(k) ∈ Rn
B ∈ Rn×m
u(k) ∈ Rm
C ∈ Rp×n
y(k) ∈ Rp
D ∈ Rp×m
Definition
A state xr ∈ Rn and an input ur ∈ Rm are an equilibrium pair if for initial
condition x(0) = xr and constant input u(k) ≡ ur , ∀k ∈ N, the state remains
constant: x(k) ≡ xr , ∀k ∈ N.
Definition
The equilibrium state xr is stable if for each initial conditions x(0) “close
enough” to xr , the corresponding trajectory x(k) remains close to xr for all
k∈N
Analytic definition: ∀ϵ > 0 ∃δ > 0 : ∥x(0) − xr ∥ < δ ⇒ ∥x(k) − xr ∥ < ϵ, ∀k ∈ N.
3
– unstable if |a| > 1
2.5
– stable if |a| ≤ 1
2
– asymptotically stable if |a| < 1 a>1
x(k) 1.5
x0 a=1
1
0.5 0<a<1
xr a=0
0
0 2 4 6 8 10
k
©2021 A. Bemporad - ``Identification, Analysis, and Control of Dynamical Systems'' 50
Stability of discrete-time linear systems
The natural response of x(k + 1) = Ax(k) + Bu(k) is x(k) = Ak x0 , so stability
only depend on A. We therefore talk about system stability
Theorem
Let λ1 , . . ., λm , m ≤ n be the eigenvalues of A ∈ Rn×n .
The system x(k + 1) = Ax(k) + Bu(k) is
• asymptotically stable iff |λi | < 1, ∀i = 1, . . . , m
• (marginally) stable if |λi | ≤ 1, ∀i = 1, . . . , m, and the eigenvalues with
unit modulus have equal algebraic and geometric multiplicity a
• unstable otherwise(in particular, if ∃ i such that |λi | > 1)
a Algebraic multiplicity of λ = number of coincident roots λ of det(λI − A). Geometric
i i
multiplicity of λi = number of linearly independent eigenvectors vi , Avi = λi vi
|λk | = ρk |ejkθ | = ρk
2 If A is not diagonalizable, it can be transformed to Jordan form. In this case the natural response
x(t) contains modes kj λk , j = 0, 1, . . . , alg. multiplicity − geom. multiplicity
u(k)
x3(k) x2(k) x1(k) y(k)
x1 (k + 1) = x2 (k)
0 1 0 0
x (k + 1) = x3 (k) x(k + 1) = 0 0 1 x(k) + 0 u(k)
2
0 0 0 1
x3 (k + 1)
= u(k)
[ ]
y(k) = x1 (k) y(k) = 1 0 0 x(k)
• Natural response: A3 x(0) = 0 for all x(0) ∈ R3
1.5
0.5
0.5
instant, respectively
−1
−0.5
−1.5
−1 −2
0 2 4 6 8 10 0 2 4 6 8 10
time t time t
• Since the input u(t) is piecewise constant, u(σ) ≡ ū(k), kTs ≤ σ < (k + 1)Ts .
By setting τ = σ − kTs we get
Z !
Ts
x((k + 1)Ts ) = eATs x(kTs ) + eA(Ts −τ ) dτ Bu(kTs )
0
and hence
Z !
Ts
ATs A(Ts −τ )
x̄(k + 1) = e x̄(k) + e dτ B ū(k)
0
0.2
−0.4
sys=ss(A,B,C,D); sys=[Link](A,B,C,D) 0 1 2 3 4 5
time t
6 7 8 9 10
sysd=c2d(sys,Ts); sysd=ctrl.c2d(sys,Ts) 1
u(t), u(kTs)
−0.5
−1
rise time
y(t), y(kTs)
1 1
90 % 0.8
0.9
0.6
0.8
0.4
0.7
0.2
0.6 0
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5
output
0.5
time t
u(t), u(kT )
0.4
s
2
0.3
1.5
0.2
1
10 %
0.1
0.5
rise time
0
0 1 2 3 4 5 6 7 8 9 10 0
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5
time t
time t
Ts TTs
t
kT
kT s
(k+1)T
(k + 1)Ts Leonhard Paul Euler
(1707-1783)
Ā ≜ I + Ts A, B̄ ≜ Ts B, C̄ ≜ C, D̄ ≜ D
Tsn An
• e Ts A = I + T s A + . . . + n!
+ . . . Euler’s method ≈ exact sampling for Ts → 0
Discrete-time model
( √ p
h̄(k + 1) = h̄(k) − Ts a 2g
h̄(k) + TAs ū(k)
√ p A
q̄(k) = a 2g h̄(k) (Torricelli's law)
u 6
h 2
1
continuous time
q Euler approximation
0
0 5 10 15 20 25 30
time (s)
• N -steps explicit forward Euler method: given x̄(k), ū(k), execute the following
steps
1. x = x̄(k), Ā = I , B̄ = 0
2. for n=1,2,…,N do
Ts ∂f
• Ā ← (I + N ∂x
(x, ū(k))Ā
Ts ∂f Ts ∂f
• B̄ ← (I + N ∂x
(x, ū(k))B̄ + N ∂u
(x, ū(k))
• x ← x + TNs f (x, ū(k))
3. end
4. return x̄(k + 1) ≈ x and matrices Ā, B̄ such that x̄(k + 1) ≈ Ax̄(k) + B ū(k).
• Property: the difference between the state x̄(k + 1) and its approximation x
computed by the above iterations satisfies kx̄(k + 1) − x)k = O TNs
• Advantage: simpler to compute than exponential matrix, without too much loss
of approximation quality
Definition
2
1.4
1.2
f(k)
∞
X
1
−k
0.8
0.4
k=0 0.2
0
−2 0 2 4 6 8 10
• Discrete impulse
0 6 0
if k =
f (k) = δ(k) ≜ ⇒ Z[δ] = F (z) = 1
1 if k = 0
• Discrete step
0 if k < 0 z
f (k) = 1I(k) ≜ ⇒ Z[1I] = F (z) =
1 if k ≥ 0 z−1
• Geometric sequence
z
f (k) = ak 1I(k) ⇒ Z[f ] = F (z) =
z−a
• Linearity
• Forward shift3
Z[f (k + 1) 1I(k)] = zZ[f ] − zf (0)
• Multiplication by k
d
Z[kf (k)] = −z Z[f ]
dz
Definition
The transfer function of the discrete-time linear system (A, B, C, D) is
that is the ratio between the Z-transform Y (z) of the output and the Z-
transform U (z) of the input signals for the initial state x0 = 0
MATLAB Python
sys=ss(A,B,C,D,Ts); sys=[Link](A,B,C,D,Ts)
G=tf(sys) G=[Link](sys)
©2021 A. Bemporad - ``Identification, Analysis, and Control of Dynamical Systems'' 67
Discrete-time transfer function
u(k) y(k) U (z) Y (z)
A; B; C; D G(z)
x0 = 0
0.5
x(k + 1) = 1
0 −0.5 x(k) + [ 01 ] u(k)
Example: The linear system
y(k) = [ 1 −1 ] x(k)
The transfer function does not depend Transfer function: Transfer function:
-z + 1.5 -z + 1.5
on the input u(k), it is only a property ————— —————
z^2 - 0.25 z^2 - 0.25
of the linear system.
bn z −n + bn−1 z −n+1 + · · · + b1 z −1
G(z) =
an z −n + an−1 z −n+1 + · · · + a1 z −1 + 1
b1 z n−1 + · · · + bn−1 z + bn
=
z n + a1 z n−1 + · · · + an−1 z + an
• Consider the impulsive input u(k) = δ(k), U (z) = 1. The corresponding output
y(k) is called impulse response
• Therefore the impulse response coincides with the inverse Z-transform g(k) of
the transfer function G(z)
Example (integrator:)
2 2
1 1
u(k)
y(k)
u(k) = δ(k) h i
0 0
Z −1 1
= 1I(k − 1)
−1 −1
y(k) = z−1 −2 −2
−2 0 2 4 6 8 10 −2 0 2 4 6 8 10
k k
C Adj(zI − A)B
C(zI − A)−1 B + D = +D
det(zI − A)
• Well, not always ... There might be a zero/pole cancellation (we will see later)
• DC gain:
h 1 0 0 i h .2
0 0 −1 1 i h i
[ 0 0 .9 ] 010 −.6 .15 0 0 ≈ 0.69
001 0 .8 .08 0
• Transfer function: G(z) = 0.432
z −0.43z +0.058z−0.0024
3 2 , G(1) ≈ 0.69
y(k)
35
30
MATLAB Python
A=[b1 0 0; a1 b2 0; 0 a2 b3]; A=[[b1, 0, 0],[a1, b2, 0],[0, a2, b3]]
25
B=[1;0;0]; B=[[1],[0],[0]]
20 C=[0 0 a3]; C=[0, 0, a3]
D=[0]; D=[0]
15
sys=ss(A,B,C,D,1); sys=[Link](A,B,C,D,1)
10 dcgain(sys) [Link](sys)
5
0.6905 0.6905
0
2006 2008 2010 2012 2014 2016
step k
r + e Z t ++ u y
Process
1
Kp
-
e(⌧ )d⌧
Ti 0
+
de(t)
Td
dt
Controller
• In digital (=discrete-time) form with sampling time Ts , the PID controller takes
the following form
Kp T s
I(k + 1) = I(k) + (r(k) − y(k)) forward differences
Ti
Td Kp Td N
D(k) = D(k − 1) − (y(k) − y(k − 1))
Td + N T s Td + N T s
backward differences
• The control law does not exploit the knowledge of the model of the process
X
k−1
x 2 = Ak x 1 + Aj Bu(k − 1 − j)
j=0
RU = X
Proof:
(⇒) Assume (A, B) reachable, choose x1 = 0 and x2 = x. Then ∃k ≥ 0 such
that
X
k−1
x= Aj Bu(k − 1 − j)
j=0
∂L
∂U = U − Rk′ λ = 0 MATLAB
⇒ U ∗ = Rk′ (Rk Rk′ )−1 ·X U=pinv(Rk)*X
∂L
= X − Rk U = 0 | {z }
∂λ Python
Rk# = pseudoinverse from [Link] import pinv
U=pinv(Rk)@X
• If the system is completely reachable, we have seen that we can bring the state
vector from any value x(0) = x1 to any other value x(n) = x2
Definition
A system x(k + 1) = Ax(k) + Bu(k) is controllable to the origin in k steps
if ∀x0 ∈ Rn there exists a sequence u(0), u(1), . . ., u(k − 1) ∈ Rm such that
Pk−1
0 = Ak x 0 + j=0 Aj Bu(k − 1 − j)
Im(An ) ⊆ Im(R)
Definition
A linear system x(k + 1) = Ax(k) + Bu(k) is called stabilizable if can be
driven asymptotically to the origin
• Since T −1 Avi are the new coordinates of Avi , the first n − nc components of
T −1 Avi are zero
• Let x = [ xxuc
c
] be the coordinates of the state vector in the new coordinate
system, xuc ∈ Rn−nc , xc ∈ Rnc
• We have that xuc (k) = Akuc xuc (0), so xuc (k) does not depend on u(k)
• Auc asymptotically stable (all eigenvalues with negative real part) is also a
necessary and sufficient condition for stabilizability
state feed
K back
K
!"#$%&'"##()$*$+%,
Theorem
(A, B) ”reachable” (rank B AB . . . An−1 B = n) ⇒ the eigenvalues of
(A + BK) can be decided arbitrarily.
• As K = [k1 . . . kn ], we have
0
.
. In−1
A + BK =
.
0
−(a0 − k1 ) −(a1 − k2 ) ... −(an−1 − kn )
a0 − k1 = d0 , a1 − k2 = d1 , . . . , an−1 − kn = dn−1
Procedure
If (A, B) is in controllable canonical form, the feedback gain
h i
K = a0 − d0 a1 − d1 . . . an−1 − dn−1
where
a1 a2 ... an−1 1
a2 a3 ... 1 0
T = R
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
a 1 0 ... 0
n−1
1 0 0 ... 0
−1
• Explanation: a matrix M and T M T have the same eigenvalues
MATLAB
Ackermann’s formula
K=-acker(A,B,P);
K = −[0 . . . 0 1][B AB . . . An−1 B]−1 pd (A) K=-place(A,B,P);
Python
where P = [λ1 λ2 . . . λn ] are the desired
K=-[Link](A,B,P)
closed-loop poles K=-[Link](A,B,P)
30
20
10
0
2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022
90
85
80
75
70
2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022
? ˆ
x(k) ./$/-)-./&%$/-
Definition
The pair of states x1 6= x2 ∈ Rn is called indistinguishable from the output
y(·) if for any input sequence u(·)
• Define
y(0) − Du(0)
C
y(1) − CBu(0) − Du(1)
CA ..
Θ=
..
Y =
.
. X
n−2
CAn−1 y(n − 1) − CAj Bu(n − 2 − j) − Du(n − 1)
| {z } j=1
n × n matrix | {z }
n-th dimensional vector
Y = Θx0
Pk−1
• Knowing x0 , we know x(k) = Ak x0 + i=0 Ai Bu(k − 1 − i) for all k ≥ 0
• Then, for linear systems the observability property only depends on A and C
x(0) = Θ−1 Y
• To close the control loop at time k it is enough to know the current x(k)
X
k−1
x(k) = Ak Θ−1 Y + Ai Bu(k − 1 − i)
i=0
• Question: Can we determine the current state x(k) even if the system is not
completely observable?
X
k−1
k
x̂(k) = A x0 + A x̄ + k
Aj Bu(k − 1 − j)
j=1
• x̂(k) coincides with x(k) if and only if x̄ ∈ ker(Ak ). Because this must hold for
any x̄ ∈ ker(Θk ), we have the following
Lemma
Definition
• Why are the eigenvalues of Auo not appearing in the transfer function G(z) ?
• The evolution of xo (k) is not affected by the unobservable states xuo (k)
X
k−1
xo (k) = Ako xo (0) + Aio Bo u(k − 1 − i)
i=0
so the output y(k) = Co xo (k) + Du(k) does not depend at all on Auo !
A,B ˆ
x(k)
./$/-)-./&%$/-
A,B ˆ
x(k)
./$/-)-./&%$/-
• The dynamics of the real system and of the numerical copy are
A,B ˆ
x(k)
./$/-)-./&%$/-
The estimation error is x̃(k) = Ak (x(0) − x̂(0)). This is not ideal, because
• The dynamics of the estimation error are fixed by the eigenvalues of A and
cannot be modified
• The estimation error vanishes asymptotically if and only if A is asymptotically
stable
• Note that we are not exploiting y(k) to compute the state estimate x̂(k) !
./$/-),1.-+2-+
./$/-),1.-+2-+
MATLAB Python
where P = [λ1 λ2 . . . λn ] =
L=acker(A’,C’,P)’; L=[Link](A.T,C.T,p).T
L=place(A’,C’,P)’; L=[Link](A.T,C.T,p).T desired observer eigenvalues
80
true state
estimator L1
60 estimator L2
estimator L3 response from initial conditions
40
x(0) = −1 0
1 , x̂(0) = [ 0 ] for
20 u(k) ≡ 0.1 for different choices of
the observer poles
0
−20
0 10 20 30 40
time (s)
©2021 A. Bemporad - ``Identification, Analysis, and Control of Dynamical Systems'' 120
Dynamic compensators
Potential issues in state feedback control
• Measuring the entire state vector may be too expensive (many sensors)
Can we use the estimate x̂(k) instead of x(k) to close the loop ?
v(k) + + ˆ
x(k) .0$0-
K -.0&%$0,+
!"#$%&'),/0*/0)1--!2$'3)',#0+,((-+
" #
h i x(k)
y(k) =
C 0
x̃(k)
©2021 A. Bemporad - ``Identification, Analysis, and Control of Dynamical Systems'' 123
Closed-loop dynamics
• The transfer function from v(k) to y(k) is
" #−1 " #
h i zI − A − BK BK B
G(z) = C 0
0 zI − A + LC 0
" #" #
h i (zI − A − BK)−1 ⋆ B
= C 0
0 (zI − A + LC)−1 0
N (z)
= C(zI − A − BK)−1 B =
DK (z)
• Even if we substituted x(k) with x̂(k), the input-output behavior of the
closed-loop system didn’t change !
The closed-loop poles can be assigned arbitrarily using dynamic output feed-
back, as in the state feedback case
The closed-loop transfer function does not depend on the observer gain L
y(0) = Cx(0)
h i h x(0) i
−BK
y(1) = C 0 A+BK 0 A−LC x̃(0)
h ih i
(A+BK)x(0)−BK x̃(0)
= C 0 (A−LC)x̃(0)
= C(A + BK)x(0) − CBK x̃(0)
h i h i
−BK x(1)
y(2) = C 0 A+BK 0 A−LC x̃(1)
• Intuitively, if x̂(k) is a poor estimate of x(k) then the control action will also be
poor
• Fact: The choice of L is very important for determining the sensitivity of the
closed-loop system with respect to input and output noise
MATLAB MATLAB
K=1; beta=.3; alpha=1; % Closed-loop system, state=[x;xhat]
G=tf(K,[1 beta alpha 0]);
bigA=[A,B*K;L*C,A+B*K-L*C];
ts=0.5; % sampling time bigB=[B;B];
Gd=c2d(G,ts); bigC=[C,zeros(1,3)];
sysd=ss(Gd); bigD=0;
[A,B,C,D]=ssdata(sysd); clsys=ss(bigA,bigB,bigC,bigD,ts);
y(k) y(k)
2 3
2.5
1.5
2
1
1.5
0.5
1
0
0.5
−0.5 0
0 5 10 15 20 0 5 10 15 20
time (s) time (s)
driving x(k) towards the origin while minimizing the performance index
X
N −1
′
J(x(0), U ) = x (N )QN x(N ) + x′ (k)Qx(k) + u′ (k)Ru(k) quadratic cost
k=0
where Q = Q′ 0, R = R′ 0, QN = Q′N 06
6 For a matrix Q ∈ Rn×n , Q ≻ 0 means that Q is a positive definite matrix, i.e., x′ Qx > 0 for all
we obtain
1 ′ 1
J(x(0), U ) = U HU + x(0)′ F U + x(0)′ Y x(0)
2 2
where H = H ′ 0 is a positive definite matrix
• The optimizer U ∗ is obtained by zeroing the gradient
0 = ∇U J(x(0), U ) = HU + F ′ x(0)
u∗ (0)
u∗ (1)
−→ U ∗ = = −H −1 F ′ x(0)
..
.
∗
u (N − 1)
• The solution
u∗ (0)
u∗ (1)
U∗ =
.. = −H −1 F ′ x(0)
.
u∗ (N − 1)
is an open-loop one: u∗ (k) = fk (x(0)), k = 0, 1, . . . , N − 1
• Solving over [0, k1 ] with terminal weight equal to the optimal cost-to-go from k1
to N at x(k1 ) is the same as solving over [0, T ]
1. Initialization: P (N ) = QN
2. For k = N, . . . , 1, compute recursively the following
matrix
3. Define
Result
Let (A, B) be a stabilizable pair, R 0, Q 0. There exists a unique solution
P∞ of the algebraic Riccati equation (ARE)
P∞ = A′ P∞ A + Q − A′ P∞ B(B ′ P∞ B + R)−1 B ′ P∞ A
such that the optimal cost is V ∞ (x(0)) = x′ (0)P∞ x(0) and the optimal con-
trol law is the constant linear state feedback u(k) = KLQR x(k) with
MATLAB
Python E = closed-loop poles
P∞ = dare(A,B,Q,R)
P∞ ,E,Km=[Link](A,B,Q,R)
[-K∞ ,P∞ ] = dlqr(A,B,Q,R) = eigenvalues of (A + BKLQR )
K∞ =-Km
[-K∞ ,P∞ ,E] = lqr(sysd,Q,R)
©2021 A. Bemporad - ``Identification, Analysis, and Control of Dynamical Systems'' 143
Linear quadratic regulation
• Go back to Riccati iterations: starting from P (∞) = P∞ and going backwards
we get P (j) = P∞ , ∀j ≥ 0
• Accordingly, we get
Intuitively: the minimum cost x′ (0)P∞ x(0) is finite ⇒ y(k) → 0 and u(k) → 0.
y(k) → 0 implies that the observable part of the state → 0. As u(k) → 0, the unobservable states
remain undriven and go to zero spontaneously (=detectability condition)
K = [−0.8166 − 1.7499]
0.5
−0.5
0 2 4 6 8 10 12 14 16 18 20
ρ = 10 (blue line)
input u(k) K = [−0.2114 − 0.7645]
1
0.5
−0.5
ρ = 1000 (green line)
K = [−0.0279 − 0.2505]
−1
0 2 4 6 8 10 12 14 16 18 20
Rudolf E. Kalman∗
(1930–2016)
∗ R.E. Kalman receiving the Medal of Science from the President of the USA on October 7, 2009
• The diagonal terms of R are related to how noisy are output sensors
• After all, Q and R are the tuning knobs of the observer (similar to LQR)
• The “larger” is R with respect to Q the “slower” is the observer to converge (L,
M will be small)
• On the contrary, the “smaller” is R than Q, the more precise are considered the
measurments, and the “faster” observer will be to converge
• The EKF is in general not optimal and may even diverge, due to linearization.
But is the de-facto standard in nonlinear state estimation
©2021 A. Bemporad - ``Identification, Analysis, and Control of Dynamical Systems'' 154
LQG control
• Linear Quadratic Gaussian (LQG) control combines an LQR control law and a
stationary Kalman predictor/filter
• Consider the stochastic dynamical system
• the pair (A, B) is reachable and the pair (A, Cq ) with Cq such that
QLQ = Cq Cq′ is observable (here Q is the weight matrix of the LQ controller)
• the pair (A, Bq ), with Bq s.t. QKF = Bq Bq′ , is stabilizable, and the pair (A, C) is
observable (here Q is the covariance matrix of the Kalman predictor/filter)
2. Determine the optimal LQR strategy assuming the state accessible, and find the
optimal gain KLQR
v(k) + + ˆ
x(k) 3$(%$#
KLQR 4(2-+
/01)',#2+,((-+
• Often a dynamical model can be difficult to obtain due to the complexity of the
process, whose dynamics may be even (partially or completely) unknown
Lecture based on
[1] L. Ljung, “System Identification,” Control Systems Handbook (W. Levine ed.), CRC Press, pp. 1033–1054, 1995
[2] L. Ljung, “System Identification: Theory for the User,” Prentice Hall, 1987
• White box: model structure based on first principles (e.g., Newton’s law), model
parameters estimated from measured data
• Grey box: model structure partially known from first principles, the rest is
reconstructed from data
• Black box: model structure and its parameters completely unknown, they are
only estimated from I/O data
u(t) ? y(t)
dynamical process
identification ^
G(z)
algorithm
• Excite the process with a step u(t) = 1I(t), record output response y(t)
y(k) = −a1 y(k−1)−...−ana y(k−na )+b1 u(k−nk )+...+bnb u(k−nk −nb +1)+e(k)
with
1 X
N −1
V (θ, Z N ) = (y(k) − ŷ(k|θ))2
y(k)
N
k=0
1 X
N −1
2
= y(k) − φ′ (k)θ
N
k=0 ϕ(k)
or
X
N −1 X
N
φ(k)y(k) = φ(k)φ′ (k)θ
k=0 k=1
MATLAB
θ ∗ =arx(Z N ,[na nb nk ])
• Drawback of (batch) linear regression: if a new data pair u(N ), y(N ) is acquired
hP i−1
′ N
the new matrix k=0 φ(k)φ (k) is required to compute the new optimal
∗
parameter vector θ
we would like to get θ∗ (k) without solving the regression problem from scratch
we get
X
k X
k−1
θ∗ (k) = P (k) φ(j)y(j) = P (k) φ(j)y(j) + φ(k)y(k)
j=0 j=0
= P (k) P −1 (k − 1)θ∗ (k − 1) + φ(k)y(k)
= P (k) (P −1 (k) − φ(k)φ′ (k))θ∗ (k − 1) + φ(k)y(k)
and therefore
we can apply the Matrix Inversion Lemma to update P (k) recursively and get
P (k − 1)φ(k)φ′ (k)P (k − 1)
P (k) = P (k − 1) −
1 + φ′ (k)P (k − 1)φ(k)
X
k−1
• Let m = dim θ = na + nb . Matrix φ(j)φ′ (j) is not invertible for k < m
j=0
"m−1 #−1
X ′
• We can start the recursions after m steps with P (m − 1) = φ(j)φ (j)
j=0
X
m−1
(if the inverse exists) and θ∗ (m − 1) = P (m − 1)−1 φ(j)y(j)
j=0
©2021 A. Bemporad - ``Identification, Analysis, and Control of Dynamical Systems'' 166
Recursive linear regression
• Alternatively, we can initialize P (−1) = ρ2 I , ρ > 0, and θ∗ (−1) = θ̄
1 Xk
′ 2 1 X
m Xk
2
min 2
kθ − θ̄k 2
2 + y(j) − φ (j)θ = 2
(θ i − θ̄ i ) 2
+ y(j) − φ′ (j)θ
ρ j=0
ρ i=1 j=0
m
X 2 X X
1 1
k
2 k
2
= θ̄i − e′i θ + y(j) − φ′ (j)θ = y(j) − φ′ (j)θ
i=1
ρ ρ j=0 j=−m
• Fit criterion between data and model: How do I best choose the model within
that class (=the parameter vector) ?
• The data set Z N should be as informative as possible to fully identify the model9
1
0.8
0.4
−0.2
MATLAB −0.4
−0.6
» u=idinput(N,’PRBS’); −0.8
−1
0 5 10 15 20 25 30
9 Sinusoidal signals u(t) = sin(ωt) are not good, as only G(jω) would be captured. The input
signal must at least contain as many different frequencies as the order of the chosen structure of
linear models. Step responses are not ideal but ok: |F [1I(t)]| = ω
1
(the Fourier transform of the
continuous-time signal 1I(t)) has in infinite number of frequencies, although decreasing in
amplitude.
v(k) = H(z)e(k)
e(k)
• The overall model is called Box-Jenkins (BJ) model C(z)
D(z)
B(z) C(z)
y(k) = u(k) + e(k) u(k) y(k)
A(z) D(z) B(z) +
+
A(z)
©2021 A. Bemporad - ``Identification, Analysis, and Control of Dynamical Systems'' Tuesday, June 1, 2010
171
Model structure - Special cases
B(z)
y(k) = u(k) + e(k)
A(z)
• This is justified if the source of disturbance enters early in the process, together
with the input
Example: in airplanes, the disturbances from wind blasts create the same kind
of forces on the airplane as the deflections of the control surfaces
e(k)
e(k) C(z)
u(k) y(k) e(k)
B(z) +
+
u(k) +
1 y(k) u(k) +
1 y(k)
+ +
• Let θ collect all the parameters in the transfer functions G(z) and H(z) to be
estimated from data
• Finally, we get
y(k) = 1 − H −1 (z, θ) y(k) + H −1 (z, θ)G(z, θ)u(k) + e(k)
• Besides choosing the model structure (ARX, ARMAX, etc.) we also need to
decide the order of the model, i.e., the number of free parameters to optimize
• A small number of parameters could make the model too simple, and not able to
explain the data
• A large number of parameters could make the model more complex than we
need and overfit the data in Z N , resulting in poor predictions on new data
and to look at
N −1
1 X
(y(k) − ysim (k, θ∗ ))2
N
k=0
(or just observe how much the plots of y(k) and ysim (k, θ ∗ ) differ)
• Ideally the prediction error (or prediction residual) ϵ(k|θ) should be white
noise and uncorrelated with u(k)
−τ −1
NX
1
Rϵ (τ ) = ϵ(k + τ |θ)ϵ(k|θ)
N
k=0
• To test correlation between ϵ(k|θ) and u(k) we compute the sample covariance
N −1
1 X
Rϵu (τ ) = ϵ(k|θ)u(k − τ )
N
k=τ −1
0.1
1 X 2
N −1
di · ln N
ϵ (k|θi∗ ) +
N N
k=0
0.1
−0.2
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5
Time
validation −0.5
−1
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5
Time
• i = 1: ARX(1,1,1) V(θ,Zest)
V(θ,Zval)
• i = 2: ARX(2,2,1)
1.35
• i = 3: ARX(3,3,1) 1.3
• i = 4: ARX(4,4,1) 1.25
• i = 5: ARX(5,5,1) 1.2
• i = 6: ARX(6,6,1) 1.15
1.1
1 1.5 2 2.5 3 3.5 4 4.5 5 5.5 6
Correlation function of residuals. Output y1 Correlation function of residuals. Output y1 Correlation function of residuals. Output y1
1 1 1
0 0 0
Cross corr. function between input u1 and residuals from output y1 Cross corr. function between input u1 and residuals from output y1 Cross corr. function between input u1 and residuals from output y1
0.3 0.3 0.3
0 0 0
• If linear model structures are not able to capture the model well, one should use
nonlinear models, like artificial neural networks, piecewise affine functions,
and other general function approximation methods available in machine
learning (Schoukens, Ljung, 2019)
• In general, the more a-priori knowledge of the process we can exploit (e.g., from
physical principles), the better. Sometimes black-box identification fails
because its very difficult to guess the right model structure