Skip to content

Commit 0a540ab

Browse files
committed
add balanced truncation on coprime factors
1 parent 3a75d7a commit 0a540ab

4 files changed

Lines changed: 43 additions & 24 deletions

File tree

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "RobustAndOptimalControl"
22
uuid = "21fd56a4-db03-40ee-82ee-a87907bee541"
33
authors = ["Fredrik Bagge Carlson", "Marcus Greiff"]
4-
version = "0.3.3"
4+
version = "0.3.4"
55

66
[deps]
77
ChainRulesCore = "d360d2e6-b24c-11e9-a2a3-2a2ae2dbcce4"

src/RobustAndOptimalControl.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ using ChainRulesCore
2424
export show_construction, vec2sys
2525
include("utils.jl")
2626

27-
export dss, hinfnorm2, h2norm, hankelnorm, nugap, νgap, baltrunc2, stab_unstab, baltrunc_unstab
27+
export dss, hinfnorm2, h2norm, hankelnorm, nugap, νgap, baltrunc2, stab_unstab, baltrunc_unstab, baltrunc_coprime
2828
include("descriptor.jl")
2929

3030
export ExtendedStateSpace, system_mapping, performance_mapping, noise_mapping, ssdata_e, partition, ss

src/descriptor.jl

Lines changed: 31 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -86,23 +86,37 @@ function baltrunc2(sys::LTISystem; residual=false, n=missing, kwargs...)
8686
ss(sysr), hs
8787
end
8888

89-
# function coprime_baltrunc(sys; residual=false, n=missing, kwargs...)
90-
# N,M = DescriptorSystems.glcf(dss(sys), mindeg=true, mininf=true, fast=false)
91-
# nu = size(N.B, 2)
92-
# # A,E,B,C,D = DescriptorSystems.dssdata(N)
93-
# # NM = DescriptorSystems.dss(A,E,[B M.B],C,[D M.D])
94-
# # Nr1, hs = DescriptorSystems.gbalmr(N; matchdc=residual, ord=n-size(M.A, 1), kwargs...)
95-
# NM = [N M]
96-
# sysr, hs = DescriptorSystems.gbalmr(NM; matchdc=residual, ord=n, kwargs...)
97-
98-
# A,E,B,C,D = DescriptorSystems.dssdata(sysr)
99-
100-
# Nr = DescriptorSystems.dss(A,E,B[:, 1:nu],C,D[:, 1:nu])
101-
# Mr = DescriptorSystems.dss(A,E,B[:, nu+1:end],C,D[:, nu+1:end])
102-
# sysr = Mr \ Nr
103-
# ss(sysr), hs
104-
# # Nr, Mr
105-
# end
89+
"""
90+
baltrunc_coprime(sys; residual = false, n = missing, factorization::F = DescriptorSystems.glcf, kwargs...)
91+
92+
Compute a balanced truncation of the left coprime factorization of `sys`.
93+
See [`baltrunc2`](@ref) for additional keyword-argument help.
94+
95+
# Arguments:
96+
- `factorization`: The function to perform the coprime factorization. A normalized factorization may be used by passing `RobustAndOptimalControl.DescriptorSystems.gnlcf`.
97+
- `kwargs`: Are passed to `DescriptorSystems.gbalmr`
98+
"""
99+
function baltrunc_coprime(sys; residual=false, n=missing, factorization::F = DescriptorSystems.glcf, kwargs...) where F
100+
N,M = factorization(dss(sys))
101+
nu = size(N.B, 2)
102+
A,E,B,C,D = DescriptorSystems.dssdata(N)
103+
NM = DescriptorSystems.dss(A,E,[B M.B],C,[D M.D])
104+
sysr, hs = DescriptorSystems.gbalmr(NM; matchdc=residual, ord=n, kwargs...)
105+
106+
A,E,B,C,D = DescriptorSystems.dssdata(DescriptorSystems.dss2ss(sysr)[1])
107+
108+
BN = B[:, 1:nu]
109+
DN = D[:, 1:nu]
110+
BM = B[:, nu+1:end]
111+
DM = D[:, nu+1:end]
112+
113+
Ar = A - BM * (DM \ C)
114+
Cr = (DM \ C)
115+
Br = BN - BM * (DM \ DN)
116+
Dr = (DM \ DN)
117+
118+
ss(Ar,Br,Cr,Dr,sys.timeevol), hs
119+
end
106120

107121

108122
"""

test/test_descriptor.jl

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,15 @@ end >= 94
2323

2424

2525
##
26-
# sys = ssrand(2,3,4, stable=false)
27-
# # N,M = coprime_baltrunc(sys, n=3)
28-
# sysr, _ = coprime_baltrunc(sys, n=3)
26+
sys = ssrand(2,3,40, stable=true)
27+
sysus = ssrand(2,3,2, stable=true)
28+
sysus.A .*= -1
29+
sys = sys + sysus
2930

30-
# @test sysr.nx == 3
31+
sysr, hs = baltrunc_coprime(sys, n=20, factorization = RobustAndOptimalControl.DescriptorSystems.glcf)
32+
33+
@test sysr.nx == 20
34+
@test linfnorm(sysr - sys)[1] < 3e-3
3135

3236
# bodeplot([sys, sysr])
3337

@@ -46,4 +50,5 @@ sys = sys + sysus
4650
sysr, hs = baltrunc_unstab(sys, n=20)
4751
@test sysr.nx == 20
4852
@test linfnorm(sysr - sys)[1] < 1e-3
49-
# bodeplot([sys, sysr])
53+
# bodeplot([sys, sysr])
54+

0 commit comments

Comments
 (0)