% Linear Models % ๐ค Sรฉbastien Boisgรฉrault
-
๐ Documents (GitHub)
-
ยฉ๏ธ License CC BY 4.0
๐ | Code | ๐ | Worked Example |
๐ | Graph | ๐งฉ | Exercise |
๐ท๏ธ | Definition | ๐ป | Numerical Method |
๐ | Theorem | ๐งฎ | Analytical Method |
๐ | Remark | ๐ง | Theory |
โน๏ธ | Information | ๐๏ธ | Hint |
Warning | ๐ | Solution |
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
::: hidden :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
# Python 3.x Standard Library
import gc
import os
# Third-Party Packages
import numpy as np; np.seterr(all="ignore")
import numpy.linalg as la
import scipy.misc
import matplotlib as mpl; mpl.use("Agg")
import matplotlib.pyplot as pp
import matplotlib.axes as ax
import matplotlib.patches as pa
#
# Matplotlib Configuration & Helper Functions
# --------------------------------------------------------------------------
# TODO: also reconsider line width and markersize stuff "for the web
# settings".
fontsize = 10
width = 345 / 72.27
height = width / (16/9)
rc = {
"text.usetex": True,
"pgf.preamble": r"\usepackage{amsmath,amsfonts,amssymb}",
#"font.family": "serif",
"font.serif": [],
#"font.sans-serif": [],
"legend.fontsize": fontsize,
"axes.titlesize": fontsize,
"axes.labelsize": fontsize,
"xtick.labelsize": fontsize,
"ytick.labelsize": fontsize,
"figure.max_open_warning": 100,
#"savefig.dpi": 300,
#"figure.dpi": 300,
"figure.figsize": [width, height],
"lines.linewidth": 1.0,
}
mpl.rcParams.update(rc)
# Web target: 160 / 9 inches (that's ~45 cm, this is huge) at 90 dpi
# (the "standard" dpi for Web computations) gives 1600 px.
width_in = 160 / 9
def save(name, **options):
cwd = os.getcwd()
root = os.path.dirname(os.path.realpath(__file__))
os.chdir(root)
pp.savefig(name + ".svg", **options)
os.chdir(cwd)
def set_ratio(ratio=1.0, bottom=0.1, top=0.1, left=0.1, right=0.1):
height_in = (1.0 - left - right)/(1.0 - bottom - top) * width_in / ratio
pp.gcf().set_size_inches((width_in, height_in))
pp.gcf().subplots_adjust(bottom=bottom, top=1.0-top, left=left, right=1.0-right)
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
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)
Their structure is
where
The vector-valued
This quantity may depend on the time
(actually it may also depend on some state, but we will adress this later).
A solution of
is merely a solution of
where
We may complement the system dynamics with an equation
The vector
Input
When
The vector field
When
(the only one in the state space if
Assume that:
-
$\dot{x}1 = A x_1 + B u_1$, $x_1(0) = x{10}$,
-
$\dot{x}2 = A x_2 + B u_2$, $x_2(0) = x{20}$,
Set
-
$u_3 = \lambda u_1 + \mu u_2$ and -
$x_{30} = \lambda x_{10} + \mu x_{20}$ .
for some
Then, if
we have
$$ \dot{x}3 = A x_3 + B u_3, ; x_3(0) = x{30}. $$
The solution of
is the sum
-
$x_1(t)$ is the solution to the internal dynamics and -
$x_2(t)$ is the solution to the external dynamics.
-
The internal dynamics is controlled by the initial value
$x_0$ only (there is no input,$u=0$ ).$$ \dot{x}_1 = A x_1, ; x_1(0) = x_0, $$
-
The external dynamics is controlled by the input
$u(t)$ only (the system is initially at rest,$x_0=0$ ).$$ \dot{x}_2 = A x_2 + Bu, ; x_2(0) = 0. $$
These systems are actually linear and time-invariant (hence LTI) systems. Time-invariant means that when
then
-
Four cells numbered 1 to 4 are arranged in a row.
-
The first cell has a heat source, the last one a temperature sensor.
-
The heat sink/source is increasing the temperature of its cell of
$u$ degrees by second. -
If the temperature of a cell is
$T$ and the one of a neighbor is$T_n$ ,$T$ increases of$T_n - T$ by second.
Given the geometric layout:
-
$d T_1/dt = u + (T_2 - T_1)$ -
$d T_2/dt = (T_1 - T_2) + (T_3 - T_2)$ -
$d T_3/dt = (T_2 - T_3) + (T_4 - T_3)$ -
$d T_4/dt = (T_3 - T_4)$ -
$y = T_4$
Set
The model is linear and its standard matrices are:
Consider the nonlinear system
Assume that
and let
Define the error variables
-
$\Delta x := x - x_e$ , -
$\Delta u := u - u_e$ and -
$\Delta y := y - y_e$ .
As long as the error variables stay small
$$ f(x, u) \simeq \overbrace{f(x_e, u_e)}^0 + \frac{\partial f}{\partial x}(x_e, u_e) \Delta x
- \frac{\partial f}{\partial u}(x_e, u_e) \Delta u $$
$$ g(x, u) \simeq \overbrace{g(x_e, u_e)}^{y_e} + \frac{\partial g}{\partial x}(x_e, u_e) \Delta x
- \frac{\partial g}{\partial u}(x_e, u_e) \Delta u $$
Hence, the error variables satisfy approximately
with
\left[ \begin{array}{c|c} \frac{\partial f}{\partial x} & \frac{\partial f}{\partial u} \ \hline \frac{\partial g}{\partial x} & \frac{\partial g}{\partial u} \end{array} \right](x_e, u_e) $$
The system
has an equilibrium at
The corresponding error variables satisfy
def f(xy):
x, y = xy
dx = -2*x + y**3
dy = -2*y + x**3
return array([dx, dy])
def fl(xy):
x, y = xy
dx = -2*x
dy = -2*y
return array([dx, dy])
figure()
x = y = linspace(-1.0, 1.0, 1000)
streamplot(*Q(f, x, y), color="k")
blue_5 = "#339af0"
streamplot(*Q(fl, x, y), color=blue_5)
plot([0], [0], "k.", ms=10.0)
axis("square")
axis("off")
::: hidden :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
tight_layout()
save("images/linearization")
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
::: slides :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
Consider
If we set
Around this configuration
and
Thus, the approximate, linearized dynamics around this equilibrium is
The equilibrium
where
The equilibrium
-
The converse is not true : the nonlinear system may be asymptotically stable but not its linearized approximation (e.g. consider
$\dot{x} = -x^3$ ). -
If we replace local asymptotic stability with local exponential stability, the requirement that locally
$$ |x(t) - x_e| \leq A e^{-\sigma t} |x(0) - x_e| $$
for some
$A >0$ and$\sigma > 0$ , then it works.
A pendulum submitted to a torque
We assume that only the angle
Let
What are the function
Show that for any angle
Compute the linearized dynamics of the pendulum around this equilibrium
and put it in the standard form (compute
The 2nd-order differential equation
is equivalent to the first-order differential equation
\left[ \begin{array}{c} \omega \ -(b /m\ell^2)\omega - (g/\ell) \sin \theta + c / m\ell^2 \end{array} \right] $$
Hence, with
with
Let
\left[ \begin{array}{c} 0 \ 0 \end{array} \right] $$
which holds if and only if
We have
\left[ \begin{array}{rr} 0 & 1 \ - (g/\ell) \cos \theta_e & -(b /m\ell^2) \ \end{array} \right] $$
\left[ \begin{array}{cc} 1 \ 0 \end{array} \right], ; D = \frac{\partial g}{\partial u_e} (x_e, u_e)
0 $$
Thus,
and obviously, as far as the output goes,