Skip to content

Commit 5b1043c

Browse files
authored
Merge pull request #94 from JuliaControl/BugsAnd0.6
Julia 0.6
2 parents d43aca2 + a7e19e8 commit 5b1043c

35 files changed

+253
-240
lines changed

.travis.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
language: julia
22
julia:
3-
- 0.5
3+
- 0.6
44
notifications:
55
email: false
66
script:
77
- if [[ -a .git/shallow ]]; then git fetch --unshallow; fi
88
- julia -e 'Pkg.clone(pwd()); Pkg.build("ControlSystems")'
9-
- julia -e 'ENV["PYTHON"] = ""; Pkg.clone("PyPlot"); Pkg.build("PyPlot")'
9+
#- julia -e 'ENV["PYTHON"] = ""; Pkg.clone("PyPlot"); Pkg.build("PyPlot")'
1010
- julia -e 'Pkg.clone("https://github.com/JuliaControl/ControlExamplePlots.jl.git");'
1111
- julia -e 'Pkg.test("ControlSystems"; coverage=true)'
1212
after_success:

REQUIRE

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
julia 0.5-
2-
Plots v0.7.4
1+
julia 0.6-
2+
Plots 0.7.4
33
Polynomials

docs/src/makeplots.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ println("Generating plots")
44

55
plotsDir = (pwd()[end-3:end] == "docs") ? "build/plots" : "docs/build/plots"
66
mkdir(plotsDir)
7-
Plots.pyplot()
7+
Plots.gr()
88

99

1010
# PID design functions
@@ -76,7 +76,7 @@ pidplots(P,:gof,;kps=kp,kis=ki, ω= logspace(-2,2,500))
7676
Plots.savefig(plotsDir*"/pidplotgof1.svg")
7777

7878
kp = linspace(-1,1,8) # Now try a different strategy, where we have specified a gain crossover frequency of 0.1 rad/s
79-
ki = sqrt(1-kp.^2)/10
79+
ki = sqrt.(1-kp.^2)./10
8080
pidplots(P,:nyquist,;kps=kp,kis=ki)
8181
Plots.savefig(plotsDir*"/pidplotsnyquist2.svg")
8282
pidplots(P,:gof,;kps=kp,kis=ki)

src/ControlSystems.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ export LTISystem,
6464
denpoly
6565

6666
import Plots
67-
import Base: +, -, *, /, (./), (==), (.+), (.-), (.*), (!=), isapprox, call, convert, promote_op
67+
import Base: +, -, *, /, (./), (==), (.+), (.-), (.*), (!=), isapprox, convert, promote_op
6868

6969
include("types/lti.jl")
7070
include("types/transferfunction.jl")

src/analysis.jl

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,9 @@ Compute the zeros, poles, and gains of system `sys`.
5252
`k` : Matrix{Float64}, (ny x nu)""" ->
5353
function zpkdata(sys::LTISystem)
5454
ny, nu = size(sys)
55-
zs = Array(Vector{Complex128}, ny, nu)
56-
ps = Array(Vector{Complex128}, ny, nu)
57-
ks = Array(Float64, ny, nu)
55+
zs = Array{Vector{Complex128}}(ny, nu)
56+
ps = Array{Vector{Complex128}}(ny, nu)
57+
ks = Array{Float64}(ny, nu)
5858
for j = 1:nu
5959
for i = 1:ny
6060
zs[i, j], ps[i, j], ks[i, j] = _zpk_kern(sys, i, j)
@@ -96,11 +96,11 @@ function damp(sys::LTISystem)
9696
Ts = sys.Ts == -1 ? 1 : sys.Ts
9797
ps = log(ps)/Ts
9898
end
99-
Wn = abs(ps)
99+
Wn = abs.(ps)
100100
order = sortperm(Wn)
101101
Wn = Wn[order]
102102
ps = ps[order]
103-
ζ = -cos(angle(ps))
103+
ζ = -cos.(angle.(ps))
104104
return Wn, ζ, ps
105105
end
106106

@@ -205,7 +205,7 @@ function reduce_sys(A::Matrix{Float64}, B::Matrix{Float64}, C::Matrix{Float64},
205205
break
206206
elseif nu == 0
207207
# System has no zeros, return empty matrices
208-
A = B = Cbar = Dbar = Float64[]
208+
A = B = Cbar = Dbar = Array{Float64,2}(0,0)
209209
break
210210
end
211211
# Update System
@@ -233,7 +233,7 @@ end
233233
function fastrank(A::Matrix{Float64}, meps::Float64)
234234
n, m = size(A, 1, 2)
235235
if n*m == 0 return 0 end
236-
norms = Array(Float64, n)
236+
norms = Array{Float64}(n)
237237
for i = 1:n
238238
norms[i] = norm(A[i, :])
239239
end
@@ -300,7 +300,7 @@ function sisomargin{S<:Real}(sys::LTISystem, w::AbstractVector{S}; full=false, a
300300
gm, idx = findmin([gm;Inf])
301301
wgm = [wgm;NaN][idx]
302302
fi = [fi;NaN][idx]
303-
pm, idx = findmin([abs(pm);Inf])
303+
pm, idx = findmin([abs.(pm);Inf])
304304
wpm = [wpm;NaN][idx]
305305
if full
306306
if !isnan(fi) #fi may be NaN, fullPhase is a scalar

src/connections.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ append(systems::LTISystem...) = append(promote(systems...)...)
5151
#This is needed until julia removes deprecated vect()
5252
function Base.vect(sys::Union{LTISystem, Real}...)
5353
T = Base.promote_typeof(sys...)
54-
copy!(Array(T,length(sys)), sys)
54+
copy!(Array{T}(length(sys)), sys)
5555
end
5656

5757
function Base.vcat(systems::StateSpace...)

src/discrete.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -231,9 +231,9 @@ function lsima{T}(sys::StateSpace, t::AbstractVector, r::AbstractVector{T}, cont
231231
dsys, x0map = c2d(sys, dt, :foh)
232232
end
233233
n = size(t, 1)
234-
x = Array(T, size(sys.A, 1), n)
235-
u = Array(T, n)
236-
y = Array(T, n)
234+
x = Array{T}(size(sys.A, 1), n)
235+
u = Array{T}(n)
236+
y = Array{T}(n)
237237
for i=1:n
238238
x[:,i] = x0
239239
y[i] = (sys.C*x0 + sys.D*u[i])[1]

src/freqresp.jl

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ function freqresp{S<:Real}(sys::LTISystem, w::AbstractVector{S})
1717
end
1818
#Evil but nessesary type instability here
1919
sys = _preprocess_for_freqresp(sys)
20-
resp = Array(Complex128, nw, ny, nu)
20+
resp = Array{Complex128}(nw, ny, nu)
2121
for i=1:nw
2222
# TODO : This doesn't actually take advantage of Hessenberg structure
2323
# for statespace version.
@@ -66,7 +66,7 @@ function evalfr(sys::TransferFunction, s::Number)
6666
S = promote_type(typeof(s), Float64)
6767
mat = sys.matrix
6868
ny, nu = size(mat)
69-
res = Array(S, ny, nu)
69+
res = Array{S}(ny, nu)
7070
for j = 1:nu
7171
for i = 1:ny
7272
res[i, j] = evalfr(mat[i, j], s)
@@ -111,7 +111,7 @@ at frequencies `w`
111111
`mag` and `phase` has size `(length(w), ny, nu)`""" ->
112112
function bode(sys::LTISystem, w::AbstractVector)
113113
resp = freqresp(sys, w)[1]
114-
return abs(resp), rad2deg(unwrap!(angle(resp),1)), w
114+
return abs.(resp), rad2deg.(unwrap!(angle.(resp),1)), w
115115
end
116116
bode(sys::LTISystem) = bode(sys, _default_freq_vector(sys, :bode))
117117

@@ -136,7 +136,7 @@ frequencies `w`
136136
function sigma(sys::LTISystem, w::AbstractVector)
137137
resp = freqresp(sys, w)[1]
138138
nw, ny, nu = size(resp)
139-
sv = Array(Float64, nw, min(ny, nu))
139+
sv = Array{Float64}(nw, min(ny, nu))
140140
for i=1:nw
141141
sv[i, :] = svdvals(resp[i, :, :])
142142
end
@@ -148,7 +148,7 @@ function _default_freq_vector{T<:LTISystem}(systems::Vector{T}, plot::Symbol)
148148
min_pt_per_dec = 60
149149
min_pt_total = 200
150150
nsys = length(systems)
151-
bounds = Array(Float64, 2, nsys)
151+
bounds = Array{Float64}(2, nsys)
152152
for i=1:nsys
153153
# TODO : For now we ignore the feature information. In the future,
154154
# these can be used to improve the frequency vector near features.
@@ -180,7 +180,7 @@ function _bounds_and_features(sys::LTISystem, plot::Symbol)
180180
zp = [tzero(sys); pole(sys)]
181181
end
182182
# Get the frequencies of the features, ignoring low frequency dynamics
183-
fzp = log10(abs(zp))
183+
fzp = log10.(abs.(zp))
184184
fzp = fzp[fzp .> -4]
185185
fzp = sort!(fzp)
186186
# Determine the bounds on the frequency vector

src/matrix_comps.jl

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ function dare(A, B, Q, R)
5454
-Ait*Q Ait]
5555

5656
S = schurfact(Z)
57-
S = ordschur(S, abs(S.values).<=1)
57+
S = ordschur(S, abs.(S.values).<=1)
5858
U = S.Z
5959

6060
(m, n) = size(U)
@@ -181,14 +181,14 @@ end
181181
covar(sys::TransferFunction, W::StridedMatrix) = covar(ss(sys), W)
182182

183183

184-
# Note: the H∞ norm computation is probably not as accurate as with SLICOT,
184+
# Note: the H∞ norm computation is probably not as accurate as with SLICOT,
185185
# but this seems to be still reasonably ok as a first step
186186
@doc """
187187
`.. norm(sys, p=2; tol=1e-6)`
188188
189189
`norm(sys)` or `norm(sys,2)` computes the H2 norm of the LTI system `sys`.
190190
191-
`norm(sys, Inf)` computes the L∞ norm of the LTI system `sys`.
191+
`norm(sys, Inf)` computes the L∞ norm of the LTI system `sys`.
192192
The H∞ norm is the same as the L∞ for stable systems, and Inf for unstable systems.
193193
If the peak gain frequency is required as well, use the function `norminf` instead.
194194
@@ -202,7 +202,7 @@ The L∞ norm computation implements the 'two-step algorithm' in:
202202
N.A. Bruinsma and M. Steinbuch, 'A fast algorithm to compute the H∞-norm
203203
of a transfer function matrix', Systems and Control Letters 14 (1990), pp. 287-293.
204204
For the discrete-time version, see, e.g.,: P. Bongers, O. Bosgra, M. Steinbuch, 'L∞-norm
205-
calculation for generalized state space systems in continuous and discrete time',
205+
calculation for generalized state space systems in continuous and discrete time',
206206
American Control Conference, 1991.
207207
""" ->
208208
function Base.norm(sys::StateSpace, p::Real=2; tol=1e-6)
@@ -226,11 +226,11 @@ end
226226
@doc """
227227
`.. (peakgain, peakgainfrequency) = norminf(sys; tol=1e-6)`
228228
229-
Compute the L∞ norm of the LTI system `sys`, together with the frequency
229+
Compute the L∞ norm of the LTI system `sys`, together with the frequency
230230
`peakgainfrequency` (in rad/TimeUnit) at which the gain achieves its peak value `peakgain`.
231231
The H∞ norm is the same as the L∞ for stable systems, and Inf for unstable systems.
232232
233-
`tol` is an optional keyword argument representing the desired relative accuracy for
233+
`tol` is an optional keyword argument representing the desired relative accuracy for
234234
the computed L∞ norm (this is not an absolute certificate however).
235235
236236
sys is first converted to a state space model if needed.
@@ -239,7 +239,7 @@ The L∞ norm computation implements the 'two-step algorithm' in:
239239
N.A. Bruinsma and M. Steinbuch, 'A fast algorithm to compute the H∞-norm
240240
of a transfer function matrix', Systems and Control Letters 14 (1990), pp. 287-293.
241241
For the discrete-time version, see, e.g.,: P. Bongers, O. Bosgra, M. Steinbuch, 'L∞-norm
242-
calculation for generalized state space systems in continuous and discrete time',
242+
calculation for generalized state space systems in continuous and discrete time',
243243
American Control Conference, 1991.
244244
""" ->
245245
function norminf(sys::StateSpace; tol=1e-6)
@@ -277,9 +277,9 @@ function normLinf_twoSteps_ct(sys::StateSpace, tol=1e-6, maxIters=1000, approxim
277277
fpeak = 0
278278
end
279279
if isreal(p) # only real poles
280-
omegap = minimum(abs(p))
280+
omegap = minimum(abs.(p))
281281
else # at least one pair of complex poles
282-
tmp = maximum(abs(imag(p)./(real(p).*abs(p))))
282+
tmp = maximum(abs.(imag.(p)./(real.(p).*abs.(p))))
283283
omegap = abs(p[indmax(tmp)])
284284
end
285285
(lb, idx) = findmax([lb, maximum(svdvals(evalfr(sys, omegap*1im)))])
@@ -297,7 +297,7 @@ function normLinf_twoSteps_ct(sys::StateSpace, tol=1e-6, maxIters=1000, approxim
297297
H = [ M -res*sys.B*(R\sys.B') ;
298298
res*sys.C'*(S\sys.C) -M' ]
299299
omegas = eigvals(H)
300-
omegaps = imag(omegas[ (abs(real(omegas)).<=approximag) & (imag(omegas).>=0) ])
300+
omegaps = imag.(omegas[ (abs.(real.(omegas)).<=approximag) .& (imag.(omegas).>=0) ])
301301
sort!(omegaps)
302302
if isempty(omegaps)
303303
return (1+tol)*lb, fpeak
@@ -324,7 +324,7 @@ function normLinf_twoSteps_dt(sys::StateSpace,tol=1e-6,maxIters=1000,approxcirc=
324324
end
325325
p = pole(sys)
326326
# Check first if there is a pole on the unit circle
327-
pidx = findfirst(map(x->isapprox(x,1.0),abs(p)))
327+
pidx = findfirst(map(x->isapprox(x,1.0),abs.(p)))
328328
if (pidx > 0)
329329
return (Inf, angle(p[pidx])/abs(sys.Ts))
330330
else
@@ -338,8 +338,8 @@ function normLinf_twoSteps_dt(sys::StateSpace,tol=1e-6,maxIters=1000,approxcirc=
338338
p = p[imag(p).>0]
339339
if ~isempty(p) # not just real poles
340340
# find frequency of pôle closest to unit circle
341-
omegap = angle(p[findmin(abs(abs(p)-1))[2]])
342-
else
341+
omegap = angle(p[findmin(abs.(abs.(p)-1))[2]])
342+
else
343343
omegap = pi/2
344344
end
345345
(lb, idx) = findmax([lb, maximum(svdvals(evalfr(sys, exp(omegap*1im))))])
@@ -355,11 +355,11 @@ function normLinf_twoSteps_dt(sys::StateSpace,tol=1e-6,maxIters=1000,approxcirc=
355355
RinvDt = R\sys.D'
356356
L = [ sys.A+sys.B*RinvDt*sys.C sys.B*(R\sys.B');
357357
zeros(sys.nx,sys.nx) eye(sys.nx)]
358-
M = [ eye(sys.nx) zeros(sys.nx,sys.nx);
358+
M = [ eye(sys.nx) zeros(sys.nx,sys.nx);
359359
sys.C'*(eye(sys.ny)+sys.D*RinvDt)*sys.C L[1:sys.nx,1:sys.nx]']
360360
zs = eig(L,M)[1] # generalized eigenvalues
361361
# are there eigenvalues on the unit circle?
362-
omegaps = angle(zs[ (abs(abs(zs)-1) .<= approxcirc) & (imag(zs).>=0)])
362+
omegaps = angle.(zs[ (abs.(abs.(zs)-1) .<= approxcirc) .& (imag(zs).>=0)])
363363
sort!(omegaps)
364364
if isempty(omegaps)
365365
return (1+tol)*lb, fpeak/sys.Ts
@@ -428,8 +428,8 @@ P = gram(sys, :c)
428428
Q = gram(sys, :o)
429429
Q1 = chol(Q)
430430
U,Σ,V = svd(Q1*P*Q1')
431-
Σ = sqrt(Σ)
432-
Σ1 = diagm((sqrt(Σ)))
431+
Σ .= sqrt.(Σ)
432+
Σ1 = diagm(sqrt.(Σ))
433433
T = Σ1\(U'Q1)
434434

435435
Pz = T*P*T'

src/pid_design.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ See also `stabregionPID`, `loopshapingPI`, `pidplots`
193193
"""
194194
function stabregionPID(P, ω = _default_freq_vector(P,:bode); kd=0, doplot = true)
195195
Pv = squeeze(freqresp(P,ω)[1],(2,3))
196-
r = abs(Pv)
196+
r = abs.(Pv)
197197
phi = angle(Pv)
198198
kp = -cos(phi)./r
199199
ki = kd*ω.^2 - ω.*sin(phi)./r
@@ -205,7 +205,7 @@ function stabregionPID(P::AbstractString, ω = logspace(-3,1); kd=0, doplot = tr
205205
Pe = parse(P)
206206
Pf(s) = eval(:(s -> $(Pe)))(s)
207207
Pv = Pf(im*ω)
208-
r = abs(Pv)
208+
r = abs.(Pv)
209209
phi = angle(Pv)
210210
kp = -cos(phi)./r
211211
ki = kd*ω.^2 - ω.*sin(phi)./r
@@ -228,7 +228,7 @@ See also `pidplots`, `stabregionPID`
228228
function loopshapingPI(P,ωp; ϕl=0,rl=0, phasemargin = 0, doplot = false)
229229
Pw = P(im*ωp)[1]
230230
ϕp = angle(Pw)
231-
rp = abs(Pw)
231+
rp = abs.(Pw)
232232

233233
if phasemargin > 0
234234
ϕl = deg2rad(-180+phasemargin)

0 commit comments

Comments
 (0)