@@ -731,6 +731,32 @@ def test_discrete(self, tsys):
731731 np .testing .assert_allclose (ios_t , lin_t ,atol = 0.002 ,rtol = 0. )
732732 np .testing .assert_allclose (ios_y , lin_y ,atol = 0.002 ,rtol = 0. )
733733
734+ def test_discrete_iosys (self , tsys ):
735+ """Create a discrete time system from scratch"""
736+ linsys = ct .StateSpace (
737+ [[- 1 , 1 ], [0 , - 2 ]], [[0 ], [1 ]], [[1 , 0 ]], [[0 ]], True )
738+
739+ # Create nonlinear version of the same system
740+ def nlsys_update (t , x , u , params ):
741+ A , B = params ['A' ], params ['B' ]
742+ return A @ x + B @ u
743+ def nlsys_output (t , x , u , params ):
744+ C = params ['C' ]
745+ return C @ x
746+ nlsys = ct .NonlinearIOSystem (
747+ nlsys_update , nlsys_output , inputs = 1 , outputs = 1 , states = 2 , dt = True )
748+
749+ # Set up parameters for simulation
750+ T , U , X0 = tsys .T , tsys .U , tsys .X0
751+
752+ # Simulate and compare to LTI output
753+ ios_t , ios_y = ios .input_output_response (
754+ nlsys , T , U , X0 ,
755+ params = {'A' : linsys .A , 'B' : linsys .B , 'C' : linsys .C })
756+ lin_t , lin_y = ct .forced_response (linsys , T , U , X0 )
757+ np .testing .assert_allclose (ios_t , lin_t ,atol = 0.002 ,rtol = 0. )
758+ np .testing .assert_allclose (ios_y , lin_y ,atol = 0.002 ,rtol = 0. )
759+
734760 def test_find_eqpts (self , tsys ):
735761 """Test find_eqpt function"""
736762 # Simple equilibrium point with no inputs
@@ -1526,7 +1552,6 @@ def secord_update(t, x, u, params={}):
15261552 """Second order system dynamics"""
15271553 omega0 = params .get ('omega0' , 1. )
15281554 zeta = params .get ('zeta' , 0.5 )
1529- u = np .array (u , ndmin = 1 )
15301555 return np .array ([
15311556 x [1 ],
15321557 - 2 * zeta * omega0 * x [1 ] - omega0 * omega0 * x [0 ] + u [0 ]
0 commit comments