-
Notifications
You must be signed in to change notification settings - Fork 85
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
Update prescale
function
#465
Closed
Closed
Changes from 6 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
bb244e9
feat: add `prescale(sys::StateSpace)` and corresponding test.
tfoliva 880fdcb
fix: `isdiagonal` -> `isdiag`.
tfoliva 4139f2d
feat: export `prescale` and `luenberger`.
tfoliva a590809
refactor: function
tfoliva be249d0
refactor: remove `canon` function; work still in progress.
tfoliva e38a79a
Merge branch 'master' into master
tfoliva c0a1088
fix: prescale tests
tfoliva ba1cc92
Merge branch 'canon'
tfoliva 8d31f6a
Merge branch 'master' of github.com:tfoliva/ControlSystems.jl
tfoliva cac2f60
refactor: slicing indices in prescale
tfoliva 69f58c3
Refactor slicing indices in prescale
tfoliva File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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 |
---|---|---|
|
@@ -568,7 +568,7 @@ end | |
syst = similarity_transform(sys, T) | ||
Perform a similarity transform `T : Tx̃ = x` on `sys` such that | ||
``` | ||
à = T⁻¹AT | ||
à = T⁻¹AT | ||
B̃ = T⁻¹ B | ||
C̃ = CT | ||
D̃ = D | ||
|
@@ -585,24 +585,33 @@ end | |
|
||
""" | ||
syst, S = prescale(sys) | ||
Perform a eigendecomposition on system state-transition matrix `sys.A`. | ||
|
||
Balances the metasystem matrix | ||
``` | ||
à = S⁻¹AS | ||
B̃ = S⁻¹ B | ||
C̃ = CS | ||
D̃ = D | ||
M = [A B; | ||
C 0] | ||
``` | ||
Such that `Ã` is diagonal. | ||
such that their column and row norms are closer. | ||
This results in a system with overall better numerical conditioning. | ||
|
||
Returns a new scaled state-space object and the associated transformation | ||
matrix. | ||
""" | ||
function prescale(sys::StateSpace) | ||
d, S = eigen(sys.A) | ||
A = Diagonal(d) | ||
B = S\sys.B | ||
C = sys.C*S | ||
normalized_sys = iscontinuous(sys) ? ss(A, B, C, sys.D) : ss(A, B, C, sys.D, sys.Ts) | ||
return normalized_sys, S | ||
function prescale(sys::StateSpace) where ST <: AbstractStateSpace | ||
n, m = size(sys.B) | ||
p = size(sys.C, 1) | ||
|
||
# create an augmented system to balance the whole system at once | ||
metasys = [sys.A sys.B zeros(n, n-m); sys.C zeros(p, n)] | ||
S, P, B = balance(metasys) | ||
T = S*P # permutation matrix to be returned later | ||
|
||
# reconstruct A, B and C by taking slices of the balanced metasystem | ||
bal_metasys = P\B*P # undo permutation | ||
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. Would it be possible to use |
||
A = bal_metasys[1:n, 1:n] | ||
B = bal_metasys[1:n, n+1:n+m] | ||
C = bal_metasys[n+1:end, 1:n] | ||
return ST(A, B, C, sys.D, sys.timeevol), T | ||
end | ||
|
||
""" | ||
|
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.
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.