diff --git a/docs/src/examples/tuning_from_data.md b/docs/src/examples/tuning_from_data.md index 08530d6c8..3ac4c2a91 100644 --- a/docs/src/examples/tuning_from_data.md +++ b/docs/src/examples/tuning_from_data.md @@ -112,7 +112,7 @@ gangoffourplot(P, CF) The gang of four indicates that we have a robust tuning, no uncomfortably large peaks appears in either ``T`` or ``S``. -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)). +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)). ## Pole placement diff --git a/lib/ControlSystemsBase/src/matrix_comps.jl b/lib/ControlSystemsBase/src/matrix_comps.jl index b734b3750..c9b67f286 100644 --- a/lib/ControlSystemsBase/src/matrix_comps.jl +++ b/lib/ControlSystemsBase/src/matrix_comps.jl @@ -635,6 +635,11 @@ function baltrunc(sys::ST; atol = sqrt(eps()), rtol = 1e-3, n = nothing, residua S = S[S .>= S[1]*rtol] n = length(S) else + 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.") + if length(S) < n + @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))") + n = length(S) + end S = S[1:n] end i1 = 1:n