Skip to content

Commit 39404c4

Browse files
committed
fix bug in the way LinearICSystem.__call__ was implemented (with unit test)
1 parent 0b3ae85 commit 39404c4

File tree

3 files changed

+11
-3
lines changed

3 files changed

+11
-3
lines changed

control/lti.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ def frequency_response(self, omega, squeeze=None):
115115

116116
# Return the data as a frequency response data object
117117
from .frdata import FrequencyResponseData
118-
response = self.__call__(s)
118+
response = self(s)
119119
return FrequencyResponseData(
120120
response, omega, return_magphase=True, squeeze=squeeze)
121121

@@ -365,7 +365,7 @@ def evalfr(sys, x, squeeze=None):
365365
.. todo:: Add example with MIMO system
366366
367367
"""
368-
return sys.__call__(x, squeeze=squeeze)
368+
return sys(x, squeeze=squeeze)
369369

370370

371371
def frequency_response(sys, omega, squeeze=None):

control/statesp.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -1495,7 +1495,8 @@ def __init__(self, io_sys, ss_sys=None):
14951495
params=io_sys.params, remove_useless_states=False)
14961496

14971497
# Use StateSpace.__call__ to evaluate at a given complex value
1498-
self.__call__ = StateSpace.__call__
1498+
def __call__(self, *args, **kwargs):
1499+
return StateSpace.__call__(self, *args, **kwargs)
14991500

15001501
# The following text needs to be replicated from StateSpace in order for
15011502
# this entry to show up properly in sphinx doccumentation (not sure why,

control/tests/iosys_test.py

+7
Original file line numberDiff line numberDiff line change
@@ -1561,6 +1561,13 @@ def test_linear_interconnection():
15611561
assert isinstance(io_connect, ct.LinearICSystem)
15621562
assert isinstance(io_connect, ct.StateSpace)
15631563

1564+
# Make sure call works properly
1565+
response = io_connect.frequency_response(1)
1566+
np.testing.assert_allclose(
1567+
response.fresp[:, :, 0], io_connect.C @ np.linalg.inv(
1568+
1j * np.eye(io_connect.nstates) - io_connect.A) @ io_connect.B + \
1569+
io_connect.D)
1570+
15641571
# Finally compare the linearization with the linear system
15651572
np.testing.assert_array_almost_equal(io_connect.A, ss_connect.A)
15661573
np.testing.assert_array_almost_equal(io_connect.B, ss_connect.B)

0 commit comments

Comments
 (0)