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

Function coeffsTransfer

SLiCAP/SLiCAPmath.py:234–294  ·  view source on GitHub ↗

Returns a nested list with the coefficients of the variable of the numerator and of the denominator of 'rational'. The coefficients are in ascending order. :param rational: Rational function of the variable. :type rational: sympy.Expr :param variable: Variable of the rati

(rational, var=ini.laplace, method='lowest')

Source from the content-addressed store, hash-verified

232 return rts
233
234def coeffsTransfer(rational, var=ini.laplace, method='lowest'):
235 """
236 Returns a nested list with the coefficients of the variable of the
237 numerator and of the denominator of 'rational'.
238
239 The coefficients are in ascending order.
240
241 :param rational: Rational function of the variable.
242 :type rational: sympy.Expr
243
244 :param variable: Variable of the rational function
245 :type variable: sympy.Symbol
246
247 :param method: Normalization method:
248
249 - "highest": the coefficients of the highest order of
250 <variable> of the denominator will be noramalized to unity.
251 - "lowest": the coefficients of the lowest order of
252 <variable> of the denominator will be noramalized to unity.
253
254 :type method: str
255
256 :return: Tuple with gain and two lists: [gain, numerCoeffs, denomCoeffs]
257
258 #. gain (*sympy.Expr*): ratio of the nonzero coefficient of the
259 lowest order of the numerator and the coefficient of the
260 nonzero coefficient of the lowest order of the denominator.
261 #. numerCoeffs (*list*): List with all coeffcients of the
262 numerator in ascending order.
263 #. denomCoeffs (*list*): List with all coeffcients of the
264 denominator in ascending order.
265
266 :rtype: tuple
267 """
268 if rational != 0:
269 num, den = rational.as_numer_denom()
270 try:
271 numPoly = sp.Poly(num, var)
272 denPoly = sp.Poly(den, var)
273 if method == 'lowest':
274 gainNum = sp.Poly.EC(numPoly)
275 gainDen = sp.Poly.EC(denPoly)
276 elif method == 'highest':
277 gainNum = sp.Poly.LC(numPoly)
278 gainDen = sp.Poly.LC(denPoly)
279 numCoeffs = numPoly.all_coeffs()
280 denCoeffs = denPoly.all_coeffs()
281 gain = sp.simplify(gainNum/gainDen)
282 numCoeffs = list(
283 reversed([sp.simplify(numCoeffs[i]/gainNum) for i in range(len(numCoeffs))]))
284 denCoeffs = list(
285 reversed([sp.simplify(denCoeffs[i]/gainDen) for i in range(len(denCoeffs))]))
286 except sp.PolynomialError:
287 gain = sp.simplify(rational)
288 numCoeffs = []
289 denCoeffs = []
290 else:
291 gain = 0

Callers 3

normalizeRationalFunction · 0.85
findServoBandwidthFunction · 0.85
equateCoeffsFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected