Skip to content

Commit 2a51c27

Browse files
committed
add method for computing the determinant of a system
1 parent 6b51f75 commit 2a51c27

File tree

3 files changed

+20
-1
lines changed

3 files changed

+20
-1
lines changed

lib/ControlSystemsBase/src/matrix_comps.jl

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1019,4 +1019,13 @@ end
10191019

10201020
function observer_filter(sys::AbstractStateSpace{Continuous}, K::AbstractMatrix; kwargs...)
10211021
observer_predictor(sys, K; kwargs...)
1022-
end
1022+
end
1023+
1024+
function LinearAlgebra.det(sys::LTISystem)
1025+
sys = deepcopy(sys)
1026+
arrayofsys = getindex.(Ref(sys), 1:sys.ny, (1:sys.nu)')
1027+
if sys isa AbstractStateSpace
1028+
@. arrayofsys = sminreal(arrayofsys)
1029+
end
1030+
LinearAlgebra.det_bareiss!(arrayofsys)
1031+
end

lib/ControlSystemsBase/src/types/StateSpace.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,10 @@ Base.zero(sys::AbstractStateSpace) = basetype(sys)(zero(sys.D), sys.timeevol)
265265
Base.zero(::Type{StateSpace{Continuous, F}}) where {F} = ss([zero(F)], Continuous())
266266
Base.zero(::Type{StateSpace{D, F}}) where {D<:Discrete, F} = ss([zero(F)], undef_sampletime(D))
267267

268+
# one is a multiplicative identity, which can be set to the one of the element type. This is different from oneunit which should be of the same type.
269+
Base.one(::Type{StateSpace{TE, T}}) where {TE, T} = Base.one(T)
270+
271+
268272
function +(s1::ST, s2::ST) where {ST <: AbstractStateSpace}
269273
#Ensure systems have same dimensions
270274
if size(s1) != size(s2)

lib/ControlSystemsBase/test/test_matrix_comps.jl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,12 @@ sysr, G = balreal(sys)
1111
@test gram(sysr, :o) diagm(G)
1212
@test sort(poles(sysr), by=real) sort(poles(sys), by=real)
1313

14+
@testset "det" begin
15+
detsys = det(sys)
16+
w = 0.1
17+
@test freqresp(detsys, w)[1] det(freqresp(sys, w))
18+
end
19+
1420
sysb,T = ControlSystemsBase.balance_statespace(sys)
1521
@test similarity_transform(sysb, T) sys
1622
Ab,Bb,Cb,T = ControlSystemsBase.balance_statespace(A,B,C)

0 commit comments

Comments
 (0)