Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add additive identity element for statespace and TF #538

Merged
merged 2 commits into from
Jun 12, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/types/StateSpace.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions src/types/TransferFunction.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 9 additions & 0 deletions test/test_connections.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down