Skip to content

Commit c451824

Browse files
committed
Almost ready to go, LQG remains
1 parent 10898b5 commit c451824

20 files changed

+72
-54
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ Some of the available commands are:
4646
##### Constructing systems
4747
ss, tf, zpk, ss2tf
4848
##### Analysis
49-
pole, tzero, sysnorm, norminf, ctrb, obsv, gangoffour, margin, markovparam, damp, dampreport, zpkdata, dcgain, covar, gram, sigma, sisomargin
49+
pole, tzero, norm, norminf, ctrb, obsv, gangoffour, margin, markovparam, damp, dampreport, zpkdata, dcgain, covar, gram, sigma, sisomargin
5050
##### Synthesis
5151
care, dare, dlyap, lqr, dlqr, place, pid, leadlink, laglink, leadlinkat, rstd, rstc, dab
5252
##### Time and Frequency response

REQUIRE

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@ LaTeXStrings
55
OrdinaryDiffEq
66
IterTools
77
Colors
8+
DSP

docs/src/lib/analysis.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ gangofseven
1616
gram
1717
margin
1818
markovparam
19-
sysnorm
19+
norm
2020
obsv
2121
pole
2222
sigma

src/ControlSystems.jl

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ import Base: +, -, *, /, (==), (!=), isapprox, convert, promote_op
8080
import LinearAlgebra: BlasFloat
8181
export lyap # Make sure LinearAlgebra.lyap is available
8282
import Printf, Colors
83+
import DSP: conv
8384

8485
abstract type AbstractSystem end
8586

@@ -129,8 +130,6 @@ include("plotting.jl")
129130
@deprecate num numvec
130131
@deprecate den denvec
131132

132-
# @deprecate norm sysnorm
133-
134133
# The path has to be evaluated upon initial import
135134
const __CONTROLSYSTEMS_SOURCE_DIR__ = dirname(Base.source_path())
136135

src/analysis.jl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -124,14 +124,14 @@ function tzero(A::Matrix{T}, B::Matrix{T}, C::Matrix{T}, D::Matrix{T}) where T<:
124124
mat = [C D]
125125
# To ensure type-stability, we have to annote the type here, as qrfact
126126
# returns many different types.
127-
W = full(qrfact(mat')[:Q], thin=false)::Matrix{T}
128-
W = flipdim(W,2)
127+
W = qr(mat').Q
128+
W = reverse(W, dims=2)
129129
mat = mat*W
130130
if fastrank(mat', meps) > 0
131131
nf = size(A, 1)
132132
m = size(D, 2)
133133
Af = ([A B] * W)[1:nf, 1:nf]
134-
Bf = ([I zeros(nf, m)] * W)[1:nf, 1:nf]
134+
Bf = ([Matrix{T}(I, nf, nf) zeros(nf, m)] * W)[1:nf, 1:nf]
135135
zs = eigvals(Af, Bf)
136136
_fix_conjugate_pairs!(zs) # Generalized eigvals does not return exact conj. pairs
137137
else
@@ -180,10 +180,10 @@ function reduce_sys(A::AbstractMatrix{T}, B::AbstractMatrix{T}, C::AbstractMatri
180180
end
181181
# Update System
182182
n, m = size(B)
183-
Vm = [V zeros(T, n, m); zeros(T, m, n) I]
183+
Vm = [V zeros(T, n, m); zeros(T, m, n) Matrix{T}(I, m, m)]
184184
if sigma > 0
185185
M = [A B; Cbar Dbar]
186-
Vs = [V' zeros(T, n, sigma) ; zeros(T, sigma, n) I]
186+
Vs = [V' zeros(T, n, sigma) ; zeros(T, sigma, n) Matrix{T}(I, sigma, sigma)]
187187
else
188188
M = [A B]
189189
Vs = V'

src/matrix_comps.jl

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -432,7 +432,12 @@ Glad, Ljung, Reglerteori: Flervariabla och Olinjära metoder
432432
function balreal(sys::StateSpace)
433433
P = gram(sys, :c)
434434
Q = gram(sys, :o)
435-
Q1 = cholesky(Q).U
435+
436+
Q1 = try
437+
cholesky(Q).U
438+
catch
439+
throw(ArgumentError("Balanced realization failed: Observability grammian not positive definite, system needs to be observable"))
440+
end
436441
U,Σ,V = svd(Q1*P*Q1')
437442
Σ .= sqrt.(Σ)
438443
Σ1 = diagm(0 => sqrt.(Σ))

src/simplification.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ end
1111

1212
# Determine the structurally controllable and observable realization for the system
1313
struct_ctrb_obsv(sys::StateSpace) = struct_ctrb_obsv(sys.A, sys.B, sys.C)
14-
function struct_ctrb_obsv(A::VecOrMat, B::VecOrMat, C::VecOrMat)
14+
function struct_ctrb_obsv(A::AbstractVecOrMat, B::AbstractVecOrMat, C::AbstractVecOrMat)
1515
costates = struct_ctrb_states(A, B) .& struct_ctrb_states(A', C')
1616
if !all(costates)
1717
inds = findall(costates)
@@ -23,11 +23,11 @@ end
2323

2424
# Compute a bit-vector, expressing whether a state of the pair (A, B) is
2525
# structurally controllable.
26-
function struct_ctrb_states(A::VecOrMat, B::VecOrMat)
26+
function struct_ctrb_states(A::AbstractVecOrMat, B::AbstractVecOrMat)
2727
bitA = A .!= 0
28-
d_cvec = cvec = any(B .!= 0, 2)
28+
d_cvec = cvec = vec(any(B .!= 0, dims=2))
2929
while any(d_cvec .!= 0)
30-
Adcvec = any(bitA[:, findall(d_cvec)], 2)
30+
Adcvec = vec(any(bitA[:, findall(d_cvec)], dims=2))
3131
cvec = cvec .| Adcvec
3232
d_cvec = Adcvec .& .~cvec
3333
end

src/synthesis.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ If no second system is given, negative identity feedback is assumed
192192
"""
193193
function feedback(sys::StateSpace)
194194
sys.ny != sys.nu && error("Use feedback(sys1::StateSpace,sys2::StateSpace) if sys.ny != sys.nu")
195-
feedback(sys,ss(Matrix{numeric_type(sys)}(I,ny,ny)))
195+
feedback(sys,ss(Matrix{numeric_type(sys)}(I,sys.ny,sys.ny)))
196196
end
197197

198198
function feedback(sys1::StateSpace,sys2::StateSpace)

src/timeresp.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,6 @@ _issmooth(u::Function) = false
247247
function _issmooth(u, thresh::AbstractFloat=0.75)
248248
u = [zeros(1, size(u, 2)); u] # Start from 0 signal always
249249
dist = maximum(u) - minimum(u)
250-
du = abs.(diff(u))
250+
du = abs.(diff(u, dims=1))
251251
return !isempty(du) && all(maximum(du) <= thresh*dist)
252252
end

src/types/SisoTfTypes/SisoRational.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ Base.zero(f::SisoRational) = zero(typeof(f))
3535

3636
isproper(f::SisoRational) = (length(f.num) <= length(f.den))
3737

38-
function minreal(sys::SisoRational, eps::Real=sqrt(eps()))
39-
return SisoRational(minreal(SisoZpk(sys), eps))
38+
function minreal(sys::SisoRational{T}, eps::Real=sqrt(eps())) where T
39+
return convert(SisoRational{T}, minreal(convert(SisoZpk,sys), eps))
4040
end
4141

4242
function print_siso(io::IO, f::SisoRational, var=:s)

0 commit comments

Comments
 (0)