-
Notifications
You must be signed in to change notification settings - Fork 438
discard zero imaginary part for sys.dcgain() #579
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
|
@@ -433,9 +433,9 @@ def test_dcgain_consistency(): | |||||||
np.testing.assert_equal( | ||||||||
sys_ss(0j, warn_infinite=False), complex(np.inf, np.nan)) | ||||||||
np.testing.assert_equal( | ||||||||
sys_tf.dcgain(warn_infinite=False), complex(np.inf, np.nan)) | ||||||||
sys_tf.dcgain(), np.inf) | ||||||||
np.testing.assert_equal( | ||||||||
sys_ss.dcgain(warn_infinite=False), complex(np.inf, np.nan)) | ||||||||
sys_ss.dcgain(), np.inf) | ||||||||
|
||||||||
# Set up transfer function with pole, zero at the origin | ||||||||
sys_tf = ctrl.tf([1, 0], [1, 0]) | ||||||||
|
@@ -448,7 +448,7 @@ def test_dcgain_consistency(): | |||||||
np.testing.assert_equal( | ||||||||
sys_tf(0j, warn_infinite=False), complex(np.nan, np.nan)) | ||||||||
np.testing.assert_equal( | ||||||||
sys_tf.dcgain(warn_infinite=False), complex(np.nan, np.nan)) | ||||||||
sys_tf.dcgain(), np.nan) | ||||||||
|
||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Consider adding a test to show that dcgain() on a system with negative gain at zero frequency returns a negative number. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Already exists: python-control/control/tests/freqresp_test.py Lines 505 to 507 in 8c9e807
|
||||||||
# Set up state space version | ||||||||
sys_ss = ctrl.tf2ss(ctrl.tf([1, 0], [1, 1])) * \ | ||||||||
|
@@ -462,15 +462,15 @@ def test_dcgain_consistency(): | |||||||
np.testing.assert_equal( | ||||||||
sys_ss(0j, warn_infinite=False), complex(np.nan, np.nan)) | ||||||||
np.testing.assert_equal( | ||||||||
sys_ss.dcgain(warn_infinite=False), complex(np.nan, np.nan)) | ||||||||
sys_ss.dcgain(), np.nan) | ||||||||
elif 0 in sys_ss.pole(): | ||||||||
# Pole at the origin, but zero elsewhere => should get (inf + nanj) | ||||||||
np.testing.assert_equal( | ||||||||
sys_ss(0, warn_infinite=False), complex(np.inf, np.nan)) | ||||||||
np.testing.assert_equal( | ||||||||
sys_ss(0j, warn_infinite=False), complex(np.inf, np.nan)) | ||||||||
np.testing.assert_equal( | ||||||||
sys_ss.dcgain(warn_infinite=False), complex(np.inf, np.nan)) | ||||||||
sys_ss.dcgain(), np.inf) | ||||||||
else: | ||||||||
# Near pole/zero cancellation => nothing sensible to check | ||||||||
pass | ||||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1070,12 +1070,19 @@ def dcgain(self, warn_infinite=False): | |
|
||
Returns | ||
------- | ||
gain : ndarray | ||
The zero-frequency gain | ||
gain : (outputs, inputs) ndarray or scalar | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. gain : (noutputs, ninputs) ndarray or scalar |
||
Array or scalar value for SISO systems, depending on | ||
config.defaults['control.squeeze_frequency_response']. | ||
The value of the array elements or the scalar is either the | ||
zero-frequency (or DC) gain, or `inf`, if the frequency response | ||
is singular. | ||
|
||
For real valued systems, the empty imaginary part of the | ||
complex zero-frequency response is discarded and a real array or | ||
scalar is returned. | ||
|
||
""" | ||
return self(0, warn_infinite=warn_infinite) if self.isctime() \ | ||
else self(1, warn_infinite=warn_infinite) | ||
return self._dcgain(warn_infinite) | ||
|
||
def _isstatic(self): | ||
"""returns True if and only if all of the numerator and denominator | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
gain : (noutputs, ninputs) ndarray or scalar