@@ -121,11 +121,11 @@ def bode_plot(syslist, omega=None,
121121
122122 Returns
123123 -------
124- mag : array ( list if len(syslist) > 1)
124+ mag : ndarray (or list of ndarray if len(syslist) > 1) )
125125 magnitude
126- phase : array ( list if len(syslist) > 1)
126+ phase : ndarray (or list of ndarray if len(syslist) > 1) )
127127 phase in radians
128- omega : array ( list if len(syslist) > 1)
128+ omega : ndarray (or list of ndarray if len(syslist) > 1) )
129129 frequency in rad/sec
130130
131131 Other Parameters
@@ -190,8 +190,8 @@ def bode_plot(syslist, omega=None,
190190 initial_phase = config ._get_param (
191191 'bode' , 'initial_phase' , kwargs , None , pop = True )
192192
193- # If argument was a singleton, turn it into a list
194- if not getattr (syslist , '__iter__' , False ):
193+ # If argument was a singleton, turn it into a tuple
194+ if not hasattr (syslist , '__iter__' ):
195195 syslist = (syslist ,)
196196
197197 if omega is None :
@@ -542,11 +542,11 @@ def nyquist_plot(syslist, omega=None, plot=True, omega_limits=None,
542542
543543 Returns
544544 -------
545- real : ndarray
545+ real : ndarray (or list of ndarray if len(syslist) > 1))
546546 real part of the frequency response array
547- imag : ndarray
547+ imag : ndarray (or list of ndarray if len(syslist) > 1))
548548 imaginary part of the frequency response array
549- freq : ndarray
549+ omega : ndarray (or list of ndarray if len(syslist) > 1))
550550 frequencies in rad/s
551551
552552 Examples
@@ -572,7 +572,7 @@ def nyquist_plot(syslist, omega=None, plot=True, omega_limits=None,
572572 label_freq = kwargs .pop ('labelFreq' )
573573
574574 # If argument was a singleton, turn it into a list
575- if not getattr (syslist , '__iter__' , False ):
575+ if not hasattr (syslist , '__iter__' ):
576576 syslist = (syslist ,)
577577
578578 # Select a default range if none is provided
@@ -593,37 +593,40 @@ def nyquist_plot(syslist, omega=None, plot=True, omega_limits=None,
593593 np .log10 (omega_limits [1 ]), num = num ,
594594 endpoint = True )
595595
596-
596+ xs , ys , omegas = [], [], []
597597 for sys in syslist :
598- if not sys .issiso ():
599- # TODO: Add MIMO nyquist plots.
600- raise ControlMIMONotImplemented (
601- "Nyquist is currently only implemented for SISO systems." )
602- else :
603- # Get the magnitude and phase of the system
604- mag , phase , omega = sys .frequency_response (omega )
605-
606- # Compute the primary curve
607- x = mag * np .cos (phase )
608- y = mag * np .sin (phase )
609-
610- if plot :
611- # Plot the primary curve and mirror image
612- p = plt .plot (x , y , '-' , color = color , * args , ** kwargs )
613- c = p [0 ].get_color ()
614- ax = plt .gca ()
615- # Plot arrow to indicate Nyquist encirclement orientation
616- ax .arrow (x [0 ], y [0 ], (x [1 ]- x [0 ])/ 2 , (y [1 ]- y [0 ])/ 2 , fc = c , ec = c ,
617- head_width = arrowhead_width ,
618- head_length = arrowhead_length )
619-
620- plt .plot (x , - y , '-' , color = c , * args , ** kwargs )
621- ax .arrow (
622- x [- 1 ], - y [- 1 ], (x [- 1 ]- x [- 2 ])/ 2 , (y [- 1 ]- y [- 2 ])/ 2 ,
623- fc = c , ec = c , head_width = arrowhead_width ,
624- head_length = arrowhead_length )
625- # Mark the -1 point
626- plt .plot ([- 1 ], [0 ], 'r+' )
598+ mag , phase , omega = sys .frequency_response (omega )
599+
600+ # Compute the primary curve
601+ x = mag * np .cos (phase )
602+ y = mag * np .sin (phase )
603+
604+ xs .append (x )
605+ ys .append (y )
606+ omegas .append (omega )
607+
608+ if plot :
609+ if not sys .issiso ():
610+ # TODO: Add MIMO nyquist plots.
611+ raise ControlMIMONotImplemented (
612+ "Nyquist plot currently supports SISO systems." )
613+
614+ # Plot the primary curve and mirror image
615+ p = plt .plot (x , y , '-' , color = color , * args , ** kwargs )
616+ c = p [0 ].get_color ()
617+ ax = plt .gca ()
618+ # Plot arrow to indicate Nyquist encirclement orientation
619+ ax .arrow (x [0 ], y [0 ], (x [1 ]- x [0 ])/ 2 , (y [1 ]- y [0 ])/ 2 , fc = c , ec = c ,
620+ head_width = arrowhead_width ,
621+ head_length = arrowhead_length )
622+
623+ plt .plot (x , - y , '-' , color = c , * args , ** kwargs )
624+ ax .arrow (
625+ x [- 1 ], - y [- 1 ], (x [- 1 ]- x [- 2 ])/ 2 , (y [- 1 ]- y [- 2 ])/ 2 ,
626+ fc = c , ec = c , head_width = arrowhead_width ,
627+ head_length = arrowhead_length )
628+ # Mark the -1 point
629+ plt .plot ([- 1 ], [0 ], 'r+' )
627630
628631 # Label the frequencies of the points
629632 if label_freq :
@@ -655,8 +658,10 @@ def nyquist_plot(syslist, omega=None, plot=True, omega_limits=None,
655658 ax .set_ylabel ("Imaginary axis" )
656659 ax .grid (color = "lightgray" )
657660
658- return x , y , omega
659-
661+ if len (syslist ) == 1 :
662+ return xs [0 ], ys [0 ], omegas [0 ]
663+ else :
664+ return xs , ys , omegas
660665
661666#
662667# Gang of Four plot
0 commit comments