Skip to content

Commit 8a11cd3

Browse files
authored
Add 's' and 'z' variable support to tf() (#304)
1 parent c596a12 commit 8a11cd3

File tree

3 files changed

+165
-74
lines changed

3 files changed

+165
-74
lines changed

control/tests/matlab_test.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -664,6 +664,22 @@ def testCombi01(self):
664664
self.assertAlmostEqual(wg, 0.176469728448)
665665
self.assertAlmostEqual(wp, 0.0616288455466)
666666

667+
def test_tf_string_args(self):
668+
# Make sure that the 's' variable is defined properly
669+
s = tf('s')
670+
G = (s + 1)/(s**2 + 2*s + 1)
671+
np.testing.assert_array_almost_equal(G.num, [[[1, 1]]])
672+
np.testing.assert_array_almost_equal(G.den, [[[1, 2, 1]]])
673+
self.assertTrue(isctime(G, strict=True))
674+
675+
# Make sure that the 'z' variable is defined properly
676+
z = tf('z')
677+
G = (z + 1)/(z**2 + 2*z + 1)
678+
np.testing.assert_array_almost_equal(G.num, [[[1, 1]]])
679+
np.testing.assert_array_almost_equal(G.den, [[[1, 2, 1]]])
680+
self.assertTrue(isdtime(G, strict=True))
681+
682+
667683
#! TODO: not yet implemented
668684
# def testMIMOtfdata(self):
669685
# sisotf = ss2tf(self.siso_ss1)

control/tests/xferfcn_test.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111
ss2tf
1212
from control.lti import evalfr
1313
from control.exception import slycot_check
14+
from control.lti import isctime, isdtime
1415
from control.dtime import sample_system
15-
# from control.lti import isdtime
1616

1717

1818
class TestXferFcn(unittest.TestCase):
@@ -704,6 +704,21 @@ def test_ss2tf(self):
704704
np.testing.assert_almost_equal(sys.num, true_sys.num)
705705
np.testing.assert_almost_equal(sys.den, true_sys.den)
706706

707+
def test_class_constants(self):
708+
# Make sure that the 's' variable is defined properly
709+
s = TransferFunction.s
710+
G = (s + 1)/(s**2 + 2*s + 1)
711+
np.testing.assert_array_almost_equal(G.num, [[[1, 1]]])
712+
np.testing.assert_array_almost_equal(G.den, [[[1, 2, 1]]])
713+
self.assertTrue(isctime(G, strict=True))
714+
715+
# Make sure that the 'z' variable is defined properly
716+
z = TransferFunction.z
717+
G = (z + 1)/(z**2 + 2*z + 1)
718+
np.testing.assert_array_almost_equal(G.num, [[[1, 1]]])
719+
np.testing.assert_array_almost_equal(G.den, [[[1, 2, 1]]])
720+
self.assertTrue(isdtime(G, strict=True))
721+
707722
def test_printing(self):
708723
# SISO, continuous time
709724
sys = ss2tf(rss(4, 1, 1))

0 commit comments

Comments
 (0)