Skip to content

Commit aad5502

Browse files
committed
allow state elimination on unstable systems with warning
1 parent 57b5307 commit aad5502

2 files changed

Lines changed: 14 additions & 10 deletions

File tree

control/canonical.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ def similarity_transform(xsys, T, timescale=1, inverse=False):
205205
timescale : float, optional
206206
If present, also rescale the time unit to tau = timescale * t
207207
inverse : bool, optional
208-
If True (default), transform so z = T x. If False, transform
208+
If False (default), transform so z = T x. If True, transform
209209
so x = T z.
210210
211211
Returns

control/modelsimp.py

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ def hankel_singular_values(sys):
108108
return hsv[::-1]
109109

110110

111-
def model_reduction(sys, ELIM, method='matchdc'):
111+
def model_reduction(sys, ELIM, method='matchdc', warn_unstable=True):
112112
"""Model reduction by state elimination.
113113
114114
Model reduction of `sys` by eliminating the states in `ELIM` using a given
@@ -122,7 +122,9 @@ def model_reduction(sys, ELIM, method='matchdc'):
122122
Vector of states to eliminate.
123123
method : string
124124
Method of removing states in `ELIM`: either 'truncate' or
125-
'matchdc'.
125+
'matchdc' (default).
126+
warn_unstable: bool, option
127+
If `False`, don't warn if system is unstable.
126128
127129
Returns
128130
-------
@@ -132,12 +134,14 @@ def model_reduction(sys, ELIM, method='matchdc'):
132134
Raises
133135
------
134136
ValueError
135-
Raised under the following conditions:
137+
If `method` is not either ``'matchdc'`` or ``'truncate'``.
138+
NotImplementedError
139+
If `sys` is a discrete time system.
136140
137-
* if `method` is not either ``'matchdc'`` or ``'truncate'``
138-
139-
* if eigenvalues of `sys.A` are not all in left half plane
140-
(`sys` must be stable)
141+
Warns
142+
-----
143+
UserWarning
144+
If eigenvalues of `sys.A` are not all stable.
141145
142146
Examples
143147
--------
@@ -162,8 +166,8 @@ def model_reduction(sys, ELIM, method='matchdc'):
162166
raise NotImplementedError("Function not implemented in discrete time")
163167

164168
# Check system is stable
165-
if np.any(np.linalg.eigvals(sys.A).real >= 0.0):
166-
raise ValueError("Oops, the system is unstable!")
169+
if np.any(np.linalg.eigvals(sys.A).real >= 0.0) and warn_unstable:
170+
warnings.warn("System is unstable; reduction may be meaningless")
167171

168172
ELIM = np.sort(ELIM)
169173
# Create list of elements not to eliminate (NELIM)

0 commit comments

Comments
 (0)