Skip to content

Commit 313d2b4

Browse files
committed
better error messages for failed inversion
1 parent b51adf7 commit 313d2b4

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

lib/ControlSystemsBase/src/discrete.jl

+3-3
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ ZoH sampling is exact for linear systems with piece-wise constant inputs (step i
2121
2222
FoH sampling is exact for linear systems with piece-wise linear inputs (ramp invariant), this is a good choice for simulation of systems with smooth continuous inputs.
2323
24-
To approximate the behavior of a continuous-time system well in the frequency domain, the `:tustin` (trapezoidal / bilinear) method may be most appropriate. In this case, the pre-warping argument can be used to ensure that the frequency response of the discrete-time system matches the continuous-time system at a given frequency. The tustin transformation alters the meaning of the state components, while ZoH and FoH preserve the meaning of the state components. The Tustin method is commonly used to discretize a continuous-tiem controller.
24+
To approximate the behavior of a continuous-time system well in the frequency domain, the `:tustin` (trapezoidal / bilinear) method may be most appropriate. In this case, the pre-warping argument can be used to ensure that the frequency response of the discrete-time system matches the continuous-time system at a given frequency. The tustin transformation alters the meaning of the state components, while ZoH and FoH preserve the meaning of the state components. The Tustin method is commonly used to discretize a continuous-time controller.
2525
2626
The forward-Euler method generally requires the sample time to be very small
2727
relative to the time constants of the system, and its use is generally discouraged.
@@ -99,8 +99,8 @@ function d2c(sys::AbstractStateSpace{<:Discrete}, method::Symbol=:zoh; w_prewarp
9999
ny, nu = size(sys)
100100
nx = nstates(sys)
101101
if method === :zoh
102-
M = log([A B;
103-
zeros(nu, nx) I])./sys.Ts
102+
M = log(Matrix([A B;
103+
zeros(nu, nx) I]))./sys.Ts
104104
Ac = M[1:nx, 1:nx]
105105
Bc = M[1:nx, nx+1:nx+nu]
106106
if eltype(A) <: Real

lib/ControlSystemsBase/src/types/StateSpace.jl

+2-1
Original file line numberDiff line numberDiff line change
@@ -431,10 +431,11 @@ end
431431
function /(n::Number, sys::ST) where ST <: AbstractStateSpace
432432
# Ensure s.D is invertible
433433
A, B, C, D = ssdata(sys)
434+
size(D, 1) == size(D, 2) || error("The inverted system must have the same number of inputs and outputs")
434435
Dinv = try
435436
inv(D)
436437
catch
437-
error("D isn't invertible")
438+
error("D isn't invertible. If you are trying to form a quotient between two systems `N(s) / D(s)` where the quotient is proper but the inverse of `D(s)` isn't, consider calling `N / D` instead of `N * inv(D)")
438439
end
439440
return basetype(ST)(A - B*Dinv*C, B*Dinv, -n*Dinv*C, n*Dinv, sys.timeevol)
440441
end

0 commit comments

Comments
 (0)