Skip to content

Commit edd7e29

Browse files
committed
fix #941
1 parent 613f0d0 commit edd7e29

File tree

2 files changed

+18
-7
lines changed

2 files changed

+18
-7
lines changed

lib/ControlSystemsBase/src/analysis.jl

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -460,8 +460,8 @@ function sisomargin(sys::LTISystem, w::AbstractVector{<:Real}; full=false, allMa
460460
if !allMargins #Only output the smallest margins
461461
gm, idx = findmin([gm;Inf])
462462
wgm = [wgm;NaN][idx]
463-
fi = [fi;NaN][idx]
464463
pm, idx = findmin([abs.(pm);Inf])
464+
fi = [fi;NaN][idx]
465465
wpm = [wpm;NaN][idx]
466466
if full
467467
if !isnan(fi) #fi may be NaN, fullPhase is a scalar
@@ -509,19 +509,19 @@ function _findCrossings(w, n, res)
509509
tcross = Vector{eltype(w)}()
510510
for i in 1:(length(w)-1)
511511
if res[i] == 0
512-
wcross = [wcross; w[i]]
513-
tcross = [tcross; i]
512+
push!(wcross, w[i])
513+
push!(tcross, i)
514514
elseif n[i] != n[i+1]
515515
#Interpolate to approximate crossing
516516
t = res[i]/(res[i]-res[i+1])
517-
tcross = [tcross; i+t]
517+
push!(tcross, i+t)
518518
wt = w[i]+t*(w[i+1]-w[i])
519-
wcross = [wcross; wt]
519+
push!(wcross, wt)
520520
end
521521
end
522522
if res[end] == 0 #Special case if multiple points
523-
wcross = [wcross; w[end]]
524-
tcross = [tcross; length(w)]
523+
push!(wcross, w[end])
524+
push!(tcross, length(w))
525525
end
526526
wcross, tcross
527527
end

lib/ControlSystemsBase/test/test_analysis.jl

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,17 @@ dm = delaymargin(P)[]
229229

230230
@test delaymargin(tf(0.1, [1, 1])) == Inf
231231

232+
# https://github.com/JuliaControl/ControlSystems.jl/issues/941
233+
C = 0.6 + 30 * tf([1, 0], [1])
234+
G = tf([0.04, 0.0001, 1.1], [1, 0.03, 254.9])
235+
H = tf([0.25], [1, 1, 0.25])
236+
L = C * G * H * delay(1)
237+
m = margin(L)
238+
Lw = freqresp(L, m[1][])[]
239+
@test imag(Lw) 0 atol = 1e-6 # Test definition of gain margin
240+
@test inv(-real(Lw)) m[2][] atol = 1e-6 # Test definition of gain margin
241+
242+
232243
# RGA
233244
a = 10
234245
P = ss([0 a; -a 0], I(2), [1 a; -a 1], 0)

0 commit comments

Comments
 (0)