From bd74b9a8a51a34ce81c17df4dfe2e0ca7da07bd4 Mon Sep 17 00:00:00 2001 From: Fredrik Bagge Carlson Date: Mon, 4 Dec 2023 06:57:17 +0100 Subject: [PATCH] improve tests and docs for delay-system inversion --- .../src/types/DelayLtiSystem.jl | 15 +++++++++------ .../test/test_delayed_systems.jl | 7 ++++--- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/lib/ControlSystemsBase/src/types/DelayLtiSystem.jl b/lib/ControlSystemsBase/src/types/DelayLtiSystem.jl index b7bf43796..f178d8c00 100644 --- a/lib/ControlSystemsBase/src/types/DelayLtiSystem.jl +++ b/lib/ControlSystemsBase/src/types/DelayLtiSystem.jl @@ -94,13 +94,16 @@ function +(sys::DelayLtiSystem{T1,S}, n::T2) where {T1,T2<:Number,S} end +""" + /(G1, G2::DelayLtiSystem) + +Compute ``G_1 * G_2^{-1} where ``G_2`` is a DelayLtiSystem. +Throws a SingularException if ``G_2`` is not invertible. +""" function /(anything, sys::DelayLtiSystem) - if !all(iszero, sys.Tau) - ny,nu = size(sys) - ny == nu || error("The denominator system must be square") - return anything * feedback(I(nu), sys - I(nu)) - end - /(anything, sys.P.P) # If all delays are zero, invert the inner system + ny,nu = size(sys) + ny == nu || error("The denominator system must be square") + return anything * feedback(I(nu), sys - I(nu)) end for other_type in [:Number, :AbstractMatrix, :LTISystem] diff --git a/lib/ControlSystemsBase/test/test_delayed_systems.jl b/lib/ControlSystemsBase/test/test_delayed_systems.jl index 361ec4f57..a848b8ff4 100644 --- a/lib/ControlSystemsBase/test/test_delayed_systems.jl +++ b/lib/ControlSystemsBase/test/test_delayed_systems.jl @@ -186,9 +186,10 @@ w = 10 .^ (-2:0.1:2) @test propertynames(delay(1.0)) == (:P, :Tau, :nu, :ny) -@test_throws ErrorException 1/f2 -@test_throws ErrorException randn(2,2)/f2 -@test_throws ErrorException f2/f2 +@test_throws SingularException 1/f2 +@test_throws SingularException randn(2,2)/f2 +@test_throws SingularException f2/f2 +@test 1/(I(2)+f2) == feedback(I(2), f2) #FIXME: A lot more tests, including MIMO systems in particular