Skip to content

Commit f15edfe

Browse files
committed
more helpful error message un baltrunc
1 parent 475758a commit f15edfe

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

docs/src/examples/tuning_from_data.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ gangoffourplot(P, CF)
112112

113113
The gang of four indicates that we have a robust tuning, no uncomfortably large peaks appears in either ``T`` or ``S``.
114114

115-
Below, we attempt a pole-placement design for comparison. Contrary to the PID controller, a pole-placement controller _can_ place all poles of this system arbitrarily (the system is _controllable_, which can be verified using the function [`controllability`](@ref)).
115+
Below, we attempt a pole-placement design for comparison. Contrary to the PID controller, a state-feedback controller designed using pole placement _can_ place all poles of this system arbitrarily (the system is _controllable_, which can be verified using the function [`controllability`](@ref)).
116116

117117

118118
## Pole placement

lib/ControlSystemsBase/src/matrix_comps.jl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -635,6 +635,11 @@ function baltrunc(sys::ST; atol = sqrt(eps()), rtol = 1e-3, n = nothing, residua
635635
S = S[S .>= S[1]*rtol]
636636
n = length(S)
637637
else
638+
n > sys.nx && error("n too large. A state dimension of n = $n was requested, but the original system has a $(sys.nx)-dimensional state.")
639+
if length(S) < n
640+
@error("n too large. A state dimension of n = $n was requested, but after a balanced realization was computed only $(length(S)) dimensions remain. Try either calling `minreal` before calling `baltrunc`, or try balancing the model using `balance_statespace`. Returning a system with n = $(length(S))")
641+
n = length(S)
642+
end
638643
S = S[1:n]
639644
end
640645
i1 = 1:n

0 commit comments

Comments
 (0)