Skip to content

Commit cf00a02

Browse files
committed
more minor fixes and work towards tests
1 parent ea3c03e commit cf00a02

File tree

7 files changed

+71
-72
lines changed

7 files changed

+71
-72
lines changed

REQUIRE

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
julia 0.6.0
1+
julia 0.6.0 0.7.0
22
Plots 0.7.4
33
Polynomials 0.3.0
44
LaTeXStrings

src/ControlSystems.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ abstract type AbstractSystem end
7979

8080
include("types/Lti.jl")
8181

82-
abstract type SisoTf{T<:Number} end
82+
include("types/SisoTf.jl")
8383

8484
# Transfer functions and tranfer function elemements
8585
include("types/TransferFunction.jl")

src/load.jl

-59
This file was deleted.

src/types/SisoTf.jl

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
abstract type SisoTf{T<:Number} end
2+
3+
+(f1::SisoTf, f2::SisoTf) = +(promote(f1,f2)...)
4+
-(f1::SisoTf, f2::SisoTf) = -(promote(f1,f2)...)
5+
6+
*(f1::SisoTf, f2::SisoTf) = *(promote(f1,f2)...)
7+
/(f1::SisoTf, f2::SisoTf) = /(promote(f1,f2)...)

src/types/SisoTfTypes/SisoZpk.jl

+7-5
Original file line numberDiff line numberDiff line change
@@ -148,9 +148,9 @@ function evalfr(f::SisoZpk{T1,TR}, s::T2) where {T1<:Number, TR<:Number, T2<:Num
148148
end
149149

150150

151-
function poly_factors2string(poly_factors, var)
151+
function poly_factors2string(poly_factors::AbstractArray{<:Poly{T}}, var) where T
152152
if length(poly_factors) == 0
153-
str = "1.0"
153+
str = sprint(printpolyfun(var), Poly{T}(one(T)))
154154
elseif length(poly_factors) == 1
155155
str = sprint(printpolyfun(var), poly_factors[1])
156156
else
@@ -162,9 +162,11 @@ end
162162
for systems on zpk form. Should at least handle the following types
163163
Measurment, Dual, Sym. """
164164
function _printcoefficient(nbr::Number)
165-
nbr_string = string(nbr)
165+
# Print type information as in 1.0f0 for Float32
166+
# showcompact might be better, but is not consistent with polynomials
167+
nbr_string = sprint(show,nbr)
166168
if contains(nbr_string, " + ") || contains(nbr_string, " - ") || contains(nbr_string, " ± ")
167-
return "($nbr_string)"
169+
return "(" * nbr_string * ")" # Add parens
168170
else
169171
return nbr_string
170172
end
@@ -203,7 +205,7 @@ end
203205

204206

205207

206-
==(f1::SisoZpk, f2::SisoZpk) = (f1-f2).k == 0.0
208+
==(f1::SisoZpk, f2::SisoZpk) = (f1-f2).k == 0
207209
function isapprox(f1::SisoZpk, f2::SisoZpk; rtol::Real=sqrt(eps()), atol::Real=sqrt(eps()))
208210
fdiff = f1 - f2
209211
isapprox(fdiff.k, 0, atol=atol, rtol=rtol)

test/test_zpk.jl

+15
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,21 @@ z2 = [-4.5-sqrt(4.5^2-17), -4.5+sqrt(4.5^2-17)]
8888

8989
# Test that number of poles matter
9090
@test !(zpk(Int64[],[1,1],1) == zpk(Int64[],[1],1))
91+
92+
# Test SispZpk and SisoTf operations
93+
C_212_tf = tf(C_212)
94+
C_111_tf = tf(C_111)
95+
# Add
96+
@test C_212_tf + C_212 2*C_212
97+
@test C_212 + C_212_tf 2*C_212
98+
# Approx
99+
@test C_212_tf + C_212 2*C_212_tf
100+
# Minus
101+
@test 2*C_212_tf - C_212 C_212
102+
# Multiply
103+
@test C_212_tf*C_111 C_212*C_111
104+
@test C_212_tf*C_111 C_212_tf*C_111_tf
105+
91106
# TODO test printing when it is implemented better
92107

93108
# Tests of minreal

test/types.jl

+40-6
Original file line numberDiff line numberDiff line change
@@ -272,13 +272,47 @@ all_fuctions_types = [
272272

273273

274274
ss1matrix(T) = (T[-1 1; 0 1], T[1 0;0 1], T[1 0], fill(T(0),1,2))
275-
args = [
276-
(Float32, Dict(
277-
"statespace" => StateSpace{Float32, Matrix{Float32}}(ss1matrix(Float32)..., 0),
278-
"tf" => ,
279-
"zpk" =>,
280-
)
275+
ss2matrix(T) = (T[-3 1; 0 1], T[1 0;0 1], T[1 0], fill(T(0),1,2))
276+
277+
tf1matrix(T) = [SisoRational{T}([1,-1],[1,0,-1]) SisoRational{T}([1,],[1,0,-1])]
278+
tf2matrix(T) = [SisoRational{T}([1,-1],[1,2,-3]) SisoRational{T}([1,],[1,2,-3])]
279+
280+
zpk1matrix(T) = [SisoZpk{T,Complex{T}}([-1,],[1, -1],1) SisoZpk{T,Complex{T}}([],[1,-1],1)]
281+
zpk2matrix(T) = [SisoZpk{T,Complex{T}}([-1,],[-3, 1],1) SisoZpk{T,Complex{T}}([],[-3,1],1)]
281282

283+
systemsdict(T) = Dict(
284+
"statespace1" => StateSpace{T, Matrix{T}}(ss1matrix(T)..., 0),
285+
"statespace2" => StateSpace{T, Matrix{T}}(ss2matrix(T)..., 0),
286+
"tf1" => TransferFunction{SisoRational{T}}(tf1matrix(T), 0),
287+
"tf2" => TransferFunction{SisoRational{T}}(tf2matrix(T), 0),
288+
"zpk1" => TransferFunction{SisoZpk{T,Complex{T}}}(zpk1matrix(T), 0),
289+
"zpk1" => TransferFunction{SisoZpk{T,Complex{T}}}(zpk2matrix(T), 0),
290+
)
291+
292+
# (ss1 +0im, ss2 +im*ss1,
293+
# tf1 +0im, tf2 +im*tf2,
294+
# zpk1+0im, zpk1+im*zpk2 )
295+
systemsdict_complex(T) = Dict(
296+
"statespace1" => StateSpace{Complex{T}, Matrix{Complex{T}}}(
297+
(ss1matrix(T) .+ 0 .* im.*ss1matrix(T))..., 0),
298+
"statespace2" => StateSpace{Complex{T}, Matrix{Complex{T}}}(
299+
(ss2matrix(T) .+ 1 .* im.*ss1matrix(T))..., 0),
300+
"tf1" => TransferFunction{SisoRational{Complex{T}}}(
301+
(tf1matrix(T) .+ 0 .* im.*tf1matrix(T)), 0),
302+
"tf2" => TransferFunction{SisoRational{Complex{T}}}(
303+
(tf2matrix(T) .+ 1 .* im.*tf1matrix(T)), 0),
304+
# "zpk1" => TransferFunction{SisoZpk{T,Complex{T}}}(
305+
# (zpk1matrix(T) .+ 0 .* im.*zpk1matrix(T))..., 0),
306+
# "zpk1" => TransferFunction{SisoZpk{T,Complex{T}}}(
307+
# (zpk2matrix(T) .+ 1 .* im.*zpk1matrix(T))..., 0),
308+
)
309+
310+
args = [
311+
(Float32, systemsdict(Float32)),
312+
(Float64, systemsdict(Float64)),
313+
(Int, systemsdict(Int)),
314+
(Complex{Float32}, systemsdict_complex(Float32)),
315+
(Complex{Float64}, systemsdict_complex(Float64)),
282316
]
283317
# NOTE
284318
# Test isleaftype(Base.code_typed(f, typeof(args))[1][2])

0 commit comments

Comments
 (0)