Skip to content

Commit 65b4e49

Browse files
committed
TST:
- added discrete-time example - added tests with more than one frequency point
1 parent 0607314 commit 65b4e49

2 files changed

Lines changed: 3111 additions & 47 deletions

File tree

control/tests/freqresp_test.py

Lines changed: 44 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -524,69 +524,91 @@ def __repr__(self):
524524

525525

526526
@pytest.fixture
527-
def ss_mimo_t():
527+
def ss_mimo_ct():
528528
A = np.diag([-1/75.0, -1/75.0])
529529
B = np.array([[87.8, -86.4],
530530
[108.2, -109.6]])/75.0
531531
C = np.eye(2)
532532
D = np.zeros((2, 2))
533533
T = TSys(ss(A, B, C, D))
534-
T.omega = 0.0
535-
T.sigma = np.array([[197.20868123], [1.39141948]])
534+
T.omegas = [0.0, [0.0], np.array([0.0, 0.01])]
535+
T.sigmas = [np.array([[197.20868123], [1.39141948]]),
536+
np.array([[197.20868123], [1.39141948]]),
537+
np.array([[197.20868123, 157.76694498], [1.39141948, 1.11313558]])
538+
]
536539
return T
537540

538541

539542
@pytest.fixture
540-
def ss_miso_t():
543+
def ss_miso_ct():
541544
A = np.diag([-1 / 75.0])
542545
B = np.array([[87.8, -86.4]]) / 75.0
543546
C = np.array([[1]])
544547
D = np.zeros((1, 2))
545548
T = TSys(ss(A, B, C, D))
546-
T.omega = 0.0
547-
T.sigma = np.array([[123.1819792]])
549+
T.omegas = [0.0, np.array([0.0, 0.01])]
550+
T.sigmas = [np.array([[123.1819792]]),
551+
np.array([[123.1819792, 98.54558336]])]
548552
return T
549553

550554

551555
@pytest.fixture
552-
def ss_simo_t():
556+
def ss_simo_ct():
553557
A = np.diag([-1 / 75.0])
554558
B = np.array([[1.0]]) / 75.0
555559
C = np.array([[87.8], [108.2]])
556560
D = np.zeros((2, 1))
557561
T = TSys(ss(A, B, C, D))
558-
T.omega = 0.0
559-
T.sigma = np.array([[139.34159465]])
562+
T.omegas = [0.0, np.array([0.0, 0.01])]
563+
T.sigmas = [np.array([[139.34159465]]),
564+
np.array([[139.34159465, 111.47327572]])]
560565
return T
561566

562567

563568
@pytest.fixture
564-
def ss_siso_t():
569+
def ss_siso_ct():
565570
A = np.diag([-1 / 75.0])
566571
B = np.array([[1.0]]) / 75.0
567572
C = np.array([[87.8]])
568573
D = np.zeros((1, 1))
569574
T = TSys(ss(A, B, C, D))
570-
T.omega = 0.0
571-
T.sigma = np.array([[87.8]])
575+
T.omegas = [0.0]
576+
T.sigmas = [np.array([[87.8]]),
577+
np.array([[87.8, 70.24]])]
572578
return T
573579

574580

575581
@pytest.fixture
576-
def tsystem(request, ss_mimo_t, ss_miso_t, ss_simo_t, ss_siso_t):
582+
def ss_mimo_dt():
583+
A = np.array([[0.98675516, 0.],
584+
[0., 0.98675516]])
585+
B = np.array([[1.16289679, -1.14435402],
586+
[1.43309149, -1.45163427]])
587+
C = np.eye(2)
588+
D = np.zeros((2, 2))
589+
T = TSys(ss(A, B, C, D, dt=1.0))
590+
T.omegas = [0.0, np.array([0.0, 0.001, 0.01])]
591+
T.sigmas = [np.array([[197.20865428], [1.39141936]]),
592+
np.array([[197.20865428, 196.6563423, 157.76758858],
593+
[1.39141936, 1.38752248, 1.11314018]])]
594+
return T
595+
596+
@pytest.fixture
597+
def tsystem(request, ss_mimo_ct, ss_miso_ct, ss_simo_ct, ss_siso_ct, ss_mimo_dt):
577598

578-
systems = {"ss_mimo": ss_mimo_t,
579-
"ss_miso": ss_miso_t,
580-
"ss_simo": ss_simo_t,
581-
"ss_siso": ss_siso_t
599+
systems = {"ss_mimo_ct": ss_mimo_ct,
600+
"ss_miso_ct": ss_miso_ct,
601+
"ss_simo_ct": ss_simo_ct,
602+
"ss_siso_ct": ss_siso_ct,
603+
"ss_mimo_dt": ss_mimo_dt
582604
}
583605
return systems[request.param]
584606

585607

586-
@pytest.mark.parametrize("tsystem", ["ss_mimo", "ss_miso", "ss_simo", "ss_siso"], indirect=["tsystem"])
608+
@pytest.mark.parametrize("tsystem",
609+
["ss_mimo_ct", "ss_miso_ct", "ss_simo_ct", "ss_siso_ct", "ss_mimo_dt"], indirect=["tsystem"])
587610
def test_singular_values_plot(tsystem):
588611
sys = tsystem.sys
589-
omega = tsystem.omega
590-
sigma_check = tsystem.sigma
591-
sigma, omega = singular_values_plot(sys, omega, plot=False)
592-
np.testing.assert_almost_equal(sigma, sigma_check)
612+
for omega_ref, sigma_ref in zip(tsystem.omegas, tsystem.sigmas):
613+
sigma, _ = singular_values_plot(sys, omega_ref, plot=False)
614+
np.testing.assert_almost_equal(sigma, sigma_ref)

0 commit comments

Comments
 (0)