From 76e72c61460e42913dcc473f1c3e6b4900b908f7 Mon Sep 17 00:00:00 2001 From: Fredrik Bagge Carlson Date: Wed, 15 Jan 2025 08:30:46 +0100 Subject: [PATCH 1/2] add `bodemag_nohess!` --- lib/ControlSystemsBase/src/analysis.jl | 2 ++ lib/ControlSystemsBase/src/freqresp.jl | 6 ++++++ lib/ControlSystemsBase/src/utilities.jl | 2 +- lib/ControlSystemsBase/test/test_freqresp.jl | 1 + 4 files changed, 10 insertions(+), 1 deletion(-) diff --git a/lib/ControlSystemsBase/src/analysis.jl b/lib/ControlSystemsBase/src/analysis.jl index f785d74cd..388df85a3 100644 --- a/lib/ControlSystemsBase/src/analysis.jl +++ b/lib/ControlSystemsBase/src/analysis.jl @@ -56,6 +56,8 @@ end count_integrators(P) Count the number of poles in the origin by finding the maximum value of `n` for which the number of poles within a circle of radius `(n+1)*eps(numeric_type(sys))^(1/n)` arount the origin (1 in discrete time) equals `n`. + +See also [`integrator_excess`](@ref). """ function count_integrators(P::LTISystem) p = poles(P) diff --git a/lib/ControlSystemsBase/src/freqresp.jl b/lib/ControlSystemsBase/src/freqresp.jl index 0b722d3ad..6613b8599 100644 --- a/lib/ControlSystemsBase/src/freqresp.jl +++ b/lib/ControlSystemsBase/src/freqresp.jl @@ -339,6 +339,12 @@ function bodemag!(ws::BodemagWorkspace, sys::LTISystem, w::AbstractVector) ws.mag end +function bodemag_nohess!(ws::BodemagWorkspace, sys::LTISystem, w::AbstractVector) + freqresp_nohess!(ws.R, sys, w) + @. ws.mag = abs(ws.R) + ws.mag +end + """ re, im, w = nyquist(sys[, w]) diff --git a/lib/ControlSystemsBase/src/utilities.jl b/lib/ControlSystemsBase/src/utilities.jl index b9166a344..c04c43387 100644 --- a/lib/ControlSystemsBase/src/utilities.jl +++ b/lib/ControlSystemsBase/src/utilities.jl @@ -34,7 +34,7 @@ to_abstract_matrix(A::AbstractVector) = reshape(A, length(A), 1) to_abstract_matrix(A::Number) = fill(A, 1, 1) # Do no sorting of eigenvalues -eigvalsnosort(args...; kwargs...) = eigvals(args...; sortby=nothing, kwargs...) +eigvalsnosort(A, args...; kwargs...)::Vector{Complex{real(float(eltype(A)))}} = eigvals(A, args...; sortby=nothing, kwargs...) eigvalsnosort(A::StaticArraysCore.StaticMatrix; kwargs...) = eigvalsnosort(Matrix(A); kwargs...) roots(args...; kwargs...) = Polynomials.roots(args...; sortby=nothing, kwargs...) diff --git a/lib/ControlSystemsBase/test/test_freqresp.jl b/lib/ControlSystemsBase/test/test_freqresp.jl index 358191f22..dda4a8402 100644 --- a/lib/ControlSystemsBase/test/test_freqresp.jl +++ b/lib/ControlSystemsBase/test/test_freqresp.jl @@ -120,6 +120,7 @@ Base.isapprox(t1::Tuple, t2::Tuple) = t1[1] ≈ t2[1] && t1[2] ≈ t2[2] @test bode(sys, ws)[1:2] ≈ (abs.(resp), rad2deg.(angle.(resp))) workspace = BodemagWorkspace(sys, ws) @test bode(sys, ws)[1] == bodemag!(workspace, sys, ws) +@test bode(sys, ws)[1] ≈ ControlSystemsBase.bodemag_nohess!(workspace, ss(sys), ws) @test nyquist(sys, ws)[1:2] ≈ (real(resp), imag(resp)) sigs = Array{Float64}(undef, 2, 50) for i in eachindex(ws) From a54405e2433e768b494fb93c0327bc1eb1a48c18 Mon Sep 17 00:00:00 2001 From: Fredrik Bagge Carlson Date: Wed, 15 Jan 2025 12:36:17 +0100 Subject: [PATCH 2/2] sort by real --- lib/ControlSystemsBase/test/test_matrix_comps.jl | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/ControlSystemsBase/test/test_matrix_comps.jl b/lib/ControlSystemsBase/test/test_matrix_comps.jl index 257f2c517..174b40aa4 100644 --- a/lib/ControlSystemsBase/test/test_matrix_comps.jl +++ b/lib/ControlSystemsBase/test/test_matrix_comps.jl @@ -1,3 +1,4 @@ +using Test, LinearAlgebra @testset "test_matrix_comps" begin A = [-0.21 0.2; 0.2 -0.21] B = 0.01*[1 0; 0 1] @@ -8,7 +9,7 @@ sysr, G = balreal(sys) @test gram(sysr, :c) ≈ diagm(G) @test gram(sysr, :o) ≈ diagm(G) -@test sort(poles(sysr)) ≈ sort(poles(sys)) +@test sort(poles(sysr), by=real) ≈ sort(poles(sys), by=real) sysb,T = ControlSystemsBase.balance_statespace(sys) @test similarity_transform(sysb, T) ≈ sys