88
99import control as ct
1010import numpy as np
11+ import pytest
12+
1113
1214def test_norm_1st_order_stable_system ():
1315 """First-order stable continuous-time system"""
1416 s = ct .tf ('s' )
17+
1518 G1 = 1 / (s + 1 )
16- assert np .allclose (ct .norm (G1 , p = 'inf' , tol = 1e-9 , print_warning = False ), 1.0 ) # Comparison to norm computed in MATLAB
17- assert np .allclose (ct .norm (G1 , p = 2 , print_warning = False ), 0.707106781186547 ) # Comparison to norm computed in MATLAB
19+ assert np .allclose (ct .norm (G1 , p = 'inf' , tol = 1e-9 ), 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
1821
1922 Gd1 = ct .sample_system (G1 , 0.1 )
20- assert np .allclose (ct .norm (Gd1 , p = 'inf' , tol = 1e-9 , print_warning = False ), 1.0 ) # Comparison to norm computed in MATLAB
21- assert np .allclose (ct .norm (Gd1 , p = 2 , print_warning = False ), 0.223513699524858 ) # Comparison to norm computed in MATLAB
23+ assert np .allclose (ct .norm (Gd1 , p = 'inf' , tol = 1e-9 ), 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
2225
2326
2427def test_norm_1st_order_unstable_system ():
2528 """First-order unstable continuous-time system"""
2629 s = ct .tf ('s' )
30+
2731 G2 = 1 / (1 - s )
28- assert np .allclose (ct .norm (G2 , p = 'inf' , tol = 1e-9 , print_warning = False ), 1.0 ) # Comparison to norm computed in MATLAB
29- assert ct .norm (G2 , p = 2 , print_warning = False ) == float ('inf' ) # Comparison to norm computed in MATLAB
32+ assert np .allclose (ct .norm (G2 , p = 'inf' , tol = 1e-9 ), 1.0 ) # Comparison to norm computed in MATLAB
33+ with pytest .warns (UserWarning , match = "System is unstable!" ):
34+ assert ct .norm (G2 , p = 2 ) == float ('inf' ) # Comparison to norm computed in MATLAB
3035
3136 Gd2 = ct .sample_system (G2 , 0.1 )
32- assert np .allclose (ct .norm (Gd2 , p = 'inf' , tol = 1e-9 , print_warning = False ), 1.0 ) # Comparison to norm computed in MATLAB
33- assert ct .norm (Gd2 , p = 2 , print_warning = False ) == float ('inf' ) # Comparison to norm computed in MATLAB
37+ assert np .allclose (ct .norm (Gd2 , p = 'inf' , tol = 1e-9 ), 1.0 ) # Comparison to norm computed in MATLAB
38+ with pytest .warns (UserWarning , match = "System is unstable!" ):
39+ assert ct .norm (Gd2 , p = 2 ) == float ('inf' ) # Comparison to norm computed in MATLAB
3440
3541def test_norm_2nd_order_system_imag_poles ():
3642 """Second-order continuous-time system with poles on imaginary axis"""
3743 s = ct .tf ('s' )
44+
3845 G3 = 1 / (s ** 2 + 1 )
39- assert ct .norm (G3 , p = 'inf' , print_warning = False ) == float ('inf' ) # Comparison to norm computed in MATLAB
40- assert ct .norm (G3 , p = 2 , print_warning = False ) == float ('inf' ) # Comparison to norm computed in MATLAB
46+ 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
48+ 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
4150
4251 Gd3 = ct .sample_system (G3 , 0.1 )
43- assert ct .norm (Gd3 , p = 'inf' , print_warning = False ) == float ('inf' ) # Comparison to norm computed in MATLAB
44- assert ct .norm (Gd3 , p = 2 , print_warning = False ) == float ('inf' ) # Comparison to norm computed in MATLAB
52+ 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
54+ 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
4556
4657def test_norm_3rd_order_mimo_system ():
4758 """Third-order stable MIMO continuous-time system"""
@@ -55,9 +66,9 @@ def test_norm_3rd_order_mimo_system():
5566 [- 0.863652821988714 , - 1.214117043615409 , - 0.006849328103348 ]])
5667 D = np .zeros ((2 ,2 ))
5768 G4 = ct .ss (A ,B ,C ,D ) # Random system generated in MATLAB
58- assert np .allclose (ct .norm (G4 , p = 'inf' , tol = 1e-9 , print_warning = False ), 4.276759162964244 ) # Comparison to norm computed in MATLAB
59- assert np .allclose (ct .norm (G4 , p = 2 , print_warning = False ), 2.237461821810309 ) # Comparison to norm computed in MATLAB
69+ assert np .allclose (ct .norm (G4 , p = 'inf' , tol = 1e-9 ), 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
6071
6172 Gd4 = ct .sample_system (G4 , 0.1 )
62- assert np .allclose (ct .norm (Gd4 , p = 'inf' , tol = 1e-9 , print_warning = False ), 4.276759162964228 ) # Comparison to norm computed in MATLAB
63- assert np .allclose (ct .norm (Gd4 , p = 2 , print_warning = False ), 0.707434962289554 ) # Comparison to norm computed in MATLAB
73+ assert np .allclose (ct .norm (Gd4 , p = 'inf' , tol = 1e-9 ), 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
0 commit comments