1111import pytest
1212
1313
14- def test_norm_1st_order_stable_system ():
14+ @pytest .mark .parametrize ("method" , ["slycot" , "scipy" , None ])
15+ def test_norm_1st_order_stable_system (method ):
1516 """First-order stable continuous-time system"""
1617 s = ct .tf ('s' )
1718
1819 G1 = 1 / (s + 1 )
19- assert np .allclose (ct .norm (G1 , p = 'inf' ), 1.0 ) # Comparison to norm computed in MATLAB
20- assert np .allclose (ct .norm (G1 , p = 2 ), 0.707106781186547 ) # Comparison to norm computed in MATLAB
20+ assert np .allclose (ct .norm (G1 , p = 'inf' , method = method ), 1.0 ) # Comparison to norm computed in MATLAB
21+ assert np .allclose (ct .norm (G1 , p = 2 , method = method ), 0.707106781186547 ) # Comparison to norm computed in MATLAB
2122
2223 Gd1 = ct .sample_system (G1 , 0.1 )
23- assert np .allclose (ct .norm (Gd1 , p = 'inf' ), 1.0 ) # Comparison to norm computed in MATLAB
24- assert np .allclose (ct .norm (Gd1 , p = 2 ), 0.223513699524858 ) # Comparison to norm computed in MATLAB
24+ assert np .allclose (ct .norm (Gd1 , p = 'inf' , method = method ), 1.0 ) # Comparison to norm computed in MATLAB
25+ assert np .allclose (ct .norm (Gd1 , p = 2 , method = method ), 0.223513699524858 ) # Comparison to norm computed in MATLAB
2526
2627
27- def test_norm_1st_order_unstable_system ():
28+ @pytest .mark .parametrize ("method" , ["slycot" , "scipy" , None ])
29+ def test_norm_1st_order_unstable_system (method ):
2830 """First-order unstable continuous-time system"""
2931 s = ct .tf ('s' )
3032
3133 G2 = 1 / (1 - s )
32- assert np .allclose (ct .norm (G2 , p = 'inf' ), 1.0 ) # Comparison to norm computed in MATLAB
34+ assert np .allclose (ct .norm (G2 , p = 'inf' , method = method ), 1.0 ) # Comparison to norm computed in MATLAB
3335 with pytest .warns (UserWarning , match = "System is unstable!" ):
34- assert ct .norm (G2 , p = 2 ) == float ('inf' ) # Comparison to norm computed in MATLAB
36+ assert ct .norm (G2 , p = 2 , method = method ) == float ('inf' ) # Comparison to norm computed in MATLAB
3537
3638 Gd2 = ct .sample_system (G2 , 0.1 )
37- assert np .allclose (ct .norm (Gd2 , p = 'inf' ), 1.0 ) # Comparison to norm computed in MATLAB
39+ assert np .allclose (ct .norm (Gd2 , p = 'inf' , method = method ), 1.0 ) # Comparison to norm computed in MATLAB
3840 with pytest .warns (UserWarning , match = "System is unstable!" ):
39- assert ct .norm (Gd2 , p = 2 ) == float ('inf' ) # Comparison to norm computed in MATLAB
41+ assert ct .norm (Gd2 , p = 2 , method = method ) == float ('inf' ) # Comparison to norm computed in MATLAB
4042
41- def test_norm_2nd_order_system_imag_poles ():
43+ @pytest .mark .parametrize ("method" , ["slycot" , "scipy" , None ])
44+ def test_norm_2nd_order_system_imag_poles (method ):
4245 """Second-order continuous-time system with poles on imaginary axis"""
4346 s = ct .tf ('s' )
4447
4548 G3 = 1 / (s ** 2 + 1 )
4649 with pytest .warns (UserWarning , match = "Poles close to, or on, the imaginary axis." ):
47- assert ct .norm (G3 , p = 'inf' ) == float ('inf' ) # Comparison to norm computed in MATLAB
50+ assert ct .norm (G3 , p = 'inf' , method = method ) == float ('inf' ) # Comparison to norm computed in MATLAB
4851 with pytest .warns (UserWarning , match = "Poles close to, or on, the imaginary axis." ):
49- assert ct .norm (G3 , p = 2 ) == float ('inf' ) # Comparison to norm computed in MATLAB
52+ assert ct .norm (G3 , p = 2 , method = method ) == float ('inf' ) # Comparison to norm computed in MATLAB
5053
5154 Gd3 = ct .sample_system (G3 , 0.1 )
5255 with pytest .warns (UserWarning , match = "Poles close to, or on, the complex unit circle." ):
53- assert ct .norm (Gd3 , p = 'inf' ) == float ('inf' ) # Comparison to norm computed in MATLAB
56+ assert ct .norm (Gd3 , p = 'inf' , method = method ) == float ('inf' ) # Comparison to norm computed in MATLAB
5457 with pytest .warns (UserWarning , match = "Poles close to, or on, the complex unit circle." ):
55- assert ct .norm (Gd3 , p = 2 ) == float ('inf' ) # Comparison to norm computed in MATLAB
58+ assert ct .norm (Gd3 , p = 2 , method = method ) == float ('inf' ) # Comparison to norm computed in MATLAB
5659
57- def test_norm_3rd_order_mimo_system ():
60+ @pytest .mark .parametrize ("method" , ["slycot" , "scipy" , None ])
61+ def test_norm_3rd_order_mimo_system (method ):
5862 """Third-order stable MIMO continuous-time system"""
5963 A = np .array ([[- 1.017041847539126 , - 0.224182952826418 , 0.042538079149249 ],
6064 [- 0.310374015319095 , - 0.516461581407780 , - 0.119195790221750 ],
@@ -66,9 +70,9 @@ def test_norm_3rd_order_mimo_system():
6670 [- 0.863652821988714 , - 1.214117043615409 , - 0.006849328103348 ]])
6771 D = np .zeros ((2 ,2 ))
6872 G4 = ct .ss (A ,B ,C ,D ) # Random system generated in MATLAB
69- assert np .allclose (ct .norm (G4 , p = 'inf' ), 4.276759162964244 ) # Comparison to norm computed in MATLAB
70- assert np .allclose (ct .norm (G4 , p = 2 ), 2.237461821810309 ) # Comparison to norm computed in MATLAB
73+ assert np .allclose (ct .norm (G4 , p = 'inf' , method = method ), 4.276759162964244 ) # Comparison to norm computed in MATLAB
74+ assert np .allclose (ct .norm (G4 , p = 2 , method = method ), 2.237461821810309 ) # Comparison to norm computed in MATLAB
7175
7276 Gd4 = ct .sample_system (G4 , 0.1 )
73- assert np .allclose (ct .norm (Gd4 , p = 'inf' ), 4.276759162964228 ) # Comparison to norm computed in MATLAB
74- assert np .allclose (ct .norm (Gd4 , p = 2 ), 0.707434962289554 ) # Comparison to norm computed in MATLAB
77+ assert np .allclose (ct .norm (Gd4 , p = 'inf' , method = method ), 4.276759162964228 ) # Comparison to norm computed in MATLAB
78+ assert np .allclose (ct .norm (Gd4 , p = 2 , method = method ), 0.707434962289554 ) # Comparison to norm computed in MATLAB
0 commit comments