From 47cbe7260301771d67b0db57d1030fe6184c2b93 Mon Sep 17 00:00:00 2001 From: Sawyer Fuller Date: Mon, 22 May 2023 14:37:29 -0700 Subject: [PATCH 1/3] fix damp command natural frequency printout for discrete poles on real axis; docstring fixes --- control/lti.py | 62 +++++++++++++++++++++----------------------------- 1 file changed, 26 insertions(+), 36 deletions(-) diff --git a/control/lti.py b/control/lti.py index 216332e91..eae80031c 100644 --- a/control/lti.py +++ b/control/lti.py @@ -2,22 +2,14 @@ The lti module contains the LTI parent class to the child classes StateSpace and TransferFunction. It is designed for use in the python-control library. - -Routines in this module: - -LTI.__init__ -isdtime() -isctime() -timebase() -common_timebase() """ import numpy as np -from numpy import absolute, real, angle, abs +from numpy import real, angle, abs from warnings import warn from . import config -from .namedio import NamedIOSystem, isdtime +from .namedio import NamedIOSystem __all__ = ['poles', 'zeros', 'damp', 'evalfr', 'frequency_response', 'freqresp', 'dcgain', 'bandwidth', 'pole', 'zero'] @@ -110,11 +102,11 @@ def damp(self): Returns ------- wn : array - Natural frequencies for each system pole + Natural frequency for each system pole zeta : array Damping ratio for each system pole poles : array - Array of system poles + System pole locations ''' poles = self.poles() @@ -122,9 +114,9 @@ def damp(self): splane_poles = np.log(poles.astype(complex))/self.dt else: splane_poles = poles - wn = absolute(splane_poles) - Z = -real(splane_poles)/wn - return wn, Z, poles + wn = abs(splane_poles) + zeta = -real(splane_poles)/wn + return wn, zeta, poles def frequency_response(self, omega, squeeze=None): """Evaluate the linear time-invariant system at an array of angular @@ -346,25 +338,23 @@ def zero(sys): def damp(sys, doprint=True): """ - Compute natural frequency, damping ratio, and poles of a system - - The function takes 1 or 2 parameters + Compute natural frequencies, damping ratios, and poles of a system Parameters ---------- sys: LTI (StateSpace or TransferFunction) A linear system object doprint: - if true, print table with values + if True, print table with values Returns ------- - wn: array - Natural frequencies of the poles - damping: array - Damping values - poles: array - Pole locations + wn : array + Natural frequency for each system pole + zeta : array + Damping ratio for each system pole + poles : array + System pole locations See Also -------- @@ -374,37 +364,37 @@ def damp(sys, doprint=True): ----- If the system is continuous, wn = abs(poles) - Z = -real(poles)/poles. + zeta = -real(poles)/poles If the system is discrete, the discrete poles are mapped to their equivalent location in the s-plane via - s = log10(poles)/dt + s = log(poles)/dt and wn = abs(s) - Z = -real(s)/wn. + zeta = -real(s)/wn. Examples -------- >>> G = ct.tf([1], [1, 4]) - >>> wn, damping, poles = ct.damp(G) - _____Eigenvalue______ Damping___ Frequency_ + >>> wn, zeta, poles = ct.damp(G) + Eigenvalue (pole)___ Damping___ Frequency_ -4 1 4 """ - wn, damping, poles = sys.damp() + wn, zeta, poles = sys.damp() if doprint: - print('_____Eigenvalue______ Damping___ Frequency_') - for p, d, w in zip(poles, damping, wn): + print('Eigenvalue (pole)___ Damping___ Frequency_') + for p, z, w in zip(poles, zeta, wn): if abs(p.imag) < 1e-12: print("%10.4g %10.4g %10.4g" % - (p.real, 1.0, -p.real)) + (p.real, 1.0, w)) else: print("%10.4g%+10.4gj %10.4g %10.4g" % - (p.real, p.imag, d, w)) - return wn, damping, poles + (p.real, p.imag, z, w)) + return wn, zeta, poles def evalfr(sys, x, squeeze=None): From cec6b5c64ea34b149011763f025df373cc16a1a6 Mon Sep 17 00:00:00 2001 From: Sawyer Fuller Date: Mon, 22 May 2023 14:40:58 -0700 Subject: [PATCH 2/3] docstring make explicit that doprint is optional --- control/lti.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/control/lti.py b/control/lti.py index eae80031c..39ea768ab 100644 --- a/control/lti.py +++ b/control/lti.py @@ -342,9 +342,9 @@ def damp(sys, doprint=True): Parameters ---------- - sys: LTI (StateSpace or TransferFunction) + sys : LTI (StateSpace or TransferFunction) A linear system object - doprint: + doprint : bool (optional) if True, print table with values Returns From 6cfd4667aee6b6f834a3afc540e163ebef719018 Mon Sep 17 00:00:00 2001 From: Sawyer Fuller Date: Mon, 22 May 2023 21:56:56 -0700 Subject: [PATCH 3/3] output more readable --- control/lti.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/control/lti.py b/control/lti.py index 39ea768ab..c904c1509 100644 --- a/control/lti.py +++ b/control/lti.py @@ -380,19 +380,19 @@ def damp(sys, doprint=True): -------- >>> G = ct.tf([1], [1, 4]) >>> wn, zeta, poles = ct.damp(G) - Eigenvalue (pole)___ Damping___ Frequency_ - -4 1 4 + Eigenvalue (pole) Damping Frequency + -4 1 4 """ wn, zeta, poles = sys.damp() if doprint: - print('Eigenvalue (pole)___ Damping___ Frequency_') + print(' Eigenvalue (pole) Damping Frequency') for p, z, w in zip(poles, zeta, wn): if abs(p.imag) < 1e-12: - print("%10.4g %10.4g %10.4g" % + print(" %10.4g %10.4g %10.4g" % (p.real, 1.0, w)) else: - print("%10.4g%+10.4gj %10.4g %10.4g" % + print("%10.4g%+10.4gj %10.4g %10.4g" % (p.real, p.imag, z, w)) return wn, zeta, poles 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