@@ -164,12 +164,10 @@ def stability_margins(sysdata, returnall=False, epsw=0.0):
164164 # test (imaginary part of tf) == 0, for phase crossover/gain margins
165165 test_w_180 = np .polyadd (np .polymul (inum , rden ), np .polymul (rnum , - iden ))
166166 w_180 = np .roots (test_w_180 )
167- #print ('1:w_180', w_180)
168167
169168 # first remove imaginary and negative frequencies, epsw removes the
170169 # "0" frequency for type-2 systems
171170 w_180 = np .real (w_180 [(np .imag (w_180 ) == 0 ) * (w_180 >= epsw )])
172- #print ('2:w_180', w_180)
173171
174172 # evaluate response at remaining frequencies, to test for phase 180 vs 0
175173 with np .errstate (all = 'ignore' ):
@@ -182,7 +180,6 @@ def stability_margins(sysdata, returnall=False, epsw=0.0):
182180
183181 # and sort
184182 w_180 .sort ()
185- #print ('3:w_180', w_180)
186183
187184 # test magnitude is 1 for gain crossover/phase margins
188185 test_wc = np .polysub (np .polyadd (_polysqr (rnum ), _polysqr (inum )),
@@ -203,32 +200,28 @@ def stability_margins(sysdata, returnall=False, epsw=0.0):
203200
204201 # find the solutions, for positive omega, and only real ones
205202 wstab = np .roots (test_wstab )
206- #print('wstabr', wstab)
207203 wstab = np .real (wstab [(np .imag (wstab ) == 0 ) *
208204 (np .real (wstab ) >= 0 )])
209- #print('wstab', wstab)
210205
211206 # and find the value of the 2nd derivative there, needs to be positive
212207 wstabplus = np .polyval (np .polyder (test_wstab ), wstab )
213- #print('wstabplus', wstabplus)
214208 wstab = np .real (wstab [(np .imag (wstab ) == 0 ) * (wstab > epsw ) *
215209 (wstabplus > 0. )])
216- #print('wstab', wstab)
217210 wstab .sort ()
218211
219212 else :
220213 # a bit coarse, have the interpolated frd evaluated again
221214 def mod (w ):
222215 """to give the function to calculate |G(jw)| = 1"""
223- return np .abs (sys .evalfr (w )[0 ][0 ]) - 1
216+ return np .abs (sys ._evalfr (w )[0 ][0 ]) - 1
224217
225218 def arg (w ):
226219 """function to calculate the phase angle at -180 deg"""
227- return np .angle (- sys .evalfr (w )[0 ][0 ])
220+ return np .angle (- sys ._evalfr (w )[0 ][0 ])
228221
229222 def dstab (w ):
230223 """function to calculate the distance from -1 point"""
231- return np .abs (sys .evalfr (w )[0 ][0 ] + 1. )
224+ return np .abs (sys ._evalfr (w )[0 ][0 ] + 1. )
232225
233226 # Find all crossings, note that this depends on omega having
234227 # a correct range
@@ -239,37 +232,28 @@ def dstab(w):
239232
240233 # find the phase crossings ang(H(jw) == -180
241234 widx = np .where (np .diff (np .sign (arg (sys .omega ))))[0 ]
242- #print('widx (180)', widx, sys.omega[widx])
243- #print('x', sys.evalfr(sys.omega[widx])[0][0])
244- widx = widx [np .real (sys .evalfr (sys .omega [widx ])[0 ][0 ]) <= 0 ]
245- #print('widx (180,2)', widx)
235+ widx = widx [np .real (sys ._evalfr (sys .omega [widx ])[0 ][0 ]) <= 0 ]
246236 w_180 = np .array (
247237 [ sp .optimize .brentq (arg , sys .omega [i ], sys .omega [i + 1 ])
248238 for i in widx if i + 1 < len (sys .omega ) ])
249- #print('x', sys.evalfr(w_180)[0][0])
250- #print('w_180', w_180)
251239
252240 # find all stab margins?
253241 widx = np .where (np .diff (np .sign (np .diff (dstab (sys .omega )))))[0 ]
254- #print('widx', widx)
255- #print('wstabx', sys.omega[widx])
256242 wstab = np .array ([ sp .optimize .minimize_scalar (
257243 dstab , bracket = (sys .omega [i ], sys .omega [i + 1 ])).x
258244 for i in widx if i + 1 < len (sys .omega ) and
259245 np .diff (np .diff (dstab (sys .omega [i - 1 :i + 2 ])))[0 ] > 0 ])
260- #print('wstabf0', wstab)
261246 wstab = wstab [(wstab >= sys .omega [0 ]) *
262247 (wstab <= sys .omega [- 1 ])]
263- #print ('wstabf', wstab)
264248
265249
266250 # margins, as iterables, converted frdata and xferfcn calculations to
267251 # vector for this
268252 with np .errstate (all = 'ignore' ):
269- gain_w_180 = np .abs (sys .evalfr (w_180 )[0 ][0 ])
253+ gain_w_180 = np .abs (sys ._evalfr (w_180 )[0 ][0 ])
270254 GM = 1.0 / gain_w_180
271- SM = np .abs (sys .evalfr (wstab )[0 ][0 ]+ 1 )
272- PM = np .remainder (np .angle (sys .evalfr (wc )[0 ][0 ], deg = True ), 360.0 ) - 180.0
255+ SM = np .abs (sys ._evalfr (wstab )[0 ][0 ]+ 1 )
256+ PM = np .remainder (np .angle (sys ._evalfr (wc )[0 ][0 ], deg = True ), 360.0 ) - 180.0
273257
274258 if returnall :
275259 return GM , PM , SM , w_180 , wc , wstab
@@ -331,7 +315,7 @@ def phase_crossover_frequencies(sys):
331315
332316 # using real() to avoid rounding errors and results like 1+0j
333317 # it would be nice to have a vectorized version of self.evalfr here
334- gain = np .real (np .asarray ([tf .evalfr (f )[0 ][0 ] for f in realposfreq ]))
318+ gain = np .real (np .asarray ([tf ._evalfr (f )[0 ][0 ] for f in realposfreq ]))
335319
336320 return realposfreq , gain
337321
0 commit comments