Skip to content

Commit

Permalink
fix for discrete systems in baltrunc
Browse files Browse the repository at this point in the history
  • Loading branch information
baggepinnen committed Jan 5, 2022
1 parent 5f9af30 commit d26f619
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
11 changes: 6 additions & 5 deletions src/matrix_comps.jl
Original file line number Diff line number Diff line change
Expand Up @@ -540,16 +540,17 @@ function baltrunc(sys::ST; atol = sqrt(eps()), rtol = 1e-3, n = nothing, residua
A11 = A[i1, i1]
A12 = A[i1, i2]
A21 = A[i2, i1]
A22 = A[i2, i2]
A22 = -A[i2, i2]
isdiscrete(sys) && (A22 += I)
B1 = B[i1, :]
B2 = B[i2, :]
C1 = C[:, i1]
C2 = C[:, i2]
A2221 = A22\A21
A = A11 - A12*(A2221)
B = B1 - (A12/A22)*B2
C = C1 - C2*A2221
D = D - (C2/A22)*B2
A = A11 + A12*(A2221)
B = B1 + (A12/A22)*B2
C = C1 + C2*A2221
D = D + (C2/A22)*B2
else
A = sysbal.A[i1,i1]
B = sysbal.B[i1,:]
Expand Down
4 changes: 4 additions & 0 deletions test/test_simplification.jl
Original file line number Diff line number Diff line change
Expand Up @@ -68,5 +68,9 @@ y2,x2 = step(sysmin,t)[[1,3]]
@test sysr.nx == 3
@test dcgain(sysr)[] dcgain(sys)[] rtol=1e-10

sys = c2d(sys, 0.01)
sysr,Σ = baltrunc(sys, n=3, residual=true)
@test sysr.nx == 3
@test dcgain(sysr)[] dcgain(sys)[] rtol=1e-10

end

0 comments on commit d26f619

Please sign in to comment.