Skip to content

Commit

Permalink
add corner case constructor
Browse files Browse the repository at this point in the history
  • Loading branch information
baggepinnen committed May 22, 2019
1 parent 488d8c2 commit e9b9d8c
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/types/StateSpace.jl
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ function StateSpace{T,MT}(A::AbstractNumOrArray, B::AbstractNumOrArray, C::Abstr
return StateSpace{T,Matrix{T}}(MT(to_matrix(T, A)), MT(to_matrix(T, B)), MT(to_matrix(T, C)), MT(D), Float64(Ts))
end

function StateSpace{T,MT}(sys::StateSpace) where {T, MT <: AbstractMatrix{T}}
StateSpace{T,MT}(sys.A,sys.B,sys.C,sys.D,sys.Ts)
end

function StateSpace(A::AbstractNumOrArray, B::AbstractNumOrArray, C::AbstractNumOrArray, D::AbstractNumOrArray, Ts::Real=0)
T = promote_type(eltype(A),eltype(B),eltype(C),eltype(D))
A = to_matrix(T, A)
Expand Down
1 change: 1 addition & 0 deletions src/types/TransferFunction.jl
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ function /(n::Number, G::TransferFunction)
end
/(G::TransferFunction, n::Number) = G*(1/n)
/(G1::TransferFunction, G2::TransferFunction) = G1*(1/G2)
Base.:(/)(sys1::LTISystem, sys2::TransferFunction) = *(promote(sys1, ss(1/sys2))...) # This spcial case is needed to properly handle improper inverse transfer function (1/s)

Base.:^(sys::TransferFunction, p::Integer) = Base.power_by_squaring(sys, p)

Expand Down
3 changes: 3 additions & 0 deletions test/test_delayed_systems.jl
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
@testset "test_delay_system" begin
ω = 0.0:8

# broken: typeof(promote(delay(0.2), ss(1))[1]) == DelayLtiSystem{Float64}
Expand Down Expand Up @@ -170,3 +171,5 @@ y_impulse, t, _ = impulse(sys_known, 3)
@test maximum(abs, y_impulse - dy_expected.(t, K)) < 1e-2

@time [s11; s12]

end

0 comments on commit e9b9d8c

Please sign in to comment.