Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion lib/ControlSystemsBase/src/matrix_comps.jl
Original file line number Diff line number Diff line change
Expand Up @@ -542,7 +542,7 @@ Compute a similarity transform `T = S*P` resulting in `B = T\\A*T` such that the
and column norms of `B` are approximately equivalent. If `perm=false`, the
transformation will only scale `A` using diagonal `S`, and not permute `A` (i.e., set `P=I`).
"""
function balance(A, perm::Bool=true)
function balance(A::AbstractMatrix{<:LinearAlgebra.BlasFloat}, perm::Bool=true)
n = LinearAlgebra.checksquare(A)
B = copy(A)
job = perm ? 'B' : 'S'
Expand Down Expand Up @@ -570,6 +570,11 @@ function cswap!(i::Integer, j::Integer, X::StridedMatrix)
end
end

function balance(A::AbstractMatrix, perm::Bool=true)
Ac = Float64.(A)
balance(Ac, perm)
end



"""
Expand Down
5 changes: 5 additions & 0 deletions lib/ControlSystemsBase/test/test_matrix_comps.jl
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ sysb,T = ControlSystemsBase.balance_statespace(sys)
@test similarity_transform(sysb, T) ≈ sys
Ab,Bb,Cb,T = ControlSystemsBase.balance_statespace(A,B,C)

sysbb,Tb = ControlSystemsBase.balance_statespace(big(1.0)*sys)
@test Tb ≈ T
@test sysbb ≈ sysb


@test Ab*T ≈ T*A
@test Bb ≈ T*B
@test Cb*T ≈ C
Expand Down
Loading