diff --git a/lib/ControlSystemsBase/src/analysis.jl b/lib/ControlSystemsBase/src/analysis.jl index da43b476a..022018e32 100644 --- a/lib/ControlSystemsBase/src/analysis.jl +++ b/lib/ControlSystemsBase/src/analysis.jl @@ -410,18 +410,19 @@ See also [`delaymargin`](@ref) and [`RobustAndOptimalControl.diskmargin`](https: function margin(sys::LTISystem, w::AbstractVector{<:Real}; full=false, allMargins=false) ny, nu = size(sys) + T = float(numeric_type(sys)) if allMargins - wgm = Array{Array{numeric_type(sys),1}}(undef, ny,nu) - gm = Array{Array{numeric_type(sys),1}}(undef, ny,nu) - wpm = Array{Array{numeric_type(sys),1}}(undef, ny,nu) - pm = Array{Array{numeric_type(sys),1}}(undef, ny,nu) - fullPhase = Array{Array{numeric_type(sys),1}}(undef, ny,nu) + wgm = Array{Array{T,1}}(undef, ny,nu) + gm = Array{Array{T,1}}(undef, ny,nu) + wpm = Array{Array{T,1}}(undef, ny,nu) + pm = Array{Array{T,1}}(undef, ny,nu) + fullPhase = Array{Array{T,1}}(undef, ny,nu) else - wgm = Array{numeric_type(sys),2}(undef, ny, nu) - gm = Array{numeric_type(sys),2}(undef, ny, nu) - wpm = Array{numeric_type(sys),2}(undef, ny, nu) - pm = Array{numeric_type(sys),2}(undef, ny, nu) - fullPhase = Array{numeric_type(sys),2}(undef, ny, nu) + wgm = Array{T,2}(undef, ny, nu) + gm = Array{T,2}(undef, ny, nu) + wpm = Array{T,2}(undef, ny, nu) + pm = Array{T,2}(undef, ny, nu) + fullPhase = Array{T,2}(undef, ny, nu) end for j=1:nu for i=1:ny diff --git a/lib/ControlSystemsBase/src/freqresp.jl b/lib/ControlSystemsBase/src/freqresp.jl index ce8148e26..ffb0ad334 100644 --- a/lib/ControlSystemsBase/src/freqresp.jl +++ b/lib/ControlSystemsBase/src/freqresp.jl @@ -382,7 +382,11 @@ function _default_freq_vector(systems::Vector{<:LTISystem}, plot) w2 = maximum(maximum, bounds) nw = round(Int, max(min_pt_total, min_pt_per_dec*(w2 - w1))) - return exp10.(range(w1, stop=w2, length=nw)) + w = exp10.(range(w1, stop=w2, length=nw)) + if length(systems) == 1 && isdiscrete(systems[1]) + w[end] = π/systems[1].Ts # To account for numerical rounding problems from exp(log()) + end + w end _default_freq_vector(sys::LTISystem, plot) = _default_freq_vector( [sys], plot) diff --git a/lib/ControlSystemsBase/test/test_freqresp.jl b/lib/ControlSystemsBase/test/test_freqresp.jl index 89a385e75..358191f22 100644 --- a/lib/ControlSystemsBase/test/test_freqresp.jl +++ b/lib/ControlSystemsBase/test/test_freqresp.jl @@ -173,6 +173,9 @@ mag, mag, ws2 = bode(sys2) @test maximum(ws2) >= 5max(p,z) @test minimum(ws2) <= 0.2min(p,z) @test length(ws2) > 100 + +@test margin(tf(1, [1, -1], 0.01)).gm == [2;;] + end @@ -204,4 +207,5 @@ end # f2 = plot(sizes, last.(times1), scale=:log10, lab="Allocations freqresp", m=:o) # plot!(sizes, last.(times2), scale=:log10, lab="Allocations freqresp_large", xlabel="Model order", m=:o) -# plot(f1, f2) \ No newline at end of file +# plot(f1, f2) +