Returns the roots of the polynomial 'expr' with indeterminate 'var'. This function uses numpy for calculation of numeric roots. :note: See: https://docs.scipy.org/doc/numpy/reference/generated/numpy.polynomial.polynomial.polyroots.html :param expr: Univariate function. :
(expr, var)
| 196 | return rts |
| 197 | |
| 198 | def _numRoots(expr, var): |
| 199 | """ |
| 200 | Returns the roots of the polynomial 'expr' with indeterminate 'var'. |
| 201 | |
| 202 | This function uses numpy for calculation of numeric roots. |
| 203 | |
| 204 | :note: |
| 205 | |
| 206 | See: https://docs.scipy.org/doc/numpy/reference/generated/numpy.polynomial.polynomial.polyroots.html |
| 207 | |
| 208 | :param expr: Univariate function. |
| 209 | :type expr: sympy.Expr |
| 210 | |
| 211 | :param var: Indeterminate of 'expr'. |
| 212 | :type var: sympy.Symbol |
| 213 | """ |
| 214 | rts = [] |
| 215 | try: |
| 216 | pol = sp.Poly(expr, var) |
| 217 | coeffs = pol.all_coeffs() |
| 218 | coeffs = [float(sp.N(coeffs[i]/sp.Poly.LC(pol))) for i in range(len(coeffs))] |
| 219 | except sp.PolynomialError: |
| 220 | print('ERROR: could not write expression as polynomial:\n\n') |
| 221 | print('Try different setting for setting: ini.numer and/or ini.denom;') |
| 222 | print('current settings: ', ini.numer, ini.denom, 'respectively.') |
| 223 | coeffs = [] |
| 224 | coeffs = np.array(coeffs[::-1], dtype=float) # Reversed list to array |
| 225 | try: |
| 226 | p = Polynomial(coeffs) |
| 227 | rts = np.flip(p.roots()) |
| 228 | except BaseException: |
| 229 | exc_type, value, exc_traceback = sys.exc_info() |
| 230 | print('\n', value) |
| 231 | print("Error: cannot determine the roots of:", str(p)) |
| 232 | return rts |
| 233 | |
| 234 | def coeffsTransfer(rational, var=ini.laplace, method='lowest'): |
| 235 | """ |
no outgoing calls
no test coverage detected