Skip to content

Commit b03e294

Browse files
committed
Merge pull request #66 from roryyorke/margin-fix
Margin fix You are right on this one.
2 parents cd87eda + b12e132 commit b03e294

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
@@ -257,7 +257,7 @@ def testMargin(self):
257257
gm, pm, wg, wp = margin(self.siso_ss2);
258258
gm, pm, wg, wp = margin(self.siso_ss2*self.siso_ss2*2);
259259
np.testing.assert_array_almost_equal(
260-
[gm, pm, wg, wp], [1.5451, 75.9933, 0.6559, 1.2720], decimal=3)
260+
[gm, pm, wg, wp], [1.5451, 75.9933, 1.2720, 0.6559], decimal=3)
261261

262262
def testDcgain(self):
263263
#Create different forms of a SISO system
@@ -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)
614611
self.assertAlmostEqual(wg, 0.176469728448)
612+
self.assertAlmostEqual(wp, 0.0616288455466)
615613

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

0 commit comments

Comments
 (0)