Skip to content

Commit bbf605d

Browse files
committed
Add MIMO-SISO truediv and rtruediv
1 parent cda9afe commit bbf605d

2 files changed

Lines changed: 57 additions & 10 deletions

File tree

control/frdata.py

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -510,11 +510,9 @@ def __truediv__(self, other):
510510
else:
511511
other = _convert_to_frd(other, omega=self.omega)
512512

513-
if (self.ninputs > 1 or self.noutputs > 1 or
514-
other.ninputs > 1 or other.noutputs > 1):
515-
raise NotImplementedError(
516-
"FRD.__truediv__ is currently only implemented for SISO "
517-
"systems.")
513+
if (other.ninputs > 1 or other.noutputs > 1):
514+
# FRD.__truediv__ is currently only implemented for SISO systems
515+
return NotImplemented
518516

519517
return FRD(self.fresp/other.fresp, self.omega,
520518
smooth=(self.ifunc is not None) and
@@ -529,11 +527,9 @@ def __rtruediv__(self, other):
529527
else:
530528
other = _convert_to_frd(other, omega=self.omega)
531529

532-
if (self.ninputs > 1 or self.noutputs > 1 or
533-
other.ninputs > 1 or other.noutputs > 1):
534-
raise NotImplementedError(
535-
"FRD.__rtruediv__ is currently only implemented for "
536-
"SISO systems.")
530+
if (self.ninputs > 1 or self.noutputs > 1):
531+
# FRD.__rtruediv__ is currently only implemented for SISO systems
532+
return NotImplemented
537533

538534
return other / self
539535

control/tests/frd_test.py

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -565,6 +565,57 @@ def test_mul_mimo_siso(self, left, right, expected):
565565
np.testing.assert_array_almost_equal(expected_frd.omega, result.omega)
566566
np.testing.assert_array_almost_equal(expected_frd.fresp, result.fresp)
567567

568+
def test_truediv_mimo_siso(self):
569+
omega = np.logspace(-1, 1, 10)
570+
tf_mimo = TransferFunction([1], [1, 0]) * np.eye(2)
571+
frd_mimo = frd(tf_mimo, omega)
572+
ss_mimo = ct.tf2ss(tf_mimo)
573+
tf_siso = TransferFunction([1], [1, 1])
574+
frd_siso = frd(tf_siso, omega)
575+
expected = frd(tf_mimo.__truediv__(tf_siso), omega)
576+
ss_siso = ct.tf2ss(tf_siso)
577+
578+
# Test division of MIMO FRD by SISO FRD
579+
result = frd_mimo.__truediv__(frd_siso)
580+
np.testing.assert_array_almost_equal(expected.omega, result.omega)
581+
np.testing.assert_array_almost_equal(expected.fresp, result.fresp)
582+
583+
# Test division of MIMO FRD by SISO TF
584+
result = frd_mimo.__truediv__(tf_siso)
585+
np.testing.assert_array_almost_equal(expected.omega, result.omega)
586+
np.testing.assert_array_almost_equal(expected.fresp, result.fresp)
587+
588+
# Test division of MIMO FRD by SISO TF
589+
result = frd_mimo.__truediv__(ss_siso)
590+
np.testing.assert_array_almost_equal(expected.omega, result.omega)
591+
np.testing.assert_array_almost_equal(expected.fresp, result.fresp)
592+
593+
def test_rtruediv_mimo_siso(self):
594+
omega = np.logspace(-1, 1, 10)
595+
tf_mimo = TransferFunction([1], [1, 0]) * np.eye(2)
596+
frd_mimo = frd(tf_mimo, omega)
597+
ss_mimo = ct.tf2ss(tf_mimo)
598+
tf_siso = TransferFunction([1], [1, 1])
599+
frd_siso = frd(tf_siso, omega)
600+
ss_siso = ct.tf2ss(tf_siso)
601+
expected = frd(tf_siso.__rtruediv__(tf_mimo), omega)
602+
603+
# Test division of MIMO FRD by SISO FRD
604+
result = frd_siso.__rtruediv__(frd_mimo)
605+
np.testing.assert_array_almost_equal(expected.omega, result.omega)
606+
np.testing.assert_array_almost_equal(expected.fresp, result.fresp)
607+
608+
# Test division of MIMO TF by SISO FRD
609+
result = frd_siso.__rtruediv__(tf_mimo)
610+
np.testing.assert_array_almost_equal(expected.omega, result.omega)
611+
np.testing.assert_array_almost_equal(expected.fresp, result.fresp)
612+
613+
# Test division of MIMO SS by SISO FRD
614+
result = frd_siso.__rtruediv__(ss_mimo)
615+
np.testing.assert_array_almost_equal(expected.omega, result.omega)
616+
np.testing.assert_array_almost_equal(expected.fresp, result.fresp)
617+
618+
568619
@pytest.mark.parametrize(
569620
"left, right, expected",
570621
[

0 commit comments

Comments
 (0)