33RMM, 30 Mar 2011 (based on TestModelSimp from v0.4a)
44"""
55
6+ import warnings
7+
68import numpy as np
79import pytest
810
11+ import control as ct
912from control import StateSpace , TimeResponseData , c2d , forced_response , \
10- impulse_response , step_response , rss , tf
13+ impulse_response , rss , step_response , tf
1114from control .exception import ControlArgument , ControlDimension
1215from control .modelsimp import balred , eigensys_realization , hsvd , markov , \
1316 modred
@@ -343,7 +346,7 @@ def testModredMatchDC(self):
343346 np .testing .assert_array_almost_equal (rsys .D , Drtrue , decimal = 2 )
344347
345348 def testModredUnstable (self ):
346- """Check if an error is thrown when an unstable system is given"""
349+ """Check if warning is issued when an unstable system is given"""
347350 A = np .array (
348351 [[4.5418 , 3.3999 , 5.0342 , 4.3808 ],
349352 [0.3890 , 0.3599 , 0.4195 , 0.1760 ],
@@ -353,7 +356,16 @@ def testModredUnstable(self):
353356 C = np .array ([[1.0 , 2.0 , 3.0 , 4.0 ], [1.0 , 2.0 , 3.0 , 4.0 ]])
354357 D = np .array ([[0.0 , 0.0 ], [0.0 , 0.0 ]])
355358 sys = StateSpace (A , B , C , D )
356- np .testing .assert_raises (ValueError , modred , sys , [2 , 3 ])
359+
360+ # Make sure we get a warning message
361+ with pytest .warns (UserWarning , match = "System is unstable" ):
362+ newsys1 = modred (sys , [2 , 3 ])
363+
364+ # Make sure we can turn the warning off
365+ with warnings .catch_warnings ():
366+ warnings .simplefilter ('error' )
367+ newsys2 = ct .model_reduction (sys , [2 , 3 ], warn_unstable = False )
368+ np .testing .assert_equal (newsys1 .A , newsys2 .A )
357369
358370 def testModredTruncate (self ):
359371 #balanced realization computed in matlab for the transfer function:
0 commit comments