Skip to content

Commit

Permalink
only simplify small systems automatically
Browse files Browse the repository at this point in the history
  • Loading branch information
baggepinnen committed Aug 15, 2022
1 parent 2337475 commit a01ac33
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "SymbolicControlSystems"
uuid = "886cb795-8fd3-4b11-92f6-8071e46f71c5"
authors = ["Fredrik Bagge Carlson"]
version = "0.1.1"
version = "0.1.2"

[deps]
ControlSystems = "a6e380b2-a6ca-5380-bf3e-84a91bcd477e"
Expand Down
23 changes: 19 additions & 4 deletions src/SymbolicControlSystems.jl
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,15 @@ end

function SymPy.Sym(sys::StateSpace{<:Any,Sym})
A, B, C, D = ControlSystems.ssdata(sys)
if isdiscrete(sys)
(C*inv(z * I(size(A, 1)) - A)*B+D)[1]
expr = if isdiscrete(sys)
(C*inv(z * I(size(A, 1)) - A)*B+D)
else
(C*inv(s * I(size(A, 1)) - A)*B+D)
end
if size(expr) == (1,1)
return expr[]
else
(C*inv(s * I(size(A, 1)) - A)*B+D)[1]
return expr
end
end

Expand All @@ -56,7 +61,11 @@ function Num(sys::StateSpace{<:Any,Num})
A, B, C, D = ControlSystems.ssdata(sys)
λ = isdiscrete(sys) ? Symb.@variables(z) : Symb.@variables(s)
λ = λ[]
Symb.simplify((C*inv* I(size(A, 1)) - A)*B+D)[1])
ex = (C*inv* I(size(A, 1)) - A)*B+D)[1]
if sys.nx < 4
ex = Symb.simplify(ex)
end
ex
end

function Num(sys::TransferFunction)
Expand Down Expand Up @@ -120,6 +129,12 @@ function ControlSystems.minreal(sys::StateSpace{<:Any,NumOrDiv})
nsys = Symb.simplify_fractions.(nsys)
end

function ControlSystems.minreal(sys::StateSpace{<:Any,Sym})
# sys |> Symb.Num .|> Symb.symbolics_to_sympy .|> sp.simplify
nsys = Sym(sys)
nsys = sp.simplify.(nsys)
end

function Num(x::Sym)
try
return Float64(x)
Expand Down

0 comments on commit a01ac33

Please sign in to comment.