@@ -403,17 +403,35 @@ def test_mimo_disk_margin():
403403 Lo = P * K # loop transfer function, broken at plant output
404404 Li = K * P # loop transfer function, broken at plant input
405405
406- # Balanced (S - T) disk-based stability margins at plant output
407- DMo , DGMo , DPMo = disk_margins (Lo , omega , skew = 0.0 )
408- assert_allclose ([DMo ], [0.3754 ], atol = 0.1 ) # disk margin of 0.3754
409- assert_allclose ([DGMo ], [3.3 ], atol = 0.1 ) # disk-based gain margin of 3.3 dB
410- assert_allclose ([DPMo ], [21.26 ], atol = 0.1 ) # disk-based phase margin of 21.26 deg
411-
412- # Balanced (S - T) disk-based stability margins at plant input
413- DMi , DGMi , DPMi = disk_margins (Li , omega , skew = 0.0 )
414- assert_allclose ([DMi ], [0.3754 ], atol = 0.1 ) # disk margin of 0.3754
415- assert_allclose ([DGMi ], [3.3 ], atol = 0.1 ) # disk-based gain margin of 3.3 dB
416- assert_allclose ([DPMi ], [21.26 ], atol = 0.1 ) # disk-based phase margin of 21.26 deg
406+ try :
407+ import slycot
408+ except ImportError :
409+ with pytest .raises (ControlMIMONotImplemented ,\
410+ match = "Need slycot to compute MIMO disk_margins" ):
411+
412+ # Balanced (S - T) disk-based stability margins at plant output
413+ DMo , DGMo , DPMo = disk_margins (Lo , omega , skew = 0.0 )
414+ assert_allclose ([DMo ], [0.3754 ], atol = 0.1 ) # disk margin of 0.3754
415+ assert_allclose ([DGMo ], [3.3 ], atol = 0.1 ) # disk-based gain margin of 3.3 dB
416+ assert_allclose ([DPMo ], [21.26 ], atol = 0.1 ) # disk-based phase margin of 21.26 deg
417+
418+ # Balanced (S - T) disk-based stability margins at plant input
419+ DMi , DGMi , DPMi = disk_margins (Li , omega , skew = 0.0 )
420+ assert_allclose ([DMi ], [0.3754 ], atol = 0.1 ) # disk margin of 0.3754
421+ assert_allclose ([DGMi ], [3.3 ], atol = 0.1 ) # disk-based gain margin of 3.3 dB
422+ assert_allclose ([DPMi ], [21.26 ], atol = 0.1 ) # disk-based phase margin of 21.26 deg
423+ else :
424+ # Balanced (S - T) disk-based stability margins at plant output
425+ DMo , DGMo , DPMo = disk_margins (Lo , omega , skew = 0.0 )
426+ assert_allclose ([DMo ], [0.3754 ], atol = 0.1 ) # disk margin of 0.3754
427+ assert_allclose ([DGMo ], [3.3 ], atol = 0.1 ) # disk-based gain margin of 3.3 dB
428+ assert_allclose ([DPMo ], [21.26 ], atol = 0.1 ) # disk-based phase margin of 21.26 deg
429+
430+ # Balanced (S - T) disk-based stability margins at plant input
431+ DMi , DGMi , DPMi = disk_margins (Li , omega , skew = 0.0 )
432+ assert_allclose ([DMi ], [0.3754 ], atol = 0.1 ) # disk margin of 0.3754
433+ assert_allclose ([DGMi ], [3.3 ], atol = 0.1 ) # disk-based gain margin of 3.3 dB
434+ assert_allclose ([DPMi ], [21.26 ], atol = 0.1 ) # disk-based phase margin of 21.26 deg
417435
418436def test_siso_disk_margin_return_all ():
419437 # Frequencies of interest
@@ -443,24 +461,50 @@ def test_mimo_disk_margin_return_all():
443461 Lo = P * K # loop transfer function, broken at plant output
444462 Li = K * P # loop transfer function, broken at plant input
445463
446- # Balanced (S - T) disk-based stability margins at plant output
447- DMo , DGMo , DPMo = disk_margins (Lo , omega , skew = 0.0 , returnall = True )
448- assert_allclose ([omega [np .argmin (DMo )]], [omega [0 ]],\
449- atol = 0.01 ) # sensitivity peak at 0 rad/s (or smallest provided)
450- assert_allclose ([min (DMo )], [0.3754 ], atol = 0.1 ) # disk margin of 0.3754
451- assert_allclose ([DGMo [np .argmin (DMo )]], [3.3 ],\
452- atol = 0.1 ) # disk-based gain margin of 3.3 dB
453- assert_allclose ([DPMo [np .argmin (DMo )]], [21.26 ],\
454- atol = 0.1 ) # disk-based phase margin of 21.26 deg
455-
456- # Balanced (S - T) disk-based stability margins at plant input
457- DMi , DGMi , DPMi = disk_margins (Li , omega , skew = 0.0 , returnall = True )
458- assert_allclose ([omega [np .argmin (DMi )]], [omega [0 ]],\
459- atol = 0.01 ) # sensitivity peak at 0 rad/s (or smallest provided)
460- assert_allclose ([min (DMi )], [0.3754 ],\
461- atol = 0.1 ) # disk margin of 0.3754
462- assert_allclose ([DGMi [np .argmin (DMi )]], [3.3 ],\
463- atol = 0.1 ) # disk-based gain margin of 3.3 dB
464- assert_allclose ([DPMi [np .argmin (DMi )]], [21.26 ],\
465- atol = 0.1 ) # disk-based phase margin of 21.26 deg
466-
464+ try :
465+ import slycot
466+ except ImportError :
467+ with pytest .raises (ControlMIMONotImplemented ,\
468+ match = "Need slycot to compute MIMO disk_margins" ):
469+
470+ # Balanced (S - T) disk-based stability margins at plant output
471+ DMo , DGMo , DPMo = disk_margins (Lo , omega , skew = 0.0 , returnall = True )
472+ assert_allclose ([omega [np .argmin (DMo )]], [omega [0 ]],\
473+ atol = 0.01 ) # sensitivity peak at 0 rad/s (or smallest provided)
474+ assert_allclose ([min (DMo )], [0.3754 ], atol = 0.1 ) # disk margin of 0.3754
475+ assert_allclose ([DGMo [np .argmin (DMo )]], [3.3 ],\
476+ atol = 0.1 ) # disk-based gain margin of 3.3 dB
477+ assert_allclose ([DPMo [np .argmin (DMo )]], [21.26 ],\
478+ atol = 0.1 ) # disk-based phase margin of 21.26 deg
479+
480+ # Balanced (S - T) disk-based stability margins at plant input
481+ DMi , DGMi , DPMi = disk_margins (Li , omega , skew = 0.0 , returnall = True )
482+ assert_allclose ([omega [np .argmin (DMi )]], [omega [0 ]],\
483+ atol = 0.01 ) # sensitivity peak at 0 rad/s (or smallest provided)
484+ assert_allclose ([min (DMi )], [0.3754 ],\
485+ atol = 0.1 ) # disk margin of 0.3754
486+ assert_allclose ([DGMi [np .argmin (DMi )]], [3.3 ],\
487+ atol = 0.1 ) # disk-based gain margin of 3.3 dB
488+ assert_allclose ([DPMi [np .argmin (DMi )]], [21.26 ],\
489+ atol = 0.1 ) # disk-based phase margin of 21.26 deg
490+ else :
491+ # Balanced (S - T) disk-based stability margins at plant output
492+ DMo , DGMo , DPMo = disk_margins (Lo , omega , skew = 0.0 , returnall = True )
493+ assert_allclose ([omega [np .argmin (DMo )]], [omega [0 ]],\
494+ atol = 0.01 ) # sensitivity peak at 0 rad/s (or smallest provided)
495+ assert_allclose ([min (DMo )], [0.3754 ], atol = 0.1 ) # disk margin of 0.3754
496+ assert_allclose ([DGMo [np .argmin (DMo )]], [3.3 ],\
497+ atol = 0.1 ) # disk-based gain margin of 3.3 dB
498+ assert_allclose ([DPMo [np .argmin (DMo )]], [21.26 ],\
499+ atol = 0.1 ) # disk-based phase margin of 21.26 deg
500+
501+ # Balanced (S - T) disk-based stability margins at plant input
502+ DMi , DGMi , DPMi = disk_margins (Li , omega , skew = 0.0 , returnall = True )
503+ assert_allclose ([omega [np .argmin (DMi )]], [omega [0 ]],\
504+ atol = 0.01 ) # sensitivity peak at 0 rad/s (or smallest provided)
505+ assert_allclose ([min (DMi )], [0.3754 ],\
506+ atol = 0.1 ) # disk margin of 0.3754
507+ assert_allclose ([DGMi [np .argmin (DMi )]], [3.3 ],\
508+ atol = 0.1 ) # disk-based gain margin of 3.3 dB
509+ assert_allclose ([DPMi [np .argmin (DMi )]], [21.26 ],\
510+ atol = 0.1 ) # disk-based phase margin of 21.26 deg
0 commit comments