Skip to content

Commit 235a92b

Browse files
committed
rewrite some tests with complex state matrices
1 parent e6f2f60 commit 235a92b

File tree

1 file changed

+31
-29
lines changed

1 file changed

+31
-29
lines changed

control/tests/statesp_test.py

Lines changed: 31 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,15 @@ def setUp(self):
2121
"""Set up a MIMO system to test operations on."""
2222

2323
# sys1: 3-states square system (2 inputs x 2 outputs)
24-
A322 = [[-3., 4., 2.],
24+
A322 = [[-3j, 4j, 2.],
2525
[-1., -3., 0.],
26-
[2., 5., 3.]]
26+
[2j, 5j, 3.]]
2727
B322 = [[1., 4.],
28-
[-3., -3.],
28+
[-3j, -3.],
2929
[-2., 1.]]
30-
C322 = [[4., 2., -3.],
30+
C322 = [[4., 2j, -3.],
3131
[1., 4., 3.]]
32-
D322 = [[-2., 4.],
32+
D322 = [[-2j, 4.],
3333
[0., 1.]]
3434
self.sys322 = StateSpace(A322, B322, C322, D322)
3535

@@ -90,9 +90,9 @@ def test_pole(self):
9090
"""Evaluate the poles of a MIMO system."""
9191

9292
p = np.sort(self.sys322.pole())
93-
true_p = np.sort([3.34747678408874,
94-
-3.17373839204437 + 1.47492908003839j,
95-
-3.17373839204437 - 1.47492908003839j])
93+
true_p = np.sort([-0.000000000000002 - 3.631067038076226j,
94+
-3.345427524119811 + 0.315533519038114j,
95+
3.345427524119812 + 0.315533519038115j])
9696

9797
np.testing.assert_array_almost_equal(p, true_p)
9898

@@ -117,20 +117,23 @@ def test_zero_siso(self):
117117

118118
np.testing.assert_almost_equal(true_z, z)
119119

120-
@unittest.skipIf(not slycot_check(), "slycot not installed")
120+
# @unittest.skipIf(not slycot_check(), "slycot not installed")
121121
def test_zero_mimo_sys322_square(self):
122122
"""Evaluate the zeros of a square MIMO system."""
123123

124124
z = np.sort(self.sys322.zero())
125-
true_z = np.sort([44.41465, -0.490252, -5.924398])
125+
true_z = np.sort([26.269442405839197 -17.632596605469434j,
126+
6.573387902319676 + 1.272834429979537j,
127+
-3.842830308158862 - 4.640237824510066j])
126128
np.testing.assert_array_almost_equal(z, true_z)
127129

128-
@unittest.skipIf(not slycot_check(), "slycot not installed")
130+
# @unittest.skipIf(not slycot_check(), "slycot not installed")
129131
def test_zero_mimo_sys222_square(self):
130132
"""Evaluate the zeros of a square MIMO system."""
131133

132134
z = np.sort(self.sys222.zero())
133-
true_z = np.sort([-10.568501, 3.368501])
135+
true_z = np.sort([ -6.904778467102364 + 1.237894313717807j,
136+
4.304778467102365 + 2.162105686282194j])
134137
np.testing.assert_array_almost_equal(z, true_z)
135138

136139
@unittest.skipIf(not slycot_check(), "slycot not installed")
@@ -144,11 +147,11 @@ def test_zero_mimo_sys623_non_square(self):
144147
def test_add_ss(self):
145148
"""Add two MIMO systems."""
146149

147-
A = [[-3., 4., 2., 0., 0.], [-1., -3., 0., 0., 0.],
148-
[2., 5., 3., 0., 0.], [0., 0., 0., 4., 1.], [0., 0., 0., 2., -3.]]
149-
B = [[1., 4.], [-3., -3.], [-2., 1.], [5., 2.], [-3., -3.]]
150-
C = [[4., 2., -3., 2., -4.], [1., 4., 3., 0., 1.]]
151-
D = [[1., 6.], [1., 0.]]
150+
A = [[-3j, 4j, 2., 0., 0.], [-1., -3., 0., 0., 0.],
151+
[2j, 5j, 3., 0., 0.], [0., 0., 0., 4., 1j], [0., 0., 0., 2j, -3.]]
152+
B = [[1., 4.], [-3j, -3.], [-2., 1.], [5., 2.], [-3j, -3]]
153+
C = [[4., 2j, -3., 2., -4.], [1., 4., 3., 0., 1j]]
154+
D = [[1j, 4+2j], [1., 0.]]
152155

153156
sys = self.sys322 + self.sys222
154157

@@ -160,11 +163,11 @@ def test_add_ss(self):
160163
def test_subtract_ss(self):
161164
"""Subtract two MIMO systems."""
162165

163-
A = [[-3., 4., 2., 0., 0.], [-1., -3., 0., 0., 0.],
164-
[2., 5., 3., 0., 0.], [0., 0., 0., 4., 1.], [0., 0., 0., 2., -3.]]
165-
B = [[1., 4.], [-3., -3.], [-2., 1.], [5., 2.], [-3., -3.]]
166-
C = [[4., 2., -3., -2., 4.], [1., 4., 3., 0., -1.]]
167-
D = [[-5., 2.], [-1., 2.]]
166+
A = [[-3j, 4j, 2., 0. ,0.], [-1., -3., 0., 0., 0.],
167+
[2j, 5j, 3., 0., 0., ], [0., 0., 0., 4., 1j], [0., 0., 0., 2j, -3.]]
168+
B = [[1., 4.], [-3j, -3.], [-2., 1.], [5., 2.], [-3j, -3.]]
169+
C = [[4., 2j, -3., -2., 4.], [1., 4., 3., 0., -1j]]
170+
D = [[5j, 4-2j], [-1., 2.]]
168171

169172
sys = self.sys322 - self.sys222
170173

@@ -176,12 +179,11 @@ def test_subtract_ss(self):
176179
def test_multiply_ss(self):
177180
"""Multiply two MIMO systems."""
178181

179-
A = [[4., 1., 0., 0., 0.], [2., -3., 0., 0., 0.], [2., 0., -3., 4., 2.],
180-
[-6., 9., -1., -3., 0.], [-4., 9., 2., 5., 3.]]
181-
B = [[5., 2.], [-3., -3.], [7., -2.], [-12., -3.], [-5., -5.]]
182-
C = [[-4., 12., 4., 2., -3.], [0., 1., 1., 4., 3.]]
183-
D = [[-2., -8.], [1., -1.]]
184-
182+
A = [[-3j, 4j, 2., 2., -4+4j], [-1., -3., 0., -6j, 9j], [2j, 5j, 3., -4., 8+1j],
183+
[0., 0., 0., 4., 1j], [0., 0., 0., 2j, -3.]]
184+
B = [[4+3j, -4+2j], [6., 9.], [1-6j, -1-4j], [5., 2.], [-3j, -3.]]
185+
C = [[4., 2j, -3., -4j, 12j], [1., 4., 3., 0., 1j]]
186+
D = [[10., 0.], [1., -1.]]
185187
sys = self.sys322 * self.sys222
186188

187189
np.testing.assert_array_almost_equal(sys.A, A)
@@ -219,7 +221,7 @@ def test_evalfr(self):
219221
assert len(w) == 1
220222
assert issubclass(w[-1].category, PendingDeprecationWarning)
221223

222-
@unittest.skipIf(not slycot_check(), "slycot not installed")
224+
# @unittest.skipIf(not slycot_check(), "slycot not installed")
223225
def test_freq_resp(self):
224226
"""Evaluate the frequency response at multiple frequencies."""
225227

0 commit comments

Comments
 (0)