- Notifications
You must be signed in to change notification settings - Fork441
Improved speed of ctrb and obsv functions#941
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
8 commits Select commitHold shift + click to select a range
5692317
improved speed to construct observability matrix by reducing matrix e…
Jpickard195ab229
improved time to create controllability matrix, fix to obsv function …
Jpickard17feeb2c
fixed differentce between ctrb and obsv
Jpickard1bfc7e6b
Update control/statefbk.py
Jpickard144d57ac
Update control/statefbk.py
Jpickard1cb4f7d9
changed doc string
Jpickard149779aa
Merge branch 'main' of https://github.com/Jpickard1/python-control
Jpickard1f8ba0d9
test cases added for t < A.shape[0]
Jpickard1File 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
34 changes: 26 additions & 8 deletionscontrol/statefbk.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 |
---|---|---|
@@ -990,13 +990,15 @@ def _control_output(t, states, inputs, params): | ||
return ctrl, closed | ||
def ctrb(A, B, t=None): | ||
"""Controllabilty matrix. | ||
Parameters | ||
---------- | ||
A, B : array_like or string | ||
Dynamics and input matrix of the system | ||
t : None or integer | ||
maximum time horizon of the controllability matrix, max = A.shape[0] | ||
Returns | ||
------- | ||
@@ -1016,22 +1018,30 @@ def ctrb(A, B): | ||
amat = _ssmatrix(A) | ||
bmat = _ssmatrix(B) | ||
n = np.shape(amat)[0] | ||
m = np.shape(bmat)[1] | ||
if t is None or t > n: | ||
t = n | ||
# Construct the controllability matrix | ||
ctrb = np.zeros((n, t * m)) | ||
ctrb[:, :m] = bmat | ||
for k in range(1, t): | ||
ctrb[:, k * m:(k + 1) * m] = np.dot(amat, ctrb[:, (k - 1) * m:k * m]) | ||
Jpickard1 marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
return _ssmatrix(ctrb) | ||
def obsv(A, C, t=None): | ||
"""Observability matrix. | ||
Parameters | ||
---------- | ||
A, C : array_like or string | ||
Dynamics and output matrix of the system | ||
t : None or integer | ||
maximum time horizon of the controllability matrix, max = A.shape[0] | ||
Returns | ||
------- | ||
O : 2D array (or matrix) | ||
@@ -1050,10 +1060,18 @@ def obsv(A, C): | ||
amat = _ssmatrix(A) | ||
cmat = _ssmatrix(C) | ||
n = np.shape(amat)[0] | ||
p = np.shape(cmat)[0] | ||
if t is None or t > n: | ||
t = n | ||
# Construct the observability matrix | ||
obsv = np.zeros((t * p, n)) | ||
obsv[:p, :] = cmat | ||
for k in range(1, t): | ||
obsv[k * p:(k + 1) * p, :] = np.dot(obsv[(k - 1) * p:k * p, :], amat) | ||
Jpickard1 marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
return _ssmatrix(obsv) | ||
16 changes: 16 additions & 0 deletionscontrol/tests/statefbk_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
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.