Skip to content

Commit

Permalink
Merge pull request #837 from JuliaControl/generibal
Browse files Browse the repository at this point in the history
make `balance_statespace` work for more system types
  • Loading branch information
baggepinnen authored May 13, 2023
2 parents ba2713d + 3c7632f commit 3c68895
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
2 changes: 2 additions & 0 deletions docs/src/man/numerical.md
Original file line number Diff line number Diff line change
Expand Up @@ -114,3 +114,5 @@ Linear systems with zero-order-hold inputs can be exactly simulated in discrete

For discrete-time systems, the function [`lsim!`](@ref) accepts a pre-allocated workspace objects that can be used to avoid allocations for repeated simulations.

### Numerical balancing
If you are only interested in the simulated outputs, not the state trajectories, you may consider applying balancing to the statespace model using [`balance_statespace`](@ref) before simulating, see the section on [State-space balancing](@ref) above. If the state trajectories are of interest, balancing can still be performed before simulation, and the inverse transformation applied to the state trajectories after simulation.
5 changes: 3 additions & 2 deletions lib/ControlSystemsBase/src/types/conversion.jl
Original file line number Diff line number Diff line change
Expand Up @@ -187,9 +187,10 @@ end
# balance_statespace(A2, B2, C2, perm)
# end

function balance_statespace(sys::StateSpace, perm::Bool=false)
function balance_statespace(sys::AbstractStateSpace, perm::Bool=false)
A, B, C, T = balance_statespace(sys.A,sys.B,sys.C, perm)
return ss(A,B,C,sys.D,sys.timeevol), T

return basetype(sys)(A,B,C,sys.D, ntuple(i->getfield(sys, i+4), fieldcount(typeof(sys))-4)...), T
end

# Method that might fail for some exotic types, such as TrackedArrays
Expand Down

0 comments on commit 3c68895

Please sign in to comment.