H2 synthesis, based on Scherer et al. 1997 example 7

Code

 1"""H2 design using h2syn.
 2
 3Demonstrate H2 design for a SISO plant using h2syn. Based on [1], Ex. 7.
 4
 5[1] Scherer, Gahinet, & Chilali, "Multiobjective Output-Feedback Control via
 6LMI Optimization", IEEE Trans. Automatic Control, Vol. 42, No. 7, July 1997.
 7
 8[2] Zhou & Doyle, "Essentials of Robust Control", Prentice Hall,
 9Upper Saddle River, NJ, 1998.
10"""
11# %%
12# Packages
13import numpy as np
14import control
15
16# %%
17# State-space system.
18
19# Process model.
20A = np.array([[0, 10, 2],
21              [-1, 1, 0],
22              [0, 2, -5]])
23B1 = np.array([[1],
24               [0],
25               [1]])
26B2 = np.array([[0],
27               [1],
28               [0]])
29
30# Plant output.
31C2 = np.array([[0, 1, 0]])
32D21 = np.array([[2]])
33D22 = np.array([[0]])
34
35# H2 performance.
36C1 = np.array([[0, 1, 0],
37               [0, 0, 1],
38               [0, 0, 0]])
39D11 = np.array([[0],
40                [0],
41                [0]])
42D12 = np.array([[0],
43                [0],
44                [1]])
45
46# Dimensions.
47n_u, n_y = 1, 1
48
49# %%
50# H2 design using h2syn.
51
52# Create augmented plant.
53Baug = np.block([B1, B2])
54Caug = np.block([[C1], [C2]])
55Daug = np.block([[D11, D12], [D21, D22]])
56Paug = control.ss(A, Baug, Caug, Daug)
57
58# Input to h2syn is Paug, number of inputs to controller,
59# and number of outputs from the controller.
60K = control.h2syn(Paug, n_y, n_u)
61
62# Extarct controller ss realization.
63A_K, B_K, C_K, D_K = K.A, K.B, K.C, K.D
64
65# %%
66# Compute closed-loop H2 norm.
67
68# Compute closed-loop system, Tzw(s). See Eq. 4 in [1].
69Azw = np.block([[A + B2 @ D_K @ C2, B2 @ C_K],
70                [B_K @ C2, A_K]])
71Bzw = np.block([[B1 + B2 @ D_K @ D21],
72                [B_K @ D21]])
73Czw = np.block([C1 + D12 @ D_K @ C2, D12 @ C_K])
74Dzw = D11 + D12 @ D_K @ D21
75Tzw = control.ss(Azw, Bzw, Czw, Dzw)
76
77# Compute closed-loop H2 norm via Lyapunov equation.
78# See [2], Lemma 4.4, pg 53.
79Qzw = control.lyap(Azw.T, Czw.T @ Czw)
80nu = np.sqrt(np.trace(Bzw.T @ Qzw @ Bzw))
81print(f'The closed-loop H_2 norm of Tzw(s) is {nu}.')
82# Value is 7.748350599360575, the same as reported in [1].
83
84# %%

Notes

1. The environment variable PYCONTROL_TEST_EXAMPLES is used for testing to turn off plotting of the outputs.