diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 57c749d..48d94ad 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,6 +1,5 @@ name: CI on: - - push - pull_request jobs: test: diff --git a/src/SymbolicControlSystems.jl b/src/SymbolicControlSystems.jl index 000b61b..2939fa6 100644 --- a/src/SymbolicControlSystems.jl +++ b/src/SymbolicControlSystems.jl @@ -89,27 +89,31 @@ function ControlSystemsBase.tf(sys::Sym, h = nothing) # d = d.monic() # Don't do this here if h === nothing || h isa Continuous d = sp.Poly(d, s) - n = n isa Number ? n : sp.Poly(n, s) + n = n isa Number ? 1.0*n : sp.Poly(n, s) tf(expand_coeffs(n, s), expand_coeffs(d, s)) else d = sp.Poly(d, z) - n = n isa Number ? n : sp.Poly(n, z) + n = n isa Number ? 1.0*n : sp.Poly(n, z) tf(expand_coeffs(n, z), expand_coeffs(d, z), h) end end function expand_coeffs(n, var; numeric = false) - n = sp.Poly(n, var) - deg = n.degree() |> Float64 |> Int - c = n.all_coeffs() # This fails if the coeffs are symbolic - numeric && (c = Float64.(c)) - [c; zeros(eltype(c), deg - length(c) + 1)] + if n == 0 + [0.0] + else + n = sp.Poly(n, var) + deg = n.degree() |> Float64 |> Int + c = n.all_coeffs() # This fails if the coeffs are symbolic + numeric && (c = Float64.(c)) + [c; zeros(eltype(c), deg - length(c) + 1)] + end end expand_coeffs(n::Real, args...; numeric = false) = n function ControlSystemsBase.tf(sys::NumOrDiv, h = nothing) - sp = Symb.symbolics_to_sympy(sys) - G = tf(sp, h) + sys_sp = Symb.symbolics_to_sympy(sys) + G = h === nothing || h === Continuous() ? tf(sys_sp) : tf(sys_sp, h) tf(to_num.(numvec(G)[]), to_num.(denvec(G)[]), G.timeevol) end @@ -144,7 +148,8 @@ function to_num(x::Sym)::Num try return Float64(x) catch - Symb.Num(Symb.variable(Symbol(x); T=Real)) + # Symb.Num(Symb.variable(Symbol(x); T=Real)) + Symb.parse_expr_to_symbolic(Meta.parse(string(x)), Main) end end diff --git a/test/runtests.jl b/test/runtests.jl index e285b45..d0d86e5 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -4,7 +4,7 @@ using ControlSystemsBase s = SymbolicControlSystems.s z = SymbolicControlSystems.z import Symbolics -import Symbolics: Num +using Symbolics: Num using LinearAlgebra isinteractive() && (Base.active_repl.options.hint_tab_completes = false) # This messes with sympy https://discourse.julialang.org/t/sympy-makes-repl-to-stuck/124814/6 @@ -96,6 +96,13 @@ end @test_both tf([b, a], [1, c, 1]) (b*s + a)/(s^2 + c*s + 1) @test_both tf([b, a], [1, c, 1], 0.1) (b*z + a)/(z^2 + c*z + 1) + + @syms T + @test convert(typeof(tf(1, [T, 1])), 0) == tf(0) + @test_nowarn [0 tf(1, [T, 1]); 0 tf(1)] + @test [tf(0) tf(1, [T, 1])] == [0 tf(1, [T, 1])] + + end