8000 discard zero imaginary part for sys.dcgain() · python-control/python-control@f9db86a · GitHub
[go: up one dir, main page]

Skip to content

Commit f9db86a

Browse files
committed
discard zero imaginary part for sys.dcgain()
1 parent b41574f commit f9db86a

File tree

2 files changed

+31
-9
lines changed

2 files changed

+31
-9
lines changed

control/statesp.py

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1216,16 +1216,29 @@ def dcgain(self, warn_infinite=False):
12161216
12171217
.. math: G(1) = C (I - A)^{-1} B + D
12181218
1219+
Parameters
1220+
----------
1221+
warn_infinite : bool, optional
1222+
By default, don't issue a warning message if the zero-frequency
1223+
gain is infinite. Setting `warn_infinite` to generate the warning
1224+
message.
1225+
12191226
Returns
12201227
-------
1221-
gain : ndarray
1222-
An array of shape (outputs,inputs); the array will either be the
1223-
zero-frequency (or DC) gain, or, if the frequency response is
1224-
singular, the array will be filled with (inf + nanj).
1225-
1228+
gain : (outputs, inputs) ndarray or scalar
1229+
Array or scalar value for SISO systems, depending on
1230+
config.defaults['control.squeeze_frequency_response'].
1231+
The value of the array elements or the scalar is either the
1232+
zero-frequency (or DC) gain, or `inf`, if the frequency response
1233+
is singular.
1234+
1235+
For real valued systems, the empty imaginary part of the
1236+
complex zero-frequency response is discarded and a real array or
1237+
scalaris returned.
12261238
"""
1227-
return self(0, warn_infinite=warn_infinite) if self.isctime() \
1239+
zeroresp = self(0, warn_infinite=warn_infinite) if self.isctime() \
12281240
else self(1, warn_infinite=warn_infinite)
1241+
return zeroresp.real if np.all(np.isreal(zeroresp)) else zeroresp
12291242

12301243
def _isstatic(self):
12311244
"""True if and only if the system has no dynamics, that is,

control/xferfcn.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1070,12 +1070,21 @@ def dcgain(self, warn_infinite=False):
10701070
10711071
Returns
10721072
-------
1073-
gain : ndarray
1074-
The zero-frequency gain
1073+
gain : (outputs, inputs) ndarray or scalar
1074+
Array or scalar value for SISO systems, depending on
1075+
config.defaults['control.squeeze_frequency_response'].
1076+
The value of the array elements or the scalar is either the
1077+
zero-frequency (or DC) gain, or `inf`, if the frequency response
1078+
is singular.
1079+
1080+
For real valued systems, the empty imaginary part of the
1081+
complex zero-frequency response is discarded and a real array or
1082+
scalaris returned.
10751083
< 6623 /div>
10761084
"""
1077-
return self(0, warn_infinite=warn_infinite) if self.isctime() \
1085+
zeroresp = self(0, warn_infinite=warn_infinite) if self.isctime() \
10781086
else self(1, warn_infinite=warn_infinite)
1087+
return zeroresp.real if np.all(np.isreal(zeroresp)) else zeroresp
10791088

10801089
def _isstatic(self):
10811090
"""returns True if and only if all of the numerator and denominator

0 commit comments

Comments
 (0)
0