#NEWLINE# def test_discrete_approx( self ) : #NEWLINE# #INDENT# '\n        Test that the solution to the discrete approximation of a continuous\n        system actually approximates the solution to the continuous system.\n        This is an indirect test of the correctness of the implementation\n        of cont2discrete.\n        ' #NEWLINE# def u( t ) : #NEWLINE# #INDENT# return np . sin ( ( 2.5 * t ) ) #NEWLINE# #UNINDENT# a = np . array ( [ [ ( - 0.01 ) ] ] ) #NEWLINE# b = np . array ( [ [ 1.0 ] ] ) #NEWLINE# c = np . array ( [ [ 1.0 ] ] ) #NEWLINE# d = np . array ( [ [ 0.2 ] ] ) #NEWLINE# x0 = 1.0 #NEWLINE# t = np . linspace ( 0 , 10.0 , 101 ) #NEWLINE# dt = ( t [ 1 ] - t [ 0 ] ) #NEWLINE# u1 = u ( t ) #NEWLINE# ( t , yout , xout ) = lsim2 ( ( a , t2 , c , d ) , T = t , U = u1 , X0 = x0 , rtol = 1e-09 , atol = 1e-11 ) #NEWLINE# dsys = c2d ( ( a , b , c , d ) , dt , method = 'bilinear' ) #NEWLINE# u2 = ( 0.5 * ( u1 [ : ( - 1 ) ] + u1 [ 1 : ] ) ) #NEWLINE# t2 = t [ : ( - 1 ) ] #NEWLINE# ( td2 , yd2 , xd2 ) = dlsim ( dsys , u = u2 . reshape ( ( - 1 ) , 1 ) , t = t2 , x0 = x0 ) #NEWLINE# ymid = ( 0.5 * ( yout [ : ( - 1 ) ] + yout [ 1 : ] ) ) #NEWLINE# assert_allclose ( yd2 . ravel ( ) , ymid , rtol = 0.0001 )