MCPcopy Index your code
hub / github.com/SLiCAP/SLiCAP_python / _cancelPZ

Function _cancelPZ

SLiCAP/SLiCAPmath.py:332–381  ·  view source on GitHub ↗

Cancels poles and zeros that coincide within the displayed accuracy. :note: The display accuracy (number of digits) is defined by ini.disp. :param poles: List with poles (*float*) of a Laplace rational function. :type poles: list :param zeros: List with zeros (*float*) o

(poles, zeros)

Source from the content-addressed store, hash-verified

330 return rational
331
332def _cancelPZ(poles, zeros):
333 """
334 Cancels poles and zeros that coincide within the displayed accuracy.
335
336 :note:
337
338 The display accuracy (number of digits) is defined by ini.disp.
339
340 :param poles: List with poles (*float*) of a Laplace rational function.
341 :type poles: list
342
343 :param zeros: List with zeros (*float*) of a Laplace rational function.
344 :type zeros: list
345
346 :return: Tuple with a list with poles (*float*) and a list with zeros (*float*).
347 :rtype: Tuple with two lists,
348 """
349 newPoles = []
350 newZeros = []
351 # make a copy of the lists of poles and zeros, this one will be modified
352 newPoles = [poles[i] for i in range(len(poles))]
353 newZeros = [zeros[i] for i in range(len(zeros))]
354 for j in range(len(zeros)):
355 for i in range(len(poles)):
356 cancel = False
357 # Check if zero coincides with pole
358 diff = poles[i]-zeros[j]
359 if not diff:
360 cancel = True
361 else:
362 try:
363 syms = len(list(diff.atoms(sp.Symbol)))
364 except:
365 syms = 0
366 if not syms:
367 ssum = poles[i]+zeros[j]
368 erel = abs(0.5*diff/ssum)
369 if erel < 10**(-ini.disp):
370 cancel = True
371 else:
372 cancel = False
373 else:
374 cancel = False
375 if cancel:
376 # if the pole and the zero exist in newPoles and newZeros, respectively
377 # then remove the pair
378 if poles[i] in newPoles and zeros[j] in newZeros:
379 newPoles.remove(poles[i])
380 newZeros.remove(zeros[j])
381 return (newPoles, newZeros)
382
383def _zeroValue(numer, denom, var):
384 """

Callers 2

_doPZFunction · 0.90
findServoBandwidthFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected