Skip to content

Commit 8b220f7

Browse files
committed
fixed matlab compatibility bug in function definition and updated tests
1 parent c257fa4 commit 8b220f7

3 files changed

Lines changed: 43 additions & 1 deletion

File tree

control/matlab/timeresp.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ def impulse(sys, T=None, input=0, output=None, return_x=False):
118118

119119
return yout, T
120120

121-
def initial(sys, T=None, X0=0., input=None, output=None):
121+
def initial(sys, T=None, X0=0., input=None, output=None, return_x=False):
122122
'''
123123
Initial condition response of a linear system
124124

control/tests/matlab_test.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,10 @@ def testStep(self):
161161
np.testing.assert_array_almost_equal(yout, youttrue, decimal=4)
162162
np.testing.assert_array_almost_equal(tout, t)
163163

164+
yout, tout, xout = step(sys, T=t, X0=0, return_x=True)
165+
np.testing.assert_array_almost_equal(yout, youttrue, decimal=4)
166+
np.testing.assert_array_almost_equal(tout, t)
167+
164168
#Test MIMO system, which contains ``siso_ss1`` twice
165169
sys = self.mimo_ss1
166170
y_00, _t = step(sys, T=t, input=0, output=0)
@@ -188,6 +192,20 @@ def testImpulse(self):
188192
np.testing.assert_array_almost_equal(yout, youttrue, decimal=4)
189193
np.testing.assert_array_almost_equal(tout, t)
190194

195+
# Play with arguments
196+
yout, tout = impulse(sys, T=t, X0=0)
197+
np.testing.assert_array_almost_equal(yout, youttrue, decimal=4)
198+
np.testing.assert_array_almost_equal(tout, t)
199+
200+
X0 = np.array([0, 0]);
201+
yout, tout = impulse(sys, T=t, X0=X0)
202+
np.testing.assert_array_almost_equal(yout, youttrue, decimal=4)
203+
np.testing.assert_array_almost_equal(tout, t)
204+
205+
yout, tout, xout = impulse(sys, T=t, X0=0, return_x=True)
206+
np.testing.assert_array_almost_equal(yout, youttrue, decimal=4)
207+
np.testing.assert_array_almost_equal(tout, t)
208+
191209
#Test MIMO system, which contains ``siso_ss1`` twice
192210
sys = self.mimo_ss1
193211
y_00, _t = impulse(sys, T=t, input=0, output=0)
@@ -206,6 +224,11 @@ def testInitial(self):
206224
np.testing.assert_array_almost_equal(yout, youttrue, decimal=4)
207225
np.testing.assert_array_almost_equal(tout, t)
208226

227+
# Play with arguments
228+
yout, tout, xout = initial(sys, T=t, X0=x0, return_x=True)
229+
np.testing.assert_array_almost_equal(yout, youttrue, decimal=4)
230+
np.testing.assert_array_almost_equal(tout, t)
231+
209232
#Test MIMO system, which contains ``siso_ss1`` twice
210233
sys = self.mimo_ss1
211234
x0 = np.matrix(".5; 1.; .5; 1.")

control/tests/timeresp_test.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,20 @@ def test_impulse_response(self):
8787
np.testing.assert_array_almost_equal(yout, youttrue, decimal=4)
8888
np.testing.assert_array_almost_equal(tout, t)
8989

90+
# Play with arguments
91+
tout, yout = impulse_response(sys, T=t, X0=0)
92+
np.testing.assert_array_almost_equal(yout, youttrue, decimal=4)
93+
np.testing.assert_array_almost_equal(tout, t)
94+
95+
X0 = np.array([0, 0])
96+
tout, yout = impulse_response(sys, T=t, X0=X0)
97+
np.testing.assert_array_almost_equal(yout, youttrue, decimal=4)
98+
np.testing.assert_array_almost_equal(tout, t)
99+
100+
tout, yout, xout = impulse_response(sys, T=t, X0=0, return_x=True)
101+
np.testing.assert_array_almost_equal(yout, youttrue, decimal=4)
102+
np.testing.assert_array_almost_equal(tout, t)
103+
90104
# Test MIMO system, which contains ``siso_ss1`` twice
91105
sys = self.mimo_ss1
92106
_t, y_00 = impulse_response(sys, T=t, input=0, output=0)
@@ -111,6 +125,11 @@ def test_initial_response(self):
111125
np.testing.assert_array_almost_equal(yout, youttrue, decimal=4)
112126
np.testing.assert_array_almost_equal(tout, t)
113127

128+
# Play with arguments
129+
tout, yout, xout = initial_response(sys, T=t, X0=x0, return_x=True)
130+
np.testing.assert_array_almost_equal(yout, youttrue, decimal=4)
131+
np.testing.assert_array_almost_equal(tout, t)
132+
114133
# Test MIMO system, which contains ``siso_ss1`` twice
115134
sys = self.mimo_ss1
116135
x0 = np.matrix(".5; 1.; .5; 1.")

0 commit comments

Comments
 (0)