Skip to content
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
wants to merge 11 commits into from
39 changes: 23 additions & 16 deletions src/matrix_comps.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -585,24 +585,31 @@ 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.
Returns a new scaled state-space object and the associated transformation
matrix.
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.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you have any reference to where this method is discussed?

"""
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::ST) 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; sys.C zeros(p, m)]
Comment on lines +603 to +604
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are using two terms here, both augmented and meta system. I seem to remember that it is instead typically called a packed representation? I think that is the term used in the Essentials of Robust Control by Zhou & Doyle,

I think it should be okay to just call the packed system representation M as you do in the tests.

S, P, B = balance(metasys)

# reconstruct A, B and C by taking slices of the balanced metasystem
bal_metasys = P\B*P # undo permutation
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be possible to use perm=false to avoid having to undo the permutation?

A = bal_metasys[1:n, 1:n]
B = bal_metasys[1:n, n+1:end]
C = bal_metasys[n+1:end, 1:n]
return ST(A, B, C, sys.D, sys.timeevol)
end

"""
Expand Down
12 changes: 7 additions & 5 deletions test/test_matrix_comps.jl
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,13 @@ syst = similarity_transform(sys, Tr)
@test sys.B ≈ Tr*syst.B
@test sys.C*Tr ≈ syst.C

nsys, T = prescale(sys)
@test isdiag(nsys.A)
@test T*nsys.A ≈ sys.A*T
@test T*nsys.B ≈ sys.B
@test nsys.C ≈ sys.C*T
nsys = prescale(sys)
@test pole(nsys) ≈ pole(sys)
n, m = size(sys.B)
p = size(sys.C, 1)
M = [nsys.A nsys.B; nsys.C zeros(p, m)]
M2 = [sys.A sys.B; sys.C zeros(p, m)]
@test cond(M) <= cond(M2)
Comment on lines +73 to +79
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be reasonable with quite a few more tests. For example to see that the system dynamics isn't changed by the prescaling. E.g. by comparing the frequency response of a MIMO systems before and after.


sys = ss([1 0.1; 0 1], ones(2), [1. 0], 0)
sysi = ControlSystems.innovation_form(sys, I, I)
Expand Down