15
15
import scipy as sp
16
16
from control .matlab import *
17
17
from control .frdata import FRD
18
+ from control .exception import slycot_check
18
19
import warnings
19
20
20
21
# for running these through Matlab or Octave
@@ -165,12 +166,13 @@ def testStep(self):
165
166
np .testing .assert_array_almost_equal (yout , youttrue , decimal = 4 )
166
167
np .testing .assert_array_almost_equal (tout , t )
167
168
168
- #Test MIMO system, which contains ``siso_ss1`` twice
169
- sys = self .mimo_ss1
170
- y_00 , _t = step (sys , T = t , input = 0 , output = 0 )
171
- y_11 , _t = step (sys , T = t , input = 1 , output = 1 )
172
- np .testing .assert_array_almost_equal (y_00 , youttrue , decimal = 4 )
173
- np .testing .assert_array_almost_equal (y_11 , youttrue , decimal = 4 )
169
+ if slycot_check ():
170
+ # Test MIMO system, which contains ``siso_ss1`` twice
171
+ sys = self .mimo_ss1
172
+ y_00 , _t = step (sys , T = t , input = 0 , output = 0 )
173
+ y_11 , _t = step (sys , T = t , input = 1 , output = 1 )
174
+ np .testing .assert_array_almost_equal (y_00 , youttrue , decimal = 4 )
175
+ np .testing .assert_array_almost_equal (y_11 , youttrue , decimal = 4 )
174
176
175
177
def testImpulse (self ):
176
178
t = np .linspace (0 , 1 , 10 )
@@ -206,12 +208,13 @@ def testImpulse(self):
206
208
np .testing .assert_array_almost_equal (yout , youttrue , decimal = 4 )
207
209
np .testing .assert_array_almost_equal (tout , t )
208
210
209
- #Test MIMO system, which contains ``siso_ss1`` twice
210
- sys = self .mimo_ss1
211
- y_00 , _t = impulse (sys , T = t , input = 0 , output = 0 )
212
- y_11 , _t = impulse (sys , T = t , input = 1 , output = 1 )
213
- np .testing .assert_array_almost_equal (y_00 , youttrue , decimal = 4 )
214
- np .testing .assert_array_almost_equal (y_11 , youttrue , decimal = 4 )
211
+ if slycot_check ():
212
+ #Test MIMO system, which contains ``siso_ss1`` twice
213
+ sys = self .mimo_ss1
214
+ y_00 , _t = impulse (sys , T = t , input = 0 , output = 0 )
215
+ y_11 , _t = impulse (sys , T = t , input = 1 , output = 1 )
216
+ np .testing .assert_array_almost_equal (y_00 , youttrue , decimal = 4 )
217
+ np .testing .assert_array_almost_equal (y_11 , youttrue , decimal = 4 )
215
218
216
219
def testInitial (self ):
217
220
#Test SISO system
@@ -229,13 +232,14 @@ def testInitial(self):
229
232
np .testing .assert_array_almost_equal (yout , youttrue , decimal = 4 )
230
233
np .testing .assert_array_almost_equal (tout , t )
231
234
232
- #Test MIMO system, which contains ``siso_ss1`` twice
233
- sys = self .mimo_ss1
234
- x0 = np .matrix (".5; 1.; .5; 1." )
235
- y_00 , _t = initial (sys , T = t , X0 = x0 , input = 0 , output = 0 )
236
- y_11 , _t = initial (sys , T = t , X0 = x0 , input = 1 , output = 1 )
237
- np .testing .assert_array_almost_equal (y_00 , youttrue , decimal = 4 )
238
- np .testing .assert_array_almost_equal (y_11 , youttrue , decimal = 4 )
235
+ if slycot_check ():
236
+ #Test MIMO system, which contains ``siso_ss1`` twice
237
+ sys = self .mimo_ss1
238
+ x0 = np .matrix (".5; 1.; .5; 1." )
239
+ y_00 , _t = initial (sys , T = t , X0 = x0 , input = 0 , output = 0 )
240
+ y_11 , _t = initial (sys , T = t , X0 = x0 , input = 1 , output = 1 )
241
+ np .testing .assert_array_almost_equal (y_00 , youttrue , decimal = 4 )
242
+ np .testing .assert_array_almost_equal (y_11 , youttrue , decimal = 4 )
239
243
240
244
def testLsim (self ):
241
245
t = np .linspace (0 , 1 , 10 )
@@ -259,18 +263,19 @@ def testLsim(self):
259
263
yout , _t , _xout = lsim (self .siso_ss1 , u , t , x0 )
260
264
np .testing .assert_array_almost_equal (yout , youttrue , decimal = 4 )
261
265
262
- #Test MIMO system, which contains ``siso_ss1`` twice
263
- #first system: initial value, second system: step response
264
- u = np .array ([[0. , 1. ], [0 , 1 ], [0 , 1 ], [0 , 1 ], [0 , 1 ],
265
- [0 , 1 ], [0 , 1 ], [0 , 1 ], [0 , 1 ], [0 , 1 ]])
266
- x0 = np .matrix (".5; 1; 0; 0" )
267
- youttrue = np .array ([[11. , 9. ], [8.1494 , 17.6457 ], [5.9361 , 24.7072 ],
268
- [4.2258 , 30.4855 ], [2.9118 , 35.2234 ],
269
- [1.9092 , 39.1165 ], [1.1508 , 42.3227 ],
270
- [0.5833 , 44.9694 ], [0.1645 , 47.1599 ],
271
- [- 0.1391 , 48.9776 ]])
272
- yout , _t , _xout = lsim (self .mimo_ss1 , u , t , x0 )
273
- np .testing .assert_array_almost_equal (yout , youttrue , decimal = 4 )
266
+ if slycot_check ():
267
+ #Test MIMO system, which contains ``siso_ss1`` twice
268
+ #first system: initial value, second system: step response
269
+ u = np .array ([[0. , 1. ], [0 , 1 ], [0 , 1 ], [0 , 1 ], [0 , 1 ],
270
+ [0 , 1 ], [0 , 1 ], [0 , 1 ], [0 , 1 ], [0 , 1 ]])
271
+ x0 = np .matrix (".5; 1; 0; 0" )
272
+ youttrue = np .array ([[11. , 9. ], [8.1494 , 17.6457 ],
273
+ [5.9361 , 24.7072 ], [4.2258 , 30.4855 ],
274
+ [2.9118 , 35.2234 ], [1.9092 , 39.1165 ],
275
+ [1.1508 , 42.3227 ], [0.5833 , 44.9694 ],
276
+ [0.1645 , 47.1599 ], [- 0.1391 , 48.9776 ]])
277
+ yout , _t , _xout = lsim (self .mimo_ss1 , u , t , x0 )
278
+ np .testing .assert_array_almost_equal (yout , youttrue , decimal = 4 )
274
279
275
280
def testMargin (self ):
276
281
#! TODO: check results to make sure they are OK
@@ -310,11 +315,12 @@ def testDcgain(self):
310
315
gain_sim ],
311
316
[59 , 59 , 59 , 59 , 59 ])
312
317
313
- # Test with MIMO system, which contains ``siso_ss1`` twice
314
- gain_mimo = dcgain (self .mimo_ss1 )
315
- # print('gain_mimo: \n', gain_mimo)
316
- np .testing .assert_array_almost_equal (gain_mimo , [[59. , 0 ],
317
- [0 , 59. ]])
318
+ if slycot_check ():
319
+ # Test with MIMO system, which contains ``siso_ss1`` twice
320
+ gain_mimo = dcgain (self .mimo_ss1 )
321
+ # print('gain_mimo: \n', gain_mimo)
322
+ np .testing .assert_array_almost_equal (gain_mimo , [[59. , 0 ],
323
+ [0 , 59. ]])
318
324
319
325
def testBode (self ):
320
326
bode (self .siso_ss1 )
@@ -370,29 +376,35 @@ def testEvalfr(self):
370
376
evalfr (self .siso_tf1 , w )
371
377
evalfr (self .siso_tf2 , w )
372
378
evalfr (self .siso_tf3 , w )
373
- np .testing .assert_array_almost_equal (
374
- evalfr (self .mimo_ss1 , w ),
375
- np .array ( [[44.8 - 21.4j , 0. ], [0. , 44.8 - 21.4j ]]))
379
+ if slycot_check ():
380
+ np .testing .assert_array_almost_equal (
381
+ evalfr (self .mimo_ss1 , w ),
382
+ np .array ( [[44.8 - 21.4j , 0. ], [0. , 44.8 - 21.4j ]]))
376
383
384
+ @unittest .skipIf (not slycot_check (), "slycot not installed" )
377
385
def testHsvd (self ):
378
386
hsvd (self .siso_ss1 )
379
387
hsvd (self .siso_ss2 )
380
388
hsvd (self .siso_ss3 )
381
389
390
+ @unittest .skipIf (not slycot_check (), "slycot not installed" )
382
391
def testBalred (self ):
383
392
balred (self .siso_ss1 , 1 )
384
393
balred (self .siso_ss2 , 2 )
385
394
balred (self .siso_ss3 , [2 , 2 ])
386
395
396
+ @unittest .skipIf (not slycot_check (), "slycot not installed" )
387
397
def testModred (self ):
388
398
modred (self .siso_ss1 , [1 ])
389
399
modred (self .siso_ss2 * self .siso_ss3 , [0 , 1 ])
390
400
modred (self .siso_ss3 , [1 ], 'matchdc' )
391
401
modred (self .siso_ss3 , [1 ], 'truncate' )
392
402
403
+ @unittest .skipIf (not slycot_check (), "slycot not installed" )
393
404
def testPlace (self ):
394
405
place (self .siso_ss1 .A , self .siso_ss1 .B , [- 2 , - 2 ])
395
406
407
+ @unittest .skipIf (not slycot_check (), "slycot not installed" )
396
408
def testLQR (self ):
397
409
(K , S , E ) = lqr (self .siso_ss1 .A , self .siso_ss1 .B , np .eye (2 ), np .eye (1 ))
398
410
(K , S , E ) = lqr (self .siso_ss2 .A , self .siso_ss2 .B , np .eye (3 ), \
@@ -416,6 +428,7 @@ def testObsv(self):
416
428
obsv (self .siso_ss1 .A , self .siso_ss1 .C )
417
429
obsv (self .siso_ss2 .A , self .siso_ss2 .C )
418
430
431
+ @unittest .skipIf (not slycot_check (), "slycot not installed" )
419
432
def testGram (self ):
420
433
gram (self .siso_ss1 , 'c' )
421
434
gram (self .siso_ss2 , 'c' )
@@ -452,6 +465,7 @@ def testSISOssdata(self):
452
465
for i in range (len (ssdata_1 )):
453
466
np .testing .assert_array_almost_equal (ssdata_1 [i ], ssdata_2 [i ])
454
467
468
+ @unittest .skipIf (not slycot_check (), "slycot not installed" )
455
469
def testMIMOssdata (self ):
456
470
m = (self .mimo_ss1 .A , self .mimo_ss1 .B , self .mimo_ss1 .C , self .mimo_ss1 .D )
457
471
ssdata_1 = ssdata (self .mimo_ss1 );
@@ -532,6 +546,7 @@ def testFRD(self):
532
546
frd2 = frd (frd1 .fresp [0 ,0 ,:], omega )
533
547
assert isinstance (frd2 , FRD )
534
548
549
+ @unittest .skipIf (not slycot_check (), "slycot not installed" )
535
550
def testMinreal (self , verbose = False ):
536
551
"""Test a minreal model reduction"""
537
552
#A = [-2, 0.5, 0; 0.5, -0.3, 0; 0, 0, -0.1]
0 commit comments