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.integrate import solve_ivp
from matplotlib.pyplot import *
🐍 Stream Plot Helper
def Q(f, xs, ys):
X, Y = meshgrid(xs, ys)
fx = vectorize(lambda x, y: f([x, y])[0 ])
fy = vectorize(lambda x, y: f([x, y])[1 ])
return X, Y, fx(X, Y), fy(X, Y)
🏷️ Well-Posedness
Make sure that a system is “sane” (not “pathological”):
Well-Posedness:
Existence +
Uniqueness +
Continuity .
We will define and study each one in the sequel.
Local vs Global
So far, we have mostly dealt with global solutions
of IVPs, defined for any .
This concept is sometimes too stringent.
🔍 Finite-Time Blow-Up
Consider the IVP
🐍 💻 📈
def fun(t, y):
return y * y
t0, tf, y0 = 0.0 , 3.0 , array([1.0 ])
result = solve_ivp(fun, t_span= [t0, tf], y0= y0)
figure()
plot(result["t" ], result["y" ][0 ], "k" )
xlim(t0, tf); xlabel("$t$" ); ylabel("$x(t)$" )
Local vs
Global
🤕 Ouch.
There is actually no global solution.
However there is a local solution ,
Indeed, the function satisfies
and
⚠️ But it’s defined (continuously) only for
🐍 💻 📈
tf = 1.0
r = solve_ivp(fun, [t0, tf], y0,
dense_output= True )
figure()
t = linspace(t0, tf, 1000 )
plot(t, r["sol" ](t)[0 ], "k" )
ylim(0.0 , 10.0 ); grid();
xlabel("$t$" ); ylabel("$x(t)$" )
This local solution is also maximal :
You cannot extend this solution beyond .
🏷️ Local Solution
A solution
of the IVP is (forward and) local if for some such that .
🏷️ Global Solution
A solution
of the IVP is (forward and) global if .
🏷️ Maximal Solution
A (local) solution
to an IVP is maximal if there is no other solution
🧩 Maximal Solutions
Consider the IVP
1. 🧮
Find a closed-formed local solution of the IVP.
🗝️ Hint: assume that then compute
2. 🧠
Make sure that your solutions are maximal.
By integration, this leads to
and thus provides
which is indeed a solution as long as the denominator is not
zero.
2. 🔓
If , this solution
is valid for all and thus
maximal.
If , the solution
is defined until where it
blows up. Thus, this solution is also maximal.
🙁 Bad News (1/3)
Sometimes things get worse than simply having no global solution.
🔍 No Local Solution
Consider the scalar IVP with initial value and right-hand side
🐍 📈 No Local Solution
def f(x1x2):
x1, x2 = x1x2
dx1 = 1.0 if x1 < 0.0 else - 1.0
return array([dx1, 0.0 ])
figure()
x1 = x2 = linspace(- 1.0 , 1.0 , 20 )
gca().set_aspect(1.0 )
quiver(* Q(f, x1, x2), color= "k" )
💎 No Local Solution
This system has no solution, not even a local one, when .
🧠 Proof
Assume that is a local solution.
Since , for some small enough and any , we have .
Consequently, and thus by integration
which is a contradiction.
🙂 Good News (1/3)
However, a local solution exists under very mild assumptions.
💎 Existence
If is continuous,
📝 Note: a maximal solution is
global iff .
💎 Maximal Solutions
A solution on is maximal if and only if either
In plain words : a non-global solution cannot be extended further in
time if and only if it “blows up”.
💎 Corollary
Let’s assume that a local maximal solution exists.
You wonder if this solution is defined in or blows up before .
For example, you wonder if a solution is global (if or .)
🧠 Prove existence
Task. Show that any solution which defined on some
sub-interval with would is bounded.
Then, no solution can be maximal on any such (since it doesn’t blow up !).
Since a maximal solution does exist, its domain is with .
a solution
is defined on .
🧩 Sigmoid
Consider the dynamical system
📈
def sigma(x):
return 1 / (1 + exp(- x))
figure()
x = linspace(- 7.0 , 7.0 , 1000 )
plot(x, sigma(x), label= "$y=\sigma(x)$" )
grid(True )
1. 🧮 Existence
Show that there is a (at least one) maximal solution to each initial
condition.
2. 🧮 Global
Show that any such solution is global.
1. 🔓 Existence
The sigmoid function is
continuous.
Consequently, 💎 Existence proves the
existence of a (at least one) maximal solution.
2. 🔓 Global
Let be a maximal solution to the IVP. We have
and by integration,
Thus, it cannot blow-up in finite time; by 💎 Maximal Solutions , it is global.
🧩 Pendulum
Consider the pendulum, subject to a torque
We assume that the torque provides a bounded power:
1. 🧮
Show that for any initial state, there is a global solution .
🗝️ Hint. Compute the derivative with respect to
of
1. 🔓
Since the system vector field
is continuous, 💎 Existence yields the
existence of a (at least one) maximal solution.
By integration
Hence, since ,
Thus, cannot
blow-up in finite time. Since
cannot blow-up in
finite time either.
By 💎 Maximal Solutions , any
maximal solution is global.
🧩 Linear Systems
Let .
Consider the dynamical system
1. 🧮
Show that
is differentiable and satisfies
for some . 🔓
2. 🧮
Let
Compute and deduce
that
3. 🧮
Prove that for any initial state there is a corresponding global solution . 🔓
1. 🔓
By definition of and since
,
Let denote the largest singular value
of (i.e. the operator norm ).
For any vector , we have
2. 🔓
Since , the
inequality is
clear.
Since ,
3. 🔓
The vector field is continuous, thus by 💎 Existence
there is a maximal solution for any initial state
Moreover,
Hence there is no finite-time blow-up and the maximal solution is
global.
🏷️ Uniqueness
In the current context, uniqueness means uniqueness
of the maximal solution to an IVP.
🙁 Bad News (2/3)
Uniqueness of solutions, even the maximal ones, is not granted
either.
🔍 Non-Uniqueness
The IVP
has several maximal (global) solutions.
Proof
For any , is a solution:
🙂 Good News (2/3)
However, uniqueness of maximal solution holds under mild
assumptions.
🏷️ Jacobian Matrix
Jacobian matrix of :
💎 Uniqueness
If exists
and is continuous, the maximal solution is unique.
🙁 Bad News (3/3)
An infinitely small error in the initial value could result in a
finite error in the solution, even in finite time.
That would severely undermine the utility of any approximation
method.
🏷️ Continuity
Instead of denoting the
solution, use to
emphasize the dependency w.r.t. the initial state.
Continuity w.r.t. the initial state means that if
is defined on and :
and that this convergence is uniform w.r.t. .
🙂 Good News (3/3)
However, continuity w.r.t. the initial value holds under mild
assumptions.
💎 Continuity
Assume that exists and is continuous.
Then the dynamical system is continous w.r.t. the initial state.
🔍 Prey-Predator
Let
with , , .
🐍
alpha = 2 / 3 ; beta = 4 / 3 ; delta = gamma = 1.0
def fun(t, y):
x, y = y
u = alpha * x - beta * x * y
v = delta * x * y - gamma * y
return array([u, v])
💻
tf = 3.0
result = solve_ivp(
fun,
t_span= (0.0 , tf),
y0= [1.5 , 1.5 ],
max_step= 0.01 )
x, y = result["y" ][0 ], result["y" ][1 ]
📈
def display_streamplot():
ax = gca()
xr = yr = linspace(0.0 , 2.0 , 1000 )
def f(y):
return fun(0 , y)
streamplot(* Q(f, xr, yr), color= "grey" )
📈
def display_reference_solution():
for xy in zip (x, y):
x_, y_ = xy
gca().add_artist(Circle((x_, y_),
0.2 , color= "#d3d3d3" ))
gca().add_artist(Circle((x[0 ], y[0 ]), 0.1 ,
color= "#808080" ))
plot(x, y, "k" )
📈
def display_alternate_solution():
result = solve_ivp(fun,
t_span= [0.0 , tf],
y0= [1.5 , 1.575 ],
max_step= 0.01 )
x, y = result["y" ][0 ], result["y" ][1 ]
plot(x, y, "k--" )
📈
figure()
display_streamplot()
display_reference_solution()
display_alternate_solution()
axis([0 ,2 ,0 ,2 ]); axis("square" )
🧩 Continuity
Let and be the solution of the IVP
1. 🧮
Let and .
Find the largest
such that ensures
that
2. 🧮
What is the behavior of
when goes to infinity?
2. 🔓
The solution to the IVP
is Hence,
Thus, the smallest such
that yields is
🧩 Continuity Issues
Consider the IVP
1. 💻 📈
Solve numerically this IVP for and and plot
the result.
Then, solve it again for , , etc. and
plot the results.
2. 🔬
Does the solution seem to be continuous with respect to the initial
value?
3. 🧠
Explain this experimental result.
1. 🔓
def fun(t, y):
x = y[0 ]
dx = sqrt(abs (y))
return [dx]
tspan = [0.0 , 3.0 ]
t = linspace(tspan[0 ], tspan[1 ], 1000 )
figure()
for x0 in [0.1 , 0.01 , 0.001 , 0.0001 , 0.0 ]:
r = solve_ivp(fun, tspan, [x0],
dense_output= True )
plot(t, r["sol" ](t)[0 ],
label= f"$x_0 = { x0} $" )
xlabel("$t$" ); ylabel("$x(t)$" )
legend()
2. 🔓
The solution does not seem to be continuous with respect to the
initial value since the graph of the solution seems to have a limit when
, but this limit is
different from which is the
numerical solution when .
3. 🔓
The jacobian matrix of the vector field is not defined when , thus the continuity was not
guaranted to begin with. Actually, uniqueness of the solution does not
even hold here, see 🔍 Non-Uniqueness .
The function is valid when
, but so is and the numerical solution seems to converge to the second one
when .
🧩 Prey-Predator
Consider the system
where , , and are positive.
1. 🧮
Prove that the system is well-posed.
2. 🧮 🧠
Prove that all maximal solutions such that and are global and satify and for every .
Hint 🗝️. Compute the ODE satisfied by and and then the derivative w.r.t.
time of
🔓 1.
The jacobian matrix of the system vector field is defined and continuous: thus the sytem is well-posed.
🔓 2.
The (continuously differentiable) change of variable is a bijection between and .
Since the prey-predator ODE is equivalent to
Accordingly,
Therefore is
constant.
Now, the function are continuous and As ,
Consequently, since is constant, the solution cannot blow
up (either in finite or infinite time).
Therefore the solution is global as is the solution in the original variables
.
Since and
the domain of is , and for any .