@@ -463,10 +463,7 @@ def __call__(self, x, squeeze=True):
463463
464464 """
465465 # Use Slycot if available
466- try :
467- out = self .slycot_horner (x )
468- except ImportError : # Slycot unavailable. use built-in horner.
469- out = self .horner (x )
466+ out = self .horner (x )
470467 if not hasattr (x , '__len__' ):
471468 # received a scalar x, squeeze down the array along last dim
472469 out = np .squeeze (out , axis = 2 )
@@ -526,33 +523,45 @@ def slycot_horner(self, s):
526523 out [:, :, kk + 1 ] = result [0 ] + self .D
527524 return out
528525
529- def horner (self , s ):
530- """Evaluate system's transfer function at complex frequencies s
531- using Horner's method.
526+ def horner (self , x ):
527+ """Evaluate system's transfer function at complex frequencies x
528+ using Horner's method.
532529
530+ Evaluates sys(x) where `x` is `s` for continuous-time systems and `z`
531+ for discrete-time systems.
532+
533533 Expects inputs and outputs to be formatted correctly. Use __call__
534534 for a more user-friendly interface.
535535
536536 Parameters
537537 ----------
538- s : array_like
538+ x : array_like
539539 Complex frequencies
540540
541541 Returns
542542 -------
543543 output : (outputs, inputs, len(s)) complex ndarray
544544 Frequency response
545+
546+ Notes
547+ -----
548+ Attempts to use Slycot library, with a fall-back to python code.
545549 """
546- s_arr = np .array (s , ndmin = 1 ) # force to be an array
547- # Preallocate
548- out = empty ((self .outputs , self .inputs , len (s_arr )), dtype = complex )
549-
550- #TODO: can this be vectorized?
551- for idx , s_idx in enumerate (s_arr ):
552- out [:,:,idx ] = \
553- np .dot (self .C ,
554- solve (s_idx * eye (self .states ) - self .A , self .B )) \
555- + self .D
550+ try :
551+ out = self .slycot_horner (x )
552+ except (ImportError , Exception ):
553+ # Fall back because either Slycot unavailable or cannot handle
554+ # certain cases.
555+ x_arr = np .array (x , ndmin = 1 ) # force to be an array
556+ # Preallocate
557+ out = empty ((self .outputs , self .inputs , len (x_arr )), dtype = complex )
558+
559+ #TODO: can this be vectorized?
560+ for idx , x_idx in enumerate (x_arr ):
561+ out [:,:,idx ] = \
562+ np .dot (self .C ,
563+ solve (x_idx * eye (self .states ) - self .A , self .B )) \
564+ + self .D
556565 return out
557566
558567 def freqresp (self , omega ):
0 commit comments