37
37
38
38
import warnings
39
39
import numpy as np
40
- from numpy import shape , size , copy , zeros , eye , finfo , inexact , atleast_2d
40
+ from numpy import copy , eye , dot , finfo , inexact , atleast_2d
41
41
42
42
import scipy as sp
43
- from scipy .linalg import eigvals , solve_discrete_are , solve
43
+ from scipy .linalg import eigvals , solve
44
44
45
- from .exception import ControlSlycot , ControlArgument , slycot_check
45
+ from .exception import ControlSlycot , ControlArgument , ControlDimension , \
46
+ slycot_check
46
47
from .statesp import _ssmatrix
47
48
48
49
# Make sure we have access to the right slycot routines
@@ -136,9 +137,9 @@ def lyap(A, Q, C=None, E=None, method=None):
136
137
method = _slycot_or_scipy (method )
137
138
if method == 'slycot' :
138
139
if sb03md is None :
139
- raise ControlSlycot ("can 't find slycot module 'sb03md'" )
140
+ raise ControlSlycot ("Can 't find slycot module 'sb03md'" )
140
141
if sb04md is None :
141
- raise ControlSlycot ("can 't find slycot module 'sb04md'" )
142
+ raise ControlSlycot ("Can 't find slycot module 'sb04md'" )
142
143
143
144
# Reshape input arrays
144
145
A = np .array (A , ndmin = 2 )
@@ -196,7 +197,7 @@ def lyap(A, Q, C=None, E=None, method=None):
196
197
from slycot import sg03ad
197
198
198
199
except ImportError :
199
- raise ControlSlycot ("can 't find slycot module 'sg03ad'" )
200
+ raise ControlSlycot ("Can 't find slycot module 'sg03ad'" )
200
201
201
202
# Solve the generalized Lyapunov equation by calling Slycot
202
203
# function sg03ad
@@ -265,11 +266,11 @@ def dlyap(A, Q, C=None, E=None, method=None):
265
266
if method == 'slycot' :
266
267
# Make sure we have access to the right slycot routines
267
268
if sb03md is None :
268
- raise ControlSlycot ("can 't find slycot module 'sb03md'" )
269
+ raise ControlSlycot ("Can 't find slycot module 'sb03md'" )
269
270
if sb04qd is None :
270
- raise ControlSlycot ("can 't find slycot module 'sb04qd'" )
271
+ raise ControlSlycot ("Can 't find slycot module 'sb04qd'" )
271
272
if sg03ad is None :
272
- raise ControlSlycot ("can 't find slycot module 'sg03ad'" )
273
+ raise ControlSlycot ("Can 't find slycot module 'sg03ad'" )
273
274
274
275
# Reshape input arrays
275
276
A = np .array (A , ndmin = 2 )
@@ -399,18 +400,18 @@ def care(A, B, Q, R=None, S=None, E=None, stabilizing=True, method=None):
399
400
try :
400
401
from slycot import sb02md
401
402
except ImportError :
402
- raise ControlSlycot ("can 't find slycot module 'sb02md'" )
403
+ raise ControlSlycot ("Can 't find slycot module 'sb02md'" )
403
404
404
405
try :
405
406
from slycot import sb02mt
406
407
except ImportError :
407
- raise ControlSlycot ("can 't find slycot module 'sb02mt'" )
408
+ raise ControlSlycot ("Can 't find slycot module 'sb02mt'" )
408
409
409
410
# Make sure we can find the required slycot routine
410
411
try :
411
412
from slycot import sg02ad
412
413
except ImportError :
413
- raise ControlSlycot ("can 't find slycot module 'sg02ad'" )
414
+ raise ControlSlycot ("Can 't find slycot module 'sg02ad'" )
414
415
415
416
# Reshape input arrays
416
417
A = np .array (A , ndmin = 2 )
@@ -500,10 +501,7 @@ def care(A, B, Q, R=None, S=None, E=None, stabilizing=True, method=None):
500
501
'R' , n , m , 0 , A , E , B , Q , R , S )
501
502
502
503
# Calculate the closed-loop eigenvalues L
503
- L = zeros (n )
504
- L .dtype = 'complex64'
505
- for i in range (n ):
506
- L [i ] = (alfar [i ] + alfai [i ]* 1j ) / beta [i ]
504
+ L = np .array ([(alfar [i ] + alfai [i ]* 1j ) / beta [i ] for i in range (n )])
507
505
508
506
# Calculate the gain matrix G
509
507
G = solve (R_b , B_b .T @ X @ E_b + S_b .T )
@@ -598,7 +596,7 @@ def dare(A, B, Q, R, S=None, E=None, stabilizing=True, method=None):
598
596
599
597
Rmat = _ssmatrix (R )
600
598
Qmat = _ssmatrix (Q )
601
- X = solve_discrete_are (A , B , Qmat , Rmat , e = E , s = S )
599
+ X = sp . linalg . solve_discrete_are (A , B , Qmat , Rmat , e = E , s = S )
602
600
if S is None :
603
601
G = solve (B .T @ X @ B + Rmat , B .T @ X @ A )
604
602
else :
@@ -616,18 +614,18 @@ def _dare_slycot(A, B, Q, R, S=None, E=None, stabilizing=True):
616
614
try :
617
615
from slycot import sb02md
618
616
except ImportError :
619
- raise ControlSlycot ("can 't find slycot module 'sb02md'" )
617
+ raise ControlSlycot ("Can 't find slycot module 'sb02md'" )
620
618
621
619
try :
622
620
from slycot import sb02mt
623
621
except ImportError :
624
- raise ControlSlycot ("can 't find slycot module 'sb02mt'" )
622
+ raise ControlSlycot ("Can 't find slycot module 'sb02mt'" )
625
623
626
624
# Make sure we can find the required slycot routine
627
625
try :
628
626
from slycot import sg02ad
629
627
except ImportError :
630
- raise ControlSlycot ("can 't find slycot module 'sg02ad'" )
628
+ raise ControlSlycot ("Can 't find slycot module 'sg02ad'" )
631
629
632
630
# Reshape input arrays
633
631
A = np .array (A , ndmin = 2 )
@@ -667,10 +665,8 @@ def _dare_slycot(A, B, Q, R, S=None, E=None, stabilizing=True):
667
665
sg02ad ('D' , 'B' , 'N' , 'U' , 'N' , 'N' , sort ,
668
666
'R' , n , m , 0 , A , E , B , Q , R , S )
669
667
670
- L = zeros (n )
671
- L .dtype = 'complex64'
672
- for i in range (n ):
673
- L [i ] = (alfar [i ] + alfai [i ]* 1j )/ beta [i ]
668
+ # Calculate the closed-loop eigenvalues L
669
+ L = np .array ([(alfar [i ] + alfai [i ]* 1j ) / beta [i ] for i in range (n )])
674
670
675
671
# Calculate the gain matrix G
676
672
G = solve (B_b .T @ X @ B_b + R_b , B_b .T @ X @ A_b + S_b .T )
@@ -687,19 +683,19 @@ def _slycot_or_scipy(method):
687
683
elif method == 'scipy' or (method is None and not slycot_check ()):
688
684
return 'scipy'
689
685
else :
690
- raise ValueError ("unknown method %s" % method )
686
+ raise ValueError ("Unknown method %s" % method )
691
687
692
688
693
689
# Utility function to check matrix dimensions
694
690
def _check_shape (name , M , n , m , square = False , symmetric = False ):
695
691
if square and M .shape [0 ] != M .shape [1 ]:
696
- raise ControlArgument ("%s must be a square matrix" % name )
692
+ raise ControlDimension ("%s must be a square matrix" % name )
697
693
698
694
if symmetric and not _is_symmetric (M ):
699
695
raise ControlArgument ("%s must be a symmetric matrix" % name )
700
696
701
697
if M .shape [0 ] != n or M .shape [1 ] != m :
702
- raise ControlArgument ("Incompatible dimensions of %s matrix" % name )
698
+ raise ControlDimension ("Incompatible dimensions of %s matrix" % name )
703
699
704
700
705
701
# Utility function to check if a matrix is symmetric
0 commit comments