Skip to content

Commit c1c35d1

Browse files
committed
Add test demonstrating bug in stability_margins
See #58
1 parent 15fd5c1 commit c1c35d1

1 file changed

Lines changed: 14 additions & 1 deletion

File tree

control/tests/margin_test.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,20 @@ def test_phase_crossover_frequencies(self):
4747
np.testing.assert_array_almost_equal(omega, [1.73205081, 0.])
4848
np.testing.assert_array_almost_equal(gain, [-0.5, 0.25])
4949

50-
def suite():
50+
def test_mag_phase_omega(self):
51+
# test for bug reported in gh-58
52+
sys = TransferFunction(15, [1, 6, 11, 6])
53+
out = stability_margins(sys)
54+
omega = np.logspace(-1,1,100)
55+
mag, phase, omega = sys.freqresp(omega)
56+
out2 = stability_margins((mag, phase*180/np.pi, omega))
57+
ind = [0,1,3,4] # indices of gm, pm, wg, wp -- ignore sm
58+
marg1 = np.array(out)[ind]
59+
marg2 = np.array(out2)[ind]
60+
np.testing.assert_array_almost_equal(marg1, marg2, 4)
61+
62+
63+
def test_suite():
5164
return unittest.TestLoader().loadTestsFromTestCase(TestMargin)
5265

5366
if __name__ == "__main__":

0 commit comments

Comments
 (0)