def test_similarity_transform(): sys = Alpha(0.1) TA, TB, TC, TD = sys.transform(np.eye(2), np.eye(2)).ss A, B, C, D = sys2ss(sys) assert np.allclose(A, TA) assert np.allclose(B, TB) assert np.allclose(C, TC) assert np.allclose(D, TD) T = [[1, 1], [-0.5, 0]] rsys = sys.transform(T) assert ss_equal(rsys, sys.transform(T, inv(T))) TA, TB, TC, TD = rsys.ss assert not np.allclose(A, TA) assert not np.allclose(B, TB) assert not np.allclose(C, TC) assert np.allclose(D, TD) assert sys_equal(sys, (TA, TB, TC, TD)) length = 1000 dt = 0.001 x_old = np.asarray( [sub.impulse(length=length, dt=dt) for sub in sys]) x_new = np.asarray( [sub.impulse(length=length, dt=dt) for sub in rsys]) # dot(T, x_new(t)) = x_old(t) assert np.allclose(np.dot(T, x_new), x_old)
def test_identity(radii): sys = Alpha(0.1) identity = Identity() assert repr(identity) == "Identity()" I = np.eye(len(sys)) realize_result = identity(sys, radii) assert realize_result.sys is sys assert np.allclose(realize_result.T, I * radii) assert np.allclose(realize_result.Tinv, inv(I * radii)) rsys = realize_result.realization assert ss_equal(rsys, sys.transform(realize_result.T)) # Check that it's still the same system, even though different matrices assert sys_equal(sys, rsys) if radii == 1: assert ss_equal(sys, rsys) else: assert not np.allclose(sys.B, rsys.B) assert not np.allclose(sys.C, rsys.C) # Check that the state vectors have scaled power assert np.allclose(state_norm(sys) / radii, state_norm(rsys))
def test_func_realize(radii): sys = Alpha(0.1) T = np.asarray([[1., 2.], [0, -1.]]) for Tinv in (None, inv(T)): realize_result = _realize(sys, radii, T, Tinv) assert realize_result.sys is sys assert np.allclose(inv(realize_result.T), realize_result.Tinv) rsys = realize_result.realization assert ss_equal(rsys, sys.transform(realize_result.T)) # Check that the state vector are related by T length = 1000 dt = 0.001 x_old = np.asarray([sub.impulse(length, dt) for sub in sys]) x_new = np.asarray([sub.impulse(length, dt) for sub in rsys]) r = np.atleast_2d(np.asarray(radii).T).T assert np.allclose(np.dot(T, x_new * r), x_old)