Skip to content

Commit 85ca1ba

Browse files
committed
Tests for pade approximation.
1 parent 07dcdd4 commit 85ca1ba

File tree

2 files changed

+38
-1
lines changed

2 files changed

+38
-1
lines changed

src/types/DelayLtiSystem.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,9 @@ function Base.getindex(sys::DelayLtiSystem, i::AbstractArray, j::AbstractArray)
145145
end
146146

147147
function Base.show(io::IO, sys::DelayLtiSystem)
148+
println(io, typeof(sys))
149+
150+
print(io, "\nP: ")
148151
show(io, sys.P.P)
149152

150153
println(io, "\n\nDelays: $(sys.Tau)")

test/test_delayed_systems.jl

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ using DelayDiffEq
88

99
@test typeof(promote(delay(0.2), ss(1.0 + im))[1]) == DelayLtiSystem{Complex{Float64}, Float64}
1010

11-
@test sprint(show, ss(1,1,1,1)*delay(1.0)) == "StateSpace{Float64,Array{Float64,2}}\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"
11+
@test sprint(show, ss(1,1,1,1)*delay(1.0)) == "DelayLtiSystem{Float64,Float64}\n\nP: StateSpace{Float64,Array{Float64,2}}\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"
1212

1313

1414
# Extremely baseic tests
@@ -201,4 +201,38 @@ y_impulse, t, _ = impulse(sys_known, 3, alg=MethodOfSteps(Tsit5()))
201201
@test y_impulse dy_expected.(t, K) rtol=1e-2 # Two orders of magnitude better with BS3 in this case, which is default for impulse
202202
@test maximum(abs, y_impulse - dy_expected.(t, K)) < 1e-2
203203

204+
205+
206+
## Test of basic pade functionality
207+
208+
Ω = [0, 0.5, 1, 2, 5]
209+
@test freqresp(pade(1, 1), Ω) == freqresp(tf([-1/2, 1], [1/2, 1]), Ω)
210+
@test freqresp(pade(1, 2), Ω) freqresp(tf([1/12, -1/2, 1], [1/12, 1/2, 1]), Ω)
211+
212+
for (n, tol)=enumerate([0.05; 1e-3; 1e-5; 1e-7; 1e-11; 1e-14*ones(5)])
213+
G = pade(0.8, n)
214+
215+
@test isstable(G)
216+
@test evalfr(G, 0)[1] 1
217+
@test abs(evalfr(G, 2im)[1]) 1
218+
@test evalfr(G, 1im)[1] exp(-0.8im) atol=tol
219+
end
220+
221+
222+
## Test pade applied to DelayLtiSystem
223+
224+
@test freqresp(pade(delay(0.5), 2), Ω) freqresp(pade(0.5, 2), Ω)
225+
226+
P = delay(1.0) * DemoSystems.lag(T=1)
227+
@test freqresp(pade(feedback(1,P), 2), Ω) == freqresp(feedback(1, pade(P,2)), Ω)
228+
229+
230+
Ω = [0, 0.1, 0.2]
231+
P_wb = DemoSystems.woodberry()
232+
233+
@test freqresp(pade(P_wb, 2), Ω) freqresp(P_wb, Ω) atol=0.02
234+
@test freqresp(pade(P_wb, 3), Ω) freqresp(P_wb, Ω) atol=5e-4
235+
236+
@test freqresp(pade(feedback(eye_(2), P_wb), 3), Ω) freqresp(feedback(eye_(2), P_wb), Ω) atol=1e-4
237+
204238
end

0 commit comments

Comments
 (0)