Skip to content

Commit

Permalink
bugfix: avoid creating continuous system with Ts=0.0 (#496)
Browse files Browse the repository at this point in the history
  • Loading branch information
olof3 authored May 13, 2021
1 parent d48190d commit 6e71421
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/types/DelayLtiSystem.jl
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ function +(sys::DelayLtiSystem{T}, n::T) where {T<:Number}
new_D = copy(ssold.D)
new_D[1:ny, 1:nu] .+= n

pnew = PartionedStateSpace(StateSpace(ssold.A, ssold.B, ssold.C, new_D, 0.0), ny, nu)
pnew = PartionedStateSpace(StateSpace(ssold.A, ssold.B, ssold.C, new_D, Continuous()), ny, nu)
DelayLtiSystem(pnew, sys.Tau)
end

Expand Down
7 changes: 6 additions & 1 deletion test/test_delayed_systems.jl
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,17 @@ else
@test sprint(show, ss(1,1,1,1)*delay(1.0)) == "DelayLtiSystem{Float64,Float64}\n\nP: StateSpace{Continuous,Float64}\nA = \n 1.0\nB = \n 0.0 1.0\nC = \n 1.0\n 0.0\nD = \n 0.0 1.0\n 1.0 0.0\n\nContinuous-time state-space model\n\nDelays: [1.0]\n"
end

# Extremely baseic tests
# Extremely basic tests
@test freqresp(delay(1), ω) reshape(exp.(-im*ω), length(ω), 1, 1) rtol=1e-15
@test freqresp(delay(2.5), ω)[:] exp.(-2.5im*ω) rtol=1e-15
@test freqresp(3.5*delay(2.5), ω)[:] 3.5*exp.(-2.5im*ω) rtol=1e-15
@test freqresp(delay(2.5)*1.5, ω)[:] exp.(-2.5im*ω)*1.5 rtol=1e-15

# Addition of constant
@test evalfr(1 + delay(1.0), 0)[] 2
@test evalfr(1 - delay(1.0), 0)[] 0
@test evalfr([2 -delay(1.0)], 0) [2 -1]

# Stritcly proper system
P1 = DelayLtiSystem(ss(-1.0, 1, 1, 0))
P1_fr = 1 ./ (im*ω .+ 1)
Expand Down

0 comments on commit 6e71421

Please sign in to comment.