Control Engineering with
Python
Symbols
🐍
Code
🔍
Worked Example
📈
Graph
🧩
Exercise
🏷️
Definition
💻
Numerical Method
💎
Theorem
🧮
Analytical Method
📝
Remark
🧠
Theory
ℹ️
Information
🗝️
Hint
⚠️
Warning
🔓
Solution
🐍 Imports
from numpy import *
from numpy.linalg import *
from scipy.linalg import *
from matplotlib.pyplot import *
from mpl_toolkits.mplot3d import *
from scipy.integrate import solve_ivp
🐍 Streamplot Helper
def Q(f, xs, ys):
X, Y = meshgrid(xs, ys)
v = vectorize
fx = v(lambda x, y: f([x, y])[0 ])
fy = v(lambda x, y: f([x, y])[1 ])
return X, Y, fx(X, Y), fy(X, Y)
ℹ️ Assumption
From now on, we only deal with well-posed systems.
🏷️ Asymptotic
Asymptotic = Long-Term: when
So far, we have given little attention to the properties that
characterize the long-term behavior of dynamical systems. Well-posedness
ensures merely the local (in time) existence of uniqueness of solutions
to an IVP and continuity with respect to the initial condition is only
applicable to solutions defined on a finite (compact) time
intervals.
We will now turn to the study of such properties specifically.
⚠️
Even simple dynamical systems may exhibit
complex asymptotic behaviors.
Lorenz System
But first, we need to realize that dynamical systems, even when they
are governed by a simple, low-dimensional system of equations, may
exhibit very complex asymptotic patterns.
The Lorenz
system is a classical example of such system.
Visualized with Fibre
The solutions of this
system, which are global, have no limit when and don’t blow up either
but instead oscillates forever between two regions of the state space.
This long-term behavior is quantitatively very sensitive to the choice
of the initial condition, making long-term predictions about the system
practically impossible: the system is chaotic.
Visualized with Fibre
Asymptotic patterns of chaotic system are by no means restricted to
this “switching” behavior. The Hadley system is another – even “messier”
– example of chaotic behavior.
Fortunately, many systems behaved more predictabily, and/or can be
controlled so that their asymptotic behavior is more acceptable.
🏷️ Equilibrium
An equilibrium of system is a state such that the maximal solution such that
is global and,
is for any .
💎 Equilibrium
The state is an equilibrium
of
If , then and thus the
(constant) function is a global solution of the IVP and .
Conversely, if , is a global solution of , then .
Stability
About the long-term behavior of solutions.
“Stability” subtle concept,
“Asymptotic Stability” simpler (and stronger),
“Attractivity” simpler yet, (but often too weak).
Attractivity
Context: system with equilibrium .
🏷️ Global Attractivity
The equilibrium is
globally attractive if for every the maximal solution such that
🏷️ Local Attractivity
The equilibrium is
locally attractive if for every close enough to , the maximal solution such that
Technically, an equilibrium
is locally attractive if there is a such that the maximal solution to
the IVP and is global and satisfies when whenever .
🔍 Global Attractivity
The system
is well-posed,
has an equilibrium at .
🐍 Vector field
def f(xy):
x, y = xy
dx = - 2 * x + y
dy = - 2 * y + x
return array([dx, dy])
📈 Stream plot
figure()
x = y = linspace(- 5.0 , 5.0 , 1000 )
streamplot(* Q(f, x, y), color= "k" )
plot([0 ], [0 ], "k." , ms= 20.0 )
axis("square" )
axis("off" )
Your browser does not support the video tag.
🔍 Local Attractivity
The system
is well-posed,
has an equilibrium at .
🐍 Vector field
def f(xy):
x, y = xy
dx = - 2 * x + y** 3
dy = - 2 * y + x** 3
return array([dx, dy])
📈 Stream plot
figure()
x = y = linspace(- 5.0 , 5.0 , 1000 )
streamplot(* Q(f, x, y), color= "k" )
plot([0 ], [0 ], "k." , ms= 10.0 )
axis("square" )
axis("off" )
Your browser does not support the video tag.
🔍 No Attractivity
The system
🐍 Vector field
def f(xy):
x, y = xy
dx = - 2 * x + y
dy = 2 * y - x
return array([dx, dy])
📈 Stream plot
figure()
x = y = linspace(- 5.0 , 5.0 , 1000 )
streamplot(* Q(f, x, y), color= "k" )
plot([0 ], [0 ], "k." , ms= 10.0 )
axis("square" )
axis("off" )
Your browser does not support the video tag.
🧩 Pendulum
The pendulum is governed by the equation
where , , and .
1. 🧮
Compute the equilibria of this system.
2. 🧠
Can any of these equilibria be globally
attractive?
3. 📈
Assume that , , and .
Make a stream plot of the system.
4. 🔬
Determine which equilibria are locally attractive.
5. 📈 Frictionless Pendulum
Assume now that .
Make a stream plot of the system.
6. 🧮 🧠
Prove that the equilibrium at is not locally attractive.
🗝️ Hint. Study how the total mechanical energy
evolves in time.
1. 🔓
The 2nd-order differential equations of the pendulum are equivalent
to the first order system
Thus, the system state is and is governed by with
Hence, the state is a solution to if and only if and . In
other words, the equilibria of the system are characterized by for some and .
2. 🔓
Since there are several equilibria, none of them can be globally
attractive.
Indeed let be a globally
attractive equilibrium and assume that is any other equilibrium. By
definition, the maximal solution such that is for every . On the other hand, since is globally attractive, it also
satisfies when , hence there is a
contradiction.
Thus, is the only possible
equilibrium.
3. 🔓
m = l = b = 1 ; g= 9.81
def f(theta_omega):
theta, omega = theta_omega
d_theta = omega
d_omega = - b / (m * l * l) * omega
d_omega -= (g / l) * sin(theta)
return (d_theta, d_omega)
figure()
theta = linspace(- 2 * pi* (1.2 ), 2 * pi* (1.2 ), 1000 )
d_theta = linspace(- 5.0 , 5.0 , 1000 )
streamplot(* Q(f, theta, d_theta), color= "k" )
plot([- 2 * pi, - pi, 0 ,pi, 2 * pi], 5 * [0.0 ], "k." )
xticks([- 2 * pi, - pi, 0 ,pi, 2 * pi],
[r"$-2\pi$" , r"$\pi$" , r"$0$" , r"$\pi$" , r"$2\pi$" ])
grid(True )
4. 🔓
From the streamplot, we see that the equilibria
are asymptotically stable, but that the equilibria
are not (they are not locally attractive).
5. 🔓
b = 0
figure()
streamplot(* Q(f, theta, d_theta), color= "k" )
plot([- 2 * pi, - pi, 0 ,pi, 2 * pi], 5 * [0.0 ], "k." )
xticks([- 2 * pi, - pi, 0 ,pi, 2 * pi],
[r"$-2\pi$" , r"$\pi$" , r"$0$" , r"$\pi$" , r"$2\pi$" ])
grid(True )
6. 🔓
Therefore, is constant.
On the other hand,
Moreover, this minimum is locally strict. Precisely, for any ,
If the origin was locally attractive, for any and small enough, we would
have (by continuity). But if , we have
and that would contradict that is constant.
Hence the origin is not locally attractive.
💎 Attractivity (Low-level)
The equilibrium is
globally attractive iff:
for any state and for
any there is a
,
such that the maximal solution such that is global and,
satisfies:
⚠️ Warning
Very close values of
could theoretically lead to very different “speed of
convergence” of towards the
equilibrium.
This is not contradictory with the well-posedness assumption:
continuity w.r.t. the initial condition only works with finite time
spans.
Equivalently, in polar coordinates:
🐍 Vector Field
def f(xy):
x, y = xy
r = sqrt(x* x + y* y)
dx = x + x * y - (x + y) * r
dy = y - x * x + (x - y) * r
return array([dx, dy])
📈 Stream Plot
figure()
x = y = linspace(- 2.0 , 2.0 , 1000 )
streamplot(* Q(f, x, y), color= "k" )
plot([1 ], [0 ], "k." , ms= 20.0 )
axis("square" )
axis("off" )
Your browser does not support the video tag.
Asymptotic Stability
Asymptotic stability is a stronger version of attractivity which is
by definition robust with respect to the choice of the initial
state.
🏷️ Global Asympt. Stability
The equilibrium is
globally asympt. stable iff:
for any state and for
any there is a
,
and there is a such
that if ,
such that the maximal solution such that is global and,
satisfies:
Global asymptotic stability is requirement which is very similar to
attractivity. The only difference is that it requires the time that we should wait to be sure that
the distance between and the
equilibrium is less that should be valid not only for
the initial condition
but also for any other initial condition in an (arbitrary small)
neighbourhood of . There is a
common profile for the “speed of convergence” towards the equilibrium
between an initial condition and its neighbors ; this condition is not
always met if we merely have an attractive equilibrium.
Set of Initial Conditions
Let and .
Let be the image of by the flow at time :
💎 Global Asympt. Stability
An equilibrium is globally
asympt. stable iff
🏷️ Limits of Sets
to be interpreted as
Your browser does not support the video tag.
Your browser does not support the video tag.
🏷️ Local Asymptotic Stability
The equilibrium is
locally asympt. stable iff:
there is a such that
for any ,
there is a such
that,
if , the
maximal solution such that
is global and
satisfies:
💎 Local Asympt. Stability
An equilibrium is locally
asympt. stable iff:
There is a such that for
every set such that
and for any , the
associated maximal solution is
global and
🏷️ Stability
An equilibrium is
stable iff:
🧩 Vinograd System
Consider the system:
🐍 Vector field
def f(xy):
x, y = xy
q = x** 2 + y** 2 * (1 + (x** 2 + y** 2 )** 2 )
dx = (x** 2 * (y - x) + y** 5 ) / q
dy = y** 2 * (y - 2 * x) / q
return array([dx, dy])
📈 Stream plot
figure()
x = y = linspace(- 1.0 , 1.0 , 1000 )
streamplot(* Q(f, x, y), color= "k" )
xticks([- 1 , 0 , 1 ])
plot([0 ], [0 ], "k." , ms= 10.0 )
axis("square" )
axis("off" )
Your browser does not support the video tag.
1. 🧮
Show that the origin is
the unique equilibrium.
2. 📈🔬
Does this equilibrium seem to be attractive (graphically) ?
3. 🧠
Show that for any equilibrium of a well-posed system:
💎 (locally) asymptotically stable stable
4. 🧪📈
Does the origin seem to be stable (experimentally ?)
Conclude accordingly.
1. 🔓
is an equilibrium of the
Vinograd system iff
or equivalently
If we assume that , then:
Under this assumption, is the only
equilibrium.
Otherwise (if ),
The initial assumption cannot hold.
Conclusion:
The Vinograd system has a single equilibrium: .
2. 🔓
Yes, the origin seems to be (globally) attractive.
As far as we can tell, the streamplot displays trajectories that
ultimately all converge towards the origin.
3. 🔓
Let’s assume that is a
(locally) asymptotically stable of a well-posed system.
Let such that this property is satisfied and let
The set is defined for
any and since is a neighbourhood of , there is such that for any , the image of by is included in .
Additionally, the system is well-posed.
Hence there is a
such that for any in the closed
ball of radius centered at and any , we have
Since is an equilibrium,
, thus
Equivalently,
Note that since , this inclusion yields . Thus, for any , either and or and since ,
Conclusion: we have established that there is a
such that and a such that and
In other words, the system is stable! 🎉
4. 🔓
No! We can pick initial states , with which are just above the origin and still the distance of
their trajectory to the origin will exceed at some point:
def fun(t, xy):
return f(xy)
eps = 1e-10 ; xy0 = (0 , eps)
sol = solve_ivp(
fun= fun,
y0= xy0,
t_span= (0.0 , 100.0 ),
dense_output= True )["sol" ]
t = linspace(0.0 , 100.0 , 10000 )
xt, yt = sol(t)
figure()
x = y = linspace(- 1.0 , 1.0 , 1000 )
streamplot(* Q(f, x, y), color= "#ced4da" )
xticks([- 1 , 0 , 1 ])
plot([0 ], [0 ], "k." , ms= 10.0 )
plot(xt, yt, color= "C0" )