diff --git a/control/modelsimp.py b/control/modelsimp.py index a2eb065b3..3c1828d86 100644 --- a/control/modelsimp.py +++ b/control/modelsimp.py @@ -250,7 +250,7 @@ def _expand_key(key): Cr = Cr[keep_outputs, :] Dr = Dr[keep_outputs, :][:, keep_inputs] - rsys = StateSpace(Ar, Br, Cr, Dr) + rsys = StateSpace(Ar, Br, Cr, Dr, sys.dt) return rsys diff --git a/control/tests/modelsimp_test.py b/control/tests/modelsimp_test.py index c2773231b..10ebf0c93 100644 --- a/control/tests/modelsimp_test.py +++ b/control/tests/modelsimp_test.py @@ -509,3 +509,19 @@ def test_model_reduction(method, kwargs, nstates, noutputs, ninputs): sys.A, sys.B[:, :ninputs], sys.C[:noutputs, :], sys.D[:noutputs, :][:, :ninputs]) np.testing.assert_allclose(red(0), chk(0)) + + +@pytest.mark.parametrize("dt", [0, None, True, 0.1]) +@pytest.mark.parametrize("method, kwargs", [ + ('truncate', {'elim_states': [1]}), + ('truncate', {'elim_states': [0, 1]}), + ('truncate', {'elim_inputs': [1], 'elim_outputs': [1]}), + ('matchdc', {'elim_inputs': [1], 'elim_outputs': [1]}), +]) +def test_model_reduction_preserves_timebase(dt, method, kwargs): + sys = ct.ss([[-0.2, 0], [0, -0.5]], np.eye(2), np.eye(2), + np.zeros((2, 2)), dt=dt) + red = ct.model_reduction(sys, method=method, **kwargs) + + assert red.dt == dt + assert type(red.dt) is type(dt)