From 78b6fc255c5d4708b21960619e66751d47abe8d5 Mon Sep 17 00:00:00 2001 From: choqueuse Date: Tue, 17 Aug 2021 19:22:01 +0200 Subject: [PATCH 1/2] fix the return of the damp method for discrete time systems with a negative real-valued pole --- control/lti.py | 1 + control/tests/lti_test.py | 9 +++++++++ 2 files changed, 10 insertions(+) diff --git a/control/lti.py b/control/lti.py index ef5d5569a..0e53ed5f9 100644 --- a/control/lti.py +++ b/control/lti.py @@ -159,6 +159,7 @@ def damp(self): poles = self.pole() if isdtime(self, strict=True): + poles = poles.astype(complex) splane_poles = np.log(poles)/self.dt else: splane_poles = poles diff --git a/control/tests/lti_test.py b/control/tests/lti_test.py index 9156ecb7e..defcba21e 100644 --- a/control/tests/lti_test.py +++ b/control/tests/lti_test.py @@ -70,6 +70,15 @@ def test_damp(self): np.testing.assert_almost_equal(sys_dt.damp(), expected_dt) np.testing.assert_almost_equal(damp(sys_dt), expected_dt) + #also check that for a discrete system with a negative real pole the damp function can extract wn and theta. + p2_zplane = -0.2 + sys_dt2 = tf(1,[1,-p2_zplane],dt) + wn2, zeta2, _ = sys_dt2.damp() + p2 = -wn2 * zeta2 + 1j * wn2 * np.sqrt(1 - zeta2**2) + p2_zplane = np.exp(p2*dt) + np.testing.assert_almost_equal(sys_dt2.pole(),p2_zplane) + + def test_dcgain(self): sys = tf(84, [1, 2]) np.testing.assert_allclose(sys.dcgain(), 42) From 140ca08fc7ad3dc64b1b5dcb28327ec8647cb205 Mon Sep 17 00:00:00 2001 From: choqueuse Date: Wed, 18 Aug 2021 08:43:42 +0200 Subject: [PATCH 2/2] fix PEP8 compliance style and preserve pole type --- control/lti.py | 3 +-- control/tests/lti_test.py | 13 ++++++------- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/control/lti.py b/control/lti.py index 0e53ed5f9..b56c2bb44 100644 --- a/control/lti.py +++ b/control/lti.py @@ -159,8 +159,7 @@ def damp(self): poles = self.pole() if isdtime(self, strict=True): - poles = poles.astype(complex) - splane_poles = np.log(poles)/self.dt + splane_poles = np.log(poles.astype(complex))/self.dt else: splane_poles = poles wn = absolute(splane_poles) diff --git a/control/tests/lti_test.py b/control/tests/lti_test.py index defcba21e..7e4f0ddb4 100644 --- a/control/tests/lti_test.py +++ b/control/tests/lti_test.py @@ -70,15 +70,14 @@ def test_damp(self): np.testing.assert_almost_equal(sys_dt.damp(), expected_dt) np.testing.assert_almost_equal(damp(sys_dt), expected_dt) - #also check that for a discrete system with a negative real pole the damp function can extract wn and theta. + #also check that for a discrete system with a negative real pole the damp function can extract wn and zeta. p2_zplane = -0.2 - sys_dt2 = tf(1,[1,-p2_zplane],dt) - wn2, zeta2, _ = sys_dt2.damp() - p2 = -wn2 * zeta2 + 1j * wn2 * np.sqrt(1 - zeta2**2) - p2_zplane = np.exp(p2*dt) - np.testing.assert_almost_equal(sys_dt2.pole(),p2_zplane) + sys_dt2 = tf(1, [1, -p2_zplane], dt) + wn2, zeta2, p2 = sys_dt2.damp() + p2_splane = -wn2 * zeta2 + 1j * wn2 * np.sqrt(1 - zeta2**2) + p2_zplane = np.exp(p2_splane * dt) + np.testing.assert_almost_equal(p2, p2_zplane) - def test_dcgain(self): sys = tf(84, [1, 2]) np.testing.assert_allclose(sys.dcgain(), 42) pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy