SymPy Cannot Solve 4th Order Polynomial Equation

I have a 4th order polynomial equation and I need to find all the roots. A simple example:

from sympy import (Symbol,solve,I) a=4+5*I; b=3+7*I; c=12-56*I; d=33+56*I; e=345-67*I; x=Symbol('x') eq=a*x**4 + b*x**3 + c*x**2 + d*x +e solve(eq,x) 

If a, b, c, d, e are purely real, then it works fine. But in my case, they are all complex numbers. Then I got a call:

 PolynomialError: 'cannot return general quartic solution' 

I see a similar problem and implement the fix: Description of the problem . Fix the problem

but it really doesn’t help. There is some strange problem, since now the call (as changed in the fix):

 PolynomialError: Cannot determine if `-((12 - 56*I)/(4 + 5*I) - 3*(3 + 7*I)**2/(8*(4 + 5*I)**2))**2/12 + (3 + 7*I)*((33 + 56*I)/(4*(4 + 5*I)) + (3 + 7*I)*(3*(3 + 7*I)**2/(256*(4 + 5*I)**2) - (12 - 56*I)/(16*(4 + 5*I)))/(4 + 5*I))/(4 + 5*I) - (345 - 67*I)/(4 + 5*I)` is nonzero. 

But to determine whether the expression above is nonzero is the simplest, so I don’t know where the problem is.

+5
source share
2 answers

Upgrade to the latest version of SymPy, which supports custom apartment solutions.

+1
source

If you want a more flexible solution, you can solve for x using a binary search, with something like the following:

 def maybeRightX(maybeX, polys): sum = 0 for i in range(len(polys)): sum += polys[i]*(maybeX ** i) return sum def solve(y, polys): lo = 0 hi = y while lo <= hi: mid = (lo + hi)//2 if (maybeRightX(mid, polys)) < y: lo = mid + 1 else: hi = mid - 1 return (hi + 1) 
0
source

Source: https://habr.com/ru/post/1212805/


All Articles