1111from numpy .testing import assert_array_almost_equal
1212from numpy import array , asarray , matrix , asmatrix , zeros , ones , linspace ,\
1313 all , hstack , vstack , c_ , r_
14- from matplotlib .pylab import show , figure , plot , legend , subplot2grid
14+ from matplotlib .pyplot import show , figure , plot , legend , subplot2grid
1515from control .matlab import ss , step , impulse , initial , lsim , dcgain , \
1616 ss2tf
1717from control .statesp import _mimo2siso
@@ -24,29 +24,13 @@ class TestControlMatlab(unittest.TestCase):
2424 def setUp (self ):
2525 pass
2626
27- def plot_matrix (self ):
28- #Test: can matplotlib correctly plot matrices?
29- #Yes, but slightly inconvenient
30- figure ()
31- t = matrix ([[ 1. ],
32- [ 2. ],
33- [ 3. ],
34- [ 4. ]])
35- y = matrix ([[ 1. , 4. ],
36- [ 4. , 5. ],
37- [ 9. , 6. ],
38- [16. , 7. ]])
39- plot (t , y )
40- #plot(asarray(t)[0], asarray(y)[0])
41-
42-
4327 def make_SISO_mats (self ):
4428 """Return matrices for a SISO system"""
45- A = matrix ([[- 81.82 , - 45.45 ],
29+ A = array ([[- 81.82 , - 45.45 ],
4630 [ 10. , - 1. ]])
47- B = matrix ([[9.09 ],
31+ B = array ([[9.09 ],
4832 [0. ]])
49- C = matrix ([[0 , 0.159 ]])
33+ C = array ([[0 , 0.159 ]])
5034 D = zeros ((1 , 1 ))
5135 return A , B , C , D
5236
@@ -181,7 +165,7 @@ def test_impulse(self):
181165
182166 #Test MIMO system
183167 A , B , C , D = self .make_MIMO_mats ()
184- sys = ss (A , B , C , D )
168+ sys = ss (A , B , C , D )
185169 t , y = impulse (sys )
186170 plot (t , y , label = 'MIMO System' )
187171
@@ -202,7 +186,7 @@ def test_initial(self):
202186
203187 #X0=[1,1] : produces a spike
204188 subplot2grid (plot_shape , (0 , 1 ))
205- t , y = initial (sys , X0 = matrix ("1; 1" ))
189+ t , y = initial (sys , X0 = array ( matrix ("1; 1" ) ))
206190 plot (t , y )
207191
208192 #Test MIMO system
@@ -318,21 +302,11 @@ def test_lsim(self):
318302 plot (t , y , label = 'y' )
319303 legend (loc = 'best' )
320304
321- #Test with matrices
322- subplot2grid (plot_shape , (1 , 0 ))
323- t = matrix (linspace (0 , 1 , 100 ))
324- u = matrix (r_ [1 :1 :50j , 0 :0 :50j ])
325- x0 = matrix ("0.; 0" )
326- y , t_out , _x = lsim (sys , u , t , x0 )
327- plot (t_out , y , label = 'y' )
328- plot (t_out , asarray (u / 10 )[0 ], label = 'u/10' )
329- legend (loc = 'best' )
330-
331305 #Test with MIMO system
332306 subplot2grid (plot_shape , (1 , 1 ))
333307 A , B , C , D = self .make_MIMO_mats ()
334308 sys = ss (A , B , C , D )
335- t = matrix (linspace (0 , 1 , 100 ))
309+ t = array (linspace (0 , 1 , 100 ))
336310 u = array ([r_ [1 :1 :50j , 0 :0 :50j ],
337311 r_ [0 :1 :50j , 0 :0 :50j ]])
338312 x0 = [0 , 0 , 0 , 0 ]
@@ -404,12 +378,12 @@ def test_convert_MIMO_to_SISO(self):
404378 #Test with additional systems --------------------------------------------
405379 #They have crossed inputs and direct feedthrough
406380 #SISO system
407- As = matrix ([[- 81.82 , - 45.45 ],
381+ As = array ([[- 81.82 , - 45.45 ],
408382 [ 10. , - 1. ]])
409- Bs = matrix ([[9.09 ],
383+ Bs = array ([[9.09 ],
410384 [0. ]])
411- Cs = matrix ([[0 , 0.159 ]])
412- Ds = matrix ([[0.02 ]])
385+ Cs = array ([[0 , 0.159 ]])
386+ Ds = array ([[0.02 ]])
413387 sys_siso = ss (As , Bs , Cs , Ds )
414388 # t, y = step(sys_siso)
415389 # plot(t, y, label='sys_siso d=0.02')
@@ -428,7 +402,7 @@ def test_convert_MIMO_to_SISO(self):
428402 [0 , 0 ]])
429403 Cm = array ([[0 , 0 , 0 , 0.159 ],
430404 [0 , 0.159 , 0 , 0 ]])
431- Dm = matrix ([[0 , 0.02 ],
405+ Dm = array ([[0 , 0.02 ],
432406 [0.02 , 0 ]])
433407 sys_mimo = ss (Am , Bm , Cm , Dm )
434408
0 commit comments