Skip to content

Commit 4f4667c

Browse files
committed
prefactor matrix
1 parent 6e6e89a commit 4f4667c

2 files changed

Lines changed: 40 additions & 36 deletions

File tree

src/descriptor.jl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -108,12 +108,12 @@ function baltrunc_coprime(sys; residual=false, n=missing, factorization::F = Des
108108
BN = B[:, 1:nu]
109109
DN = D[:, 1:nu]
110110
BM = B[:, nu+1:end]
111-
DM = D[:, nu+1:end]
111+
DMi = pinv(D[:, nu+1:end])
112112

113-
Ar = A - BM * (DM \ C)
114-
Cr = (DM \ C)
115-
Br = BN - BM * (DM \ DN)
116-
Dr = (DM \ DN)
113+
Ar = A - BM * (DMi * C)
114+
Cr = (DMi * C)
115+
Br = BN - BM * (DMi * DN)
116+
Dr = (DMi * DN)
117117

118118
ss(Ar,Br,Cr,Dr,sys.timeevol), hs
119119
end

test/test_descriptor.jl

Lines changed: 35 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -23,35 +23,39 @@ end >= 94
2323

2424

2525
##
26-
sys = ssrand(2,3,40, stable=true)
27-
sysus = ssrand(2,3,2, stable=true)
28-
sysus.A .*= -1
29-
sys = sys + sysus
30-
31-
sysr, hs = RobustAndOptimalControl.baltrunc_coprime(sys, n=20, factorization = RobustAndOptimalControl.DescriptorSystems.glcf)
32-
33-
@test sysr.nx <= 20
34-
@test linfnorm(sysr - sys)[1] < 3e-3
35-
36-
e = poles(sysr)
37-
@test count(e->real(e)>0, e) == 2 # test that the two unstable poles were preserved
38-
39-
# bodeplot([sys, sysr])
40-
41-
## stab_unstab
42-
sys = ssrand(2,3,40, stable=false)
43-
stab, unstab = stab_unstab(sys)
44-
@test all(real(poles(stab)) .< 0)
45-
@test all(real(poles(unstab)) .>= 0)
46-
@test linfnorm(stab + unstab - sys)[1] < 1e-8
47-
48-
## baltrunc_unstab
49-
sys = ssrand(2,3,40, stable=true)
50-
sysus = ssrand(2,3,2, stable=true)
51-
sysus.A .*= -1
52-
sys = sys + sysus
53-
sysr, hs = baltrunc_unstab(sys, n=20)
54-
@test sysr.nx <= 20
55-
@test linfnorm(sysr - sys)[1] < 1e-3
56-
# bodeplot([sys, sysr])
26+
@testset "unstable baltrunc" begin
27+
@info "Testing unstable baltrunc"
28+
for proper = [true, false]
29+
sys = ssrand(2,3,40; stable=true, proper)
30+
sysus = ssrand(2,3,2; stable=true, proper)
31+
sysus.A .*= -1
32+
sys = sys + sysus
33+
34+
sysr, hs = RobustAndOptimalControl.baltrunc_coprime(sys, n=20, factorization = RobustAndOptimalControl.DescriptorSystems.glcf)
35+
36+
@test sysr.nx <= 20
37+
@test linfnorm(sysr - sys)[1] < 9e-3
38+
39+
e = poles(sysr)
40+
@test count(e->real(e)>0, e) == 2 # test that the two unstable poles were preserved
41+
# bodeplot([sys, sysr])
42+
end
5743

44+
## stab_unstab
45+
sys = ssrand(2,3,40, stable=false)
46+
stab, unstab = stab_unstab(sys)
47+
@test all(real(poles(stab)) .< 0)
48+
@test all(real(poles(unstab)) .>= 0)
49+
@test linfnorm(stab + unstab - sys)[1] < 1e-8
50+
51+
## baltrunc_unstab
52+
sys = ssrand(2,3,40, stable=true)
53+
sysus = ssrand(2,3,2, stable=true)
54+
sysus.A .*= -1
55+
sys = sys + sysus
56+
sysr, hs = baltrunc_unstab(sys, n=20)
57+
@test sysr.nx <= 20
58+
@test linfnorm(sysr - sys)[1] < 1e-3
59+
# bodeplot([sys, sysr])
60+
61+
end

0 commit comments

Comments
 (0)