Skip to content

Commit 72cb23f

Browse files
committed
added warning method when falling back to frd
1 parent 567b4db commit 72cb23f

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

control/margins.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
"""
5252

5353
import math
54+
from warnings import warn
5455
import numpy as np
5556
import scipy as sp
5657
from . import xferfcn
@@ -207,7 +208,7 @@ def fun(wdt):
207208

208209
return z, w
209210

210-
def _numerical_inaccuracy(sys):
211+
def _likely_numerical_inaccuracy(sys):
211212
# crude, conservative check for if
212213
# num(z)*num(1/z) << den(z)*den(1/z) for DT systems
213214
num, den, num_inv_zp, den_inv_zq, p_q, dt = _poly_z_invz(sys)
@@ -334,7 +335,9 @@ def stability_margins(sysdata, returnall=False, epsw=0.0, method='best'):
334335
elif method == 'best':
335336
# convert to FRD if anticipated numerical issues
336337
if isinstance(sys, xferfcn.TransferFunction) and not sys.isctime():
337-
if _numerical_inaccuracy(sys):
338+
if _likely_numerical_inaccuracy(sys):
339+
warn("stability_margins: Falling back to 'frd' method "
340+
"because of chance of numerical inaccuracy in 'poly' method.")
338341
omega_sys = freqplot._default_frequency_range(sys)
339342
omega_sys = omega_sys[omega_sys < np.pi / sys.dt]
340343
sys = frdata.FRD(sys, omega_sys, smooth=True)

0 commit comments

Comments
 (0)