Skip to content

Commit 33c59a8

Browse files
committed
Change DICO parameter to boolean dtime. Update tests as well.
1 parent cfe18ea commit 33c59a8

2 files changed

Lines changed: 22 additions & 15 deletions

File tree

control/statefbk.py

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -113,9 +113,9 @@ def place(A, B, p):
113113
return K
114114

115115

116-
def place_varga(A, B, p, DICO='C', alpha=None):
116+
def place_varga(A, B, p, dtime=False, alpha=None):
117117
"""Place closed loop eigenvalues
118-
K = place_varga(A, B, p, DICO='C', alpha=None)
118+
K = place_varga(A, B, p, dtime=False, alpha=None)
119119
120120
Required Parameters
121121
----------
@@ -128,8 +128,8 @@ def place_varga(A, B, p, DICO='C', alpha=None):
128128
129129
Optional Parameters
130130
---------------
131-
DICO : 'C' for continuous time pole placement or 'D' for discrete time.
132-
The default is DICO='C'.
131+
dtime: False for continuous time pole placement or True for discrete time.
132+
The default is dtime=False.
133133
alpha: double scalar
134134
If DICO='C', then place_varga will leave the eigenvalues with real
135135
real part less than alpha untouched.
@@ -160,7 +160,7 @@ def place_varga(A, B, p, DICO='C', alpha=None):
160160
--------
161161
>>> A = [[-1, -1], [0, 1]]
162162
>>> B = [[0], [1]]
163-
>>> K = place(A, B, [-2, -5])
163+
>>> K = place_varga(A, B, [-2, -5])
164164
165165
See Also:
166166
--------
@@ -184,25 +184,32 @@ def place_varga(A, B, p, DICO='C', alpha=None):
184184
system_eigs = np.linalg.eig(A_mat)[0]
185185
placed_eigs = np.array(p)
186186

187+
# Need a character parameter for SB01BD
188+
if dtime:
189+
DICO = 'D'
190+
else:
191+
DICO = 'C'
192+
187193
if alpha is None:
188194
# SB01BD ignores eigenvalues with real part less than alpha
189195
# (if DICO='C') or with modulus less than alpha
190196
# (if DICO = 'D').
191-
if DICO == 'C':
197+
if dtime:
198+
# For discrete time, slycot only cares about modulus, so just make
199+
# alpha the smallest it can be.
200+
alpha = 0.0
201+
else:
192202
# Choosing alpha=min_eig is insufficient and can lead to an
193203
# error or not having all the eigenvalues placed that we wanted.
194204
# Evidently, what python thinks are the eigs is not precisely
195205
# the same as what slicot thinks are the eigs. So we need some
196206
# numerical breathing room. The following is pretty heuristic,
197207
# but does the trick
198208
alpha = -2*abs(min(system_eigs.real))
199-
elif DICO == 'D':
200-
# For discrete time, slycot only cares about modulus, so just make
201-
# alpha the smallest it can be.
202-
alpha = 0.0
203-
elif DICO == 'D' and alpha < 0.0:
209+
elif dtime and alpha < 0.0:
204210
raise ValueError("Need alpha > 0 when DICO='D'")
205211

212+
206213
# Call SLICOT routine to place the eigenvalues
207214
A_z,w,nfp,nap,nup,F,Z = \
208215
sb01bd(B_mat.shape[0], B_mat.shape[1], len(placed_eigs), alpha,

control/tests/statefbk_test.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ def testPlace(self):
188188
@unittest.skipIf(not slycot_check(), "slycot not installed")
189189
def testPlace_varga_continuous(self):
190190
"""
191-
Check that we can place eigenvalues for DICO='C'
191+
Check that we can place eigenvalues for dtime=False
192192
"""
193193
A = np.array([[1., -2.], [3., -4.]])
194194
B = np.array([[5.], [7.]])
@@ -243,13 +243,13 @@ def testPlace_varga_continuous_partial_eigs(self):
243243
@unittest.skipIf(not slycot_check(), "slycot not installed")
244244
def testPlace_varga_discrete(self):
245245
"""
246-
Check that we can place poles using DICO='D' (discrete time)
246+
Check that we can place poles using dtime=True (discrete time)
247247
"""
248248
A = np.array([[1., 0], [0, 0.5]])
249249
B = np.array([[5.], [7.]])
250250

251251
P = np.array([0.5, 0.5])
252-
K = place_varga(A, B, P, DICO='D')
252+
K = place_varga(A, B, P, dtime=True)
253253
P_placed = np.linalg.eigvals(A - B.dot(K))
254254
# No guarantee of the ordering, so sort them
255255
P.sort()
@@ -269,7 +269,7 @@ def testPlace_varga_discrete_partial_eigs(self):
269269
P = np.array([0.2, 0.6])
270270
P_expected = np.array([0.5, 0.6])
271271
alpha = 0.51
272-
K = place_varga(A, B, P, DICO='D', alpha=alpha)
272+
K = place_varga(A, B, P, dtime=True, alpha=alpha)
273273
P_placed = np.linalg.eigvals(A - B.dot(K))
274274
P_expected.sort()
275275
P_placed.sort()

0 commit comments

Comments
 (0)