Skip to content

Commit 020f64c

Browse files
committed
Check eigenvalues' real part using NumPy
Faster than converting to a pure Python list.
1 parent f75f9d4 commit 020f64c

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

control/modelsimp.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ def modred(sys, ELIM, method='matchdc'):
149149

150150

151151
#Check system is stable
152-
if any(e.real >= 0.0 for e in np.linalg.eigvals(sys.A)):
152+
if np.any(np.linalg.eigvals(sys.A).real >= 0.0):
153153
raise ValueError("Oops, the system is unstable!")
154154

155155
ELIM = np.sort(ELIM)
@@ -251,7 +251,7 @@ def balred(sys, orders, method='truncate'):
251251
dico = 'C'
252252

253253
#Check system is stable
254-
if any(e.real >= 0.0 for e in np.linalg.eigvals(sys.A)):
254+
if np.any(np.linalg.eigvals(sys.A).real >= 0.0):
255255
raise ValueError("Oops, the system is unstable!")
256256

257257
if method=='matchdc':

control/statefbk.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,7 @@ def gram(sys,type):
355355

356356
#TODO: Check system is stable, perhaps a utility in ctrlutil.py
357357
# or a method of the StateSpace class?
358-
if any(e.real >= 0.0 for e in np.linalg.eigvals(sys.A)):
358+
if np.any(np.linalg.eigvals(sys.A).real >= 0.0):
359359
raise ValueError("Oops, the system is unstable!")
360360

361361
if type=='c':

0 commit comments

Comments
 (0)