- Notifications
You must be signed in to change notification settings - Fork441
improved default time vector for time response functions that takes zeros into account.#454
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Merged
Uh oh!
There was an error while loading.Please reload this page.
Merged
Changes fromall commits
Commits
Show all changes
7 commits Select commitHold shift + click to select a range
9658e0f
beginnings of code starts with a docstring
sawyerbfullerafdc5e3
first commit that adds ilayn's default time for step code
bnavigatora6cac86
Update control/timeresp.py
sawyerbfuller65ee5ed
removed one more unicode symbol
sawyerbfuller3d25b8b
more unicode expulsion
sawyerbfuller23d90d6
curse you python 2. removed '@' sign
sawyerbfullerc588cdc
Update control/xferfcn.py
sawyerbfullerFile filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
4 changes: 4 additions & 0 deletionscontrol/statesp.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
14 changes: 10 additions & 4 deletionscontrol/tests/sisotool_test.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
65 changes: 41 additions & 24 deletionscontrol/tests/timeresp_test.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -29,6 +29,12 @@ def setUp(self): | ||
# Create some transfer functions | ||
self.siso_tf1 = TransferFunction([1], [1, 2, 1]) | ||
self.siso_tf2 = _convert_to_transfer_function(self.siso_ss1) | ||
# tests for pole cancellation | ||
self.pole_cancellation = TransferFunction([1.067e+05, 5.791e+04], | ||
[10.67, 1.067e+05, 5.791e+04]) | ||
self.no_pole_cancellation = TransferFunction([1.881e+06], | ||
[188.1, 1.881e+06]) | ||
# Create MIMO system, contains ``siso_ss1`` twice | ||
A = np.matrix("1. -2. 0. 0.;" | ||
@@ -167,6 +173,14 @@ def test_step_info(self): | ||
2.50, | ||
rtol=rtol) | ||
# confirm that pole-zero cancellation doesn't perturb results | ||
# https://github.com/python-control/python-control/issues/440 | ||
step_info_no_cancellation = step_info(self.no_pole_cancellation) | ||
step_info_cancellation = step_info(self.pole_cancellation) | ||
for key in step_info_no_cancellation: | ||
np.testing.assert_allclose(step_info_no_cancellation[key], | ||
step_info_cancellation[key], rtol=1e-4) | ||
def test_impulse_response(self): | ||
# Test SISO system | ||
sys = self.siso_ss1 | ||
@@ -348,33 +362,41 @@ def test_step_robustness(self): | ||
sys2 = TransferFunction(num, den2) | ||
# Compute step response from input 1 to output 1, 2 | ||
t1, y1 = step_response(sys1, input=0,T=2,T_num=100) | ||
t2, y2 = step_response(sys2, input=0,T=2,T_num=100) | ||
np.testing.assert_array_almost_equal(y1, y2) | ||
def test_auto_generated_time_vector(self): | ||
# confirm a TF with a pole at p simulates forratio/p seconds | ||
p = 0.5 | ||
ratio = 9.21034*p # taken from code | ||
ratio2 = 25*p | ||
np.testing.assert_array_almost_equal( | ||
_ideal_tfinal_and_dt(TransferFunction(1, [1, .5]))[0], | ||
(ratio/p)) | ||
np.testing.assert_array_almost_equal( | ||
_ideal_tfinal_and_dt(TransferFunction(1, [1, .5]).sample(.1))[0], | ||
(ratio2/p)) | ||
# confirm a TF with poles at 0 and p simulates forratio/p seconds | ||
np.testing.assert_array_almost_equal( | ||
_ideal_tfinal_and_dt(TransferFunction(1, [1, .5, 0]))[0], | ||
(ratio2/p)) | ||
# confirm a TF with a natural frequency of wn rad/s gets a | ||
# dt of 1/(ratio*wn) | ||
wn = 10 | ||
ratio_dt = 1/(0.025133 * ratio * wn) | ||
np.testing.assert_array_almost_equal( | ||
_ideal_tfinal_and_dt(TransferFunction(1, [1, 0, wn**2]))[1], | ||
1/(ratio_dt*ratio*wn)) | ||
wn = 100 | ||
np.testing.assert_array_almost_equal( | ||
_ideal_tfinal_and_dt(TransferFunction(1, [1, 0, wn**2]))[1], | ||
1/(ratio_dt*ratio*wn)) | ||
zeta = .1 | ||
np.testing.assert_array_almost_equal( | ||
_ideal_tfinal_and_dt(TransferFunction(1, [1, 2*zeta*wn, wn**2]))[1], | ||
1/(ratio_dt*ratio*wn)) | ||
# but a smapled one keeps its dt | ||
np.testing.assert_array_almost_equal( | ||
_ideal_tfinal_and_dt(TransferFunction(1, [1, 2*zeta*wn, wn**2]).sample(.1))[1], | ||
@@ -384,37 +406,32 @@ def test_auto_generated_time_vector(self): | ||
.1) | ||
np.testing.assert_array_almost_equal( | ||
_ideal_tfinal_and_dt(TransferFunction(1, [1, 2*zeta*wn, wn**2]))[1], | ||
1/(ratio_dt*ratio*wn)) | ||
# TF with fast oscillations simulates only 5000 time steps even with long tfinal | ||
self.assertEqual(5000, | ||
len(_default_time_vector(TransferFunction(1, [1, 0, wn**2]),tfinal=100))) | ||
sys = TransferFunction(1, [1, .5, 0]) | ||
sysdt = TransferFunction(1, [1, .5, 0], .1) | ||
# test impose number of time steps | ||
self.assertEqual(10, len(step_response(sys, T_num=10)[0])) | ||
# test that discrete ignores T_num | ||
self.assertNotEqual(15, len(step_response(sysdt, T_num=15)[0])) | ||
# test impose final time | ||
np.testing.assert_array_almost_equal( | ||
100, | ||
np.ceil(step_response(sys, 100)[0][-1])) | ||
np.testing.assert_array_almost_equal( | ||
100, | ||
np.ceil(step_response(sysdt, 100)[0][-1])) | ||
np.testing.assert_array_almost_equal( | ||
100, | ||
np.ceil(impulse_response(sys, 100)[0][-1])) | ||
np.testing.assert_array_almost_equal( | ||
100, | ||
np.ceil(initial_response(sys, 100)[0][-1])) | ||
sawyerbfuller marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
def test_time_vector(self): | ||
Oops, something went wrong.
Uh oh!
There was an error while loading.Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.