diff --git a/src/types/StateSpace.jl b/src/types/StateSpace.jl index d1759fed8..937bbeaed 100644 --- a/src/types/StateSpace.jl +++ b/src/types/StateSpace.jl @@ -217,6 +217,8 @@ function isapprox(sys1::ST1, sys2::ST2; kwargs...) where {ST1<:AbstractStateSpac end ## ADDITION ## +Base.zero(sys::AbstractStateSpace) = ss(zero(sys.D), sys.timeevol) + function +(s1::StateSpace{TE,T}, s2::StateSpace{TE,T}) where {TE,T} #Ensure systems have same dimensions if size(s1) != size(s2) diff --git a/src/types/TransferFunction.jl b/src/types/TransferFunction.jl index 6695ba9bd..d02acb591 100644 --- a/src/types/TransferFunction.jl +++ b/src/types/TransferFunction.jl @@ -33,6 +33,8 @@ ninputs(G::TransferFunction) = size(G.matrix, 2) Base.ndims(::TransferFunction) = 2 Base.size(G::TransferFunction) = size(G.matrix) Base.eltype(::Type{S}) where {S<:TransferFunction} = S +Base.zero(G::TransferFunction{TE,S}) where {TE,S} = tf(zeros(numeric_type(S), size(G)), G.timeevol) # can not create a zero of a discrete system from the type alone, the sampletime is not stored. + function Base.getindex(G::TransferFunction{TE,S}, inds...) where {TE,S<:SisoTf} if size(inds, 1) != 2 diff --git a/test/test_connections.jl b/test/test_connections.jl index 9dcfccf37..fbc38dbb7 100644 --- a/test/test_connections.jl +++ b/test/test_connections.jl @@ -83,6 +83,15 @@ s = tf("s") vecarray(2, 1, [1,13,55,75], [1,13,55,75])); @test parallel(Ctf_111, Ctf_211) == tf([2,17,44,45], [1,13,55,75]) +# Test that the additive identity element for LTI system is known +@test zero(C_111) isa typeof(C_111) +@test zero(Ctf_111) isa typeof(Ctf_111) +@test zero(ss(randn(2,3))) == ss(zeros(2,3)) +@test zero(tf(randn(2,3))) == tf(zeros(2,3)) + + + + # Combination tf and ss @test [C_111 Ctf_221] == [C_111 ss(Ctf_221)] @test [C_111; Ctf_212] == [C_111; ss(Ctf_212)]