ControlSystems.jl icon indicating copy to clipboard operation
ControlSystems.jl copied to clipboard

Building a vector of both continuous and discrete

Open albheim opened this issue 3 years ago • 2 comments

Noticed that plotting by sending in a vector of plots does not seem to work when there is a mix of discrete and continuous, but when sending them in one by one it works nicely. Have not looked into it at all, just felt it should probably be possible to do, so thought I could put it up here.

julia> G = tf([0.1, 0], [0.1, 1]);

julia> H = c2d(G, 0.01, :fwdeuler);

julia> bodeplot([G, H])
ERROR: Sampling time mismatch
Stacktrace:
 [1] promote_rule(#unused#::Type{Discrete{Float64}}, #unused#::Type{Continuous})
   @ ControlSystems ~/.julia/packages/ControlSystems/lbxGy/src/types/TimeEvolution.jl:31
 [2] promote_type
   @ ./promotion.jl:289 [inlined]
 [3] promote_rule(#unused#::Type{TransferFunction{Continuous, ControlSystems.SisoRational{Float64}}}, #unused#::Type{TransferFunction{Discrete{Float64}, ControlSystems.SisoRational{Float64}}})
   @ ControlSystems ~/.julia/packages/ControlSystems/lbxGy/src/types/promotion.jl:36
 [4] promote_type
   @ ./promotion.jl:289 [inlined]
 [5] promote_typeof(x::TransferFunction{Continuous, ControlSystems.SisoRational{Float64}}, xs::TransferFunction{Discrete{Float64}, ControlSystems.SisoRational{Float64}})
   @ Base ./promotion.jl:330
 [6] vect(::TransferFunction{Continuous, ControlSystems.SisoRational{Float64}}, ::Vararg{Any})
   @ Base ./array.jl:144
 [7] top-level scope
   @ REPL[8]:1

julia> bodeplot(G)

julia> bodeplot!(H) # Works nicely

albheim avatar Mar 08 '22 15:03 albheim

The problem is not the plot, it's the creation of the vector

julia> G = tf([0.1, 0], [0.1, 1]);

julia> H = c2d(G, 0.01, :fwdeuler);

julia> [G, H]
ERROR: Sampling time mismatch
Stacktrace:
 [1] promote_rule(#unused#::Type{Discrete{Float64}}, #unused#::Type{Continuous})
   @ ControlSystems ~/.julia/dev/ControlSystems/src/types/TimeEvolution.jl:31
 [2] promote_type
   @ ./promotion.jl:289 [inlined]
 [3] promote_rule(#unused#::Type{TransferFunction{Continuous, ControlSystems.SisoRational{Float64}}}, #unused#::Type{TransferFunction{Discrete{Float64}, ControlSystems.SisoRational{Float64}}})
   @ ControlSystems ~/.julia/dev/ControlSystems/src/types/promotion.jl:36
 [4] promote_type
   @ ./promotion.jl:289 [inlined]
 [5] promote_typeof(x::TransferFunction{Continuous, ControlSystems.SisoRational{Float64}}, xs::TransferFunction{Discrete{Float64}, ControlSystems.SisoRational{Float64}})
   @ Base ./promotion.jl:330
 [6] vect(::TransferFunction{Continuous, ControlSystems.SisoRational{Float64}}, ::Vararg{Any})
   @ Base ./array.jl:144
 [7] top-level scope
   @ REPL[12]:1

The following works

julia> TransferFunction[G, H]
2-element Vector{TransferFunction}:

baggepinnen avatar Mar 08 '22 15:03 baggepinnen

I have also been bothered by our handling of of vect and cat etc., it's sometimes inconventient to build arrays of systems without forming a single MIMO system, might be worth spending some time to figure out best practices here before 1.0

baggepinnen avatar Mar 08 '22 15:03 baggepinnen