10000 Bugfix: order of returned values in margin() · XiangPiCha/python-control@00b2998 · GitHub
[go: up one dir, main page]

Skip to content

Commit 00b2998

Browse files
committed
Bugfix: order of returned values in margin()
control.margins.margin() was returning the gain and phase margin frequencies in the wrong order. Added TestMargin.test_margin, duplicating test case from TestMargin.test_stability_margins, in margin_test.py, and unskipped TestMatlab.testCombi01 in matlab_test.py.
1 parent cd87eda commit 00b2998

File tree

3 files changed

+11
-6
lines changed

3 files changed

+11
-6
lines changed

control/margins.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -312,4 +312,4 @@ def margin(*args):
312312
raise ValueError("Margin needs 1 or 3 arguments; received %i."
313313
% len(args))
314314

315-
return margin[0], margin[1], margin[4], margin[3]
315+
return margin[0], margin[1], margin[3], margin[4]

control/tests/margin_test.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ def setUp(self):
2020
s = TransferFunction([1, 0], [1])
2121
self.sys4 = (8.75*(4*s**2+0.4*s+1))/((100*s+1)*(s**2+0.22*s+1)) * \
2222
1./(s**2/(10.**2)+2*0.04*s/10.+1)
23+
self.stability_margins4 = [2.2716, 97.5941, 1.0454, 10.0053, 0.0850, 0.4973]
2324

2425
def test_stability_margins(self):
2526
gm, pm, sm, wg, wp, ws = stability_margins(self.sys1);
@@ -28,7 +29,13 @@ def test_stability_margins(self):
2829
gm, pm, sm, wg, wp, ws = stability_margins(self.sys4);
2930
np.testing.assert_array_almost_equal(
3031
[gm, pm, sm, wg, wp, ws],
31-
[2.2716, 97.5941, 1.0454, 10.0053, 0.0850, 0.4973], 3)
32+
self.stability_margins4, 3)
33+
34+
def test_margin(self):
35+
gm, pm, wg, wp = margin(self.sys4)
36+
np.testing.assert_array_almost_equal(
37+
[gm, pm, wg, wp],
38+
self.stability_margins4[:2] + self.stability_margins4[3:5], 3)
3239

3340
def test_phase_crossover_frequencies(self):
3441
omega, gain = phase_crossover_frequencies(self.sys2)

control/tests/matlab_test.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -554,8 +554,6 @@ def testSS2cont(self):
554554
-0.260952977031384 -0.274201791021713;
555555
-0.304617775734327 0.075182622718853"""), sysd.B)
556556

557-
558-
@unittest.skip("need to update margin command")
559557
def testCombi01(self):
560558
# test from a "real" case, combines tf, ss, connect and margin
561559
# this is a type 2 system, with phase starting at -180. The
@@ -610,8 +608,8 @@ def testCombi01(self):
610608
# print("%f %f %f %f" % (gm, pm, wg, wp))
611609
self.assertAlmostEqual(gm, 3.32065569155)
612610
self.assertAlmostEqual(pm, 46.9740430224)
613-
self.assertAlmostEqual(wp, 0.0616288455466)
614-
self.assertAlmostEqual(wg, 0.176469728448)
611+
self.assertAlmostEqual(wg, 0.0616288455466)
612+
self.assertAlmostEqual(wp, 0.176469728448)
615613

616614
#! TODO: not yet implemented
617615
# def testMIMOtfdata(self):

0 commit comments

Comments
 (0)
0