Skip to content

Commit 6f90fca

Browse files
committed
Deploying to gh-pages from @ a30c683 🚀
0 parents  commit 6f90fca

File tree

1,321 files changed

+389351
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

1,321 files changed

+389351
-0
lines changed

‎.gitattributes‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# SCM syntax highlighting
2+
pixi.lock linguist-language=YAML linguist-generated=true

‎.gitpod.yml‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
tasks:
2+
- init: pip install -r requirements.txt

‎.jupyterlite.doit.db‎

352 KB
Binary file not shown.

‎.nojekyll‎

Whitespace-only changes.

‎.tmp.py‎

Lines changed: 144 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
1+
from numpy import *
2+
from numpy.linalg import *
3+
from scipy.integrate import solve_ivp
4+
from scipy.linalg import solve_continuous_are
5+
from matplotlib.pyplot import *
6+
from numpy.testing import *
7+
# Python 3.x Standard Library
8+
import gc
9+
import os
10+
11+
# Third-Party Packages
12+
import numpy as np; np.seterr(all="ignore")
13+
import numpy.linalg as la
14+
import scipy.misc
15+
import matplotlib as mpl; mpl.use("Agg")
16+
import matplotlib.pyplot as pp
17+
import matplotlib.axes as ax
18+
import matplotlib.patches as pa
19+
20+
21+
#
22+
# Matplotlib Configuration & Helper Functions
23+
# --------------------------------------------------------------------------
24+
25+
# TODO: also reconsider line width and markersize stuff "for the web
26+
# settings".
27+
fontsize = 10
28+
29+
width = 345 / 72.27
30+
height = width / (16/9)
31+
32+
rc = {
33+
"text.usetex": True,
34+
"pgf.preamble": r"\usepackage{amsmath,amsfonts,amssymb}",
35+
#"font.family": "serif",
36+
"font.serif": [],
37+
#"font.sans-serif": [],
38+
"legend.fontsize": fontsize,
39+
"axes.titlesize": fontsize,
40+
"axes.labelsize": fontsize,
41+
"xtick.labelsize": fontsize,
42+
"ytick.labelsize": fontsize,
43+
"figure.max_open_warning": 100,
44+
#"savefig.dpi": 300,
45+
#"figure.dpi": 300,
46+
"figure.figsize": [width, height],
47+
"lines.linewidth": 1.0,
48+
}
49+
mpl.rcParams.update(rc)
50+
51+
# Web target: 160 / 9 inches (that's ~45 cm, this is huge) at 90 dpi
52+
# (the "standard" dpi for Web computations) gives 1600 px.
53+
width_in = 160 / 9
54+
55+
def save(name, **options):
56+
cwd = os.getcwd()
57+
root = os.path.dirname(os.path.realpath(__file__))
58+
os.chdir(root)
59+
pp.savefig(name + ".svg", **options)
60+
os.chdir(cwd)
61+
62+
def set_ratio(ratio=1.0, bottom=0.1, top=0.1, left=0.1, right=0.1):
63+
height_in = (1.0 - left - right)/(1.0 - bottom - top) * width_in / ratio
64+
pp.gcf().set_size_inches((width_in, height_in))
65+
pp.gcf().subplots_adjust(bottom=bottom, top=1.0-top, left=left, right=1.0-right)
66+
def Q(f, xs, ys):
67+
X, Y = meshgrid(xs, ys)
68+
fx = vectorize(lambda x, y: f([x, y])[0])
69+
fy = vectorize(lambda x, y: f([x, y])[1])
70+
return X, Y, fx(X, Y), fy(X, Y)
71+
from scipy.signal import place_poles
72+
A = array([[0, 1], [0, 0]])
73+
C = array([[1, 0]])
74+
poles = [-1, -2]
75+
K = place_poles(A.T, C.T, poles).gain_matrix
76+
L = K.T
77+
assert_almost_equal(K, [[3.0, 2.0]])
78+
def fun(t, X_Xhat):
79+
x, x_hat = X_Xhat[0:2], X_Xhat[2:4]
80+
y, y_hat = C.dot(x), C.dot(x_hat)
81+
dx = A.dot(x)
82+
dx_hat = A.dot(x_hat) - L.dot(y_hat - y)
83+
return r_[dx, dx_hat]
84+
y0 = [-2.0, 1.0, 0.0, 0.0]
85+
result = solve_ivp(
86+
fun=fun,
87+
t_span=[0.0, 5.0],
88+
y0=y0,
89+
max_step=0.1
90+
)
91+
figure()
92+
t = result["t"]
93+
y = result["y"]
94+
plot(t, y[0], "C0", label="$x_1$")
95+
plot(t, y[2], "C0--", label=r"$\hat{x}_1$")
96+
plot(t, y[1], "C1", label="$x_2$")
97+
plot(t, y[3], "C1--", label=r"$\hat{x}_2$")
98+
xlabel("$t$"); grid(); legend()
99+
pp.gcf().subplots_adjust(bottom=0.2)
100+
save("images/observer-trajectories")
101+
A = array([[0, 1], [0, 0]])
102+
B = array([[0], [1]])
103+
Q = array([[1, 0], [0, 1]])
104+
R = array([[1]])
105+
sca = solve_continuous_are
106+
Sigma = sca(A.T, C.T, inv(Q), inv(R))
107+
L = Sigma @ C.T @ R
108+
109+
eigenvalues, _ = eig(A - L @ C)
110+
assert all([real(s) < 0 for s in eigenvalues])
111+
figure()
112+
x = [real(s) for s in eigenvalues]
113+
y = [imag(s) for s in eigenvalues]
114+
plot(x, y, "kx"); xlim(-2, 2); ylim(-2, 2)
115+
plot([0, 0], [-2, 2], "k");
116+
plot([-2, 2], [0, 0], "k")
117+
grid(True); axis("square")
118+
title("Eigenvalues")
119+
axis("square")
120+
axis([-2, 2, -2, 2])
121+
save("images/poles-Kalman")
122+
def fun(t, X_Xhat):
123+
x, x_hat = X_Xhat[0:2], X_Xhat[2:4]
124+
y, y_hat = C.dot(x), C.dot(x_hat)
125+
dx = A.dot(x)
126+
dx_hat = A.dot(x_hat) - L.dot(y_hat - y)
127+
return r_[dx, dx_hat]
128+
y0 = [-2.0, 1.0, 0.0, 0.0]
129+
result = solve_ivp(
130+
fun=fun,
131+
t_span=[0.0, 5.0],
132+
y0=y0,
133+
max_step=0.1
134+
)
135+
figure()
136+
t = result["t"]; y = result["y"]
137+
plot(t, y[0], "C0", label="$x_1$")
138+
plot(t, y[2], "C0--", label=r"$\hat{x}_1$")
139+
plot(t, y[1], "C1", label="$x_2$")
140+
plot(t, y[3], "C1--", label=r"$\hat{x}_2$")
141+
xlabel("$t$")
142+
grid(); legend()
143+
pp.gcf().subplots_adjust(bottom=0.2)
144+
save("images/observer-Kalman-trajectories")

‎.travis.yml.old‎

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
dist: xenial
2+
language: bash
3+
4+
env:
5+
global:
6+
- CONDA=https://repo.continuum.io/miniconda/Miniconda3-latest-Linux-x86_64.sh
7+
- MYBINDER=https://mybinder.org/v2/gh/boisgera/control-engineering-with-python/gh-pages
8+
9+
before_install:
10+
- sudo apt-get --yes --force-yes install texlive-full
11+
- sudo apt-get install chromium-browser
12+
- curl $CONDA > conda.sh
13+
- bash conda.sh -b -p $HOME/conda
14+
- export PATH=$HOME/conda/bin:$PATH
15+
- hash -r
16+
- conda config --set always_yes yes --set changeps1 no
17+
- conda update conda
18+
- conda info -a # debugging
19+
- conda env create -f environment.yml
20+
- source activate control-engineering-with-python
21+
- conda install -c conda-forge nodejs=10.13.0
22+
- npm install -g --unsafe-perm hummus
23+
- npm install -g --unsafe-perm decktape
24+
25+
install:
26+
- ./build # generate slides and notebooks
27+
- ./build-pdf
28+
- rm -rf src # pandoc from git, clean-up for deployment to gh-pages
29+
- rm -rf conda.sh # clean-up conda installer before deployment
30+
- mv .gitignore .gitignore.bak # for deployment to gh-pages
31+
32+
deploy:
33+
provider: pages
34+
skip-cleanup: true
35+
github-token: $GITHUB_TOKEN
36+
on:
37+
branch: master
38+
39+
script:
40+
- chromium-browser --headless --disable-gpu $MYBINDER
41+

0 commit comments

Comments
 (0)