Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 19 additions & 5 deletions control/statesp.py
Original file line number Diff line number Diff line change
Expand Up @@ -851,7 +851,7 @@ def slycot_laub(self, x):
# transformed state matrices, at, bt, ct.

# Start at the second frequency, already have the first.
for kk, x_kk in enumerate(x_arr[1:len(x_arr)]):
for kk, x_kk in enumerate(x_arr[1:]):
result = tb05ad(n, m, p, x_kk, at, bt, ct, job='NH')
# When job='NH', result = (g_i, hinvb, info)

Expand Down Expand Up @@ -885,15 +885,29 @@ def horner(self, x, warn_infinite=True):
Attempts to use Laub's method from Slycot library, with a
fall-back to python code.
"""
# Make sure the argument is a 1D array of complex numbers
x_arr = np.atleast_1d(x).astype(complex, copy=False)

# return fast on systems with 0 or 1 state
if not config.defaults['statesp.use_numpy_matrix']:
if self.nstates == 0:
return self.D[:, :, np.newaxis] \
* np.ones_like(x_arr, dtype=complex)
if self.nstates == 1:
with np.errstate(divide='ignore', invalid='ignore'):
out = self.C[:, :, np.newaxis] \
/ (x_arr - self.A[0, 0]) \
* self.B[:, :, np.newaxis] \
+ self.D[:, :, np.newaxis]
out[np.isnan(out)] = complex(np.inf, np.nan)
return out

try:
out = self.slycot_laub(x)
out = self.slycot_laub(x_arr)
except (ImportError, Exception):
# Fall back because either Slycot unavailable or cannot handle
# certain cases.

# Make sure the argument is a 1D array of complex numbers
x_arr = np.atleast_1d(x).astype(complex, copy=False)

# Make sure that we are operating on a simple list
if len(x_arr.shape) > 1:
raise ValueError("input list must be 1D")
Expand Down