Dear friends,
I currently ran into a math-issue when trying to get the analytical roots of a polynomial of order 4.
What I want to solve is:
The solution shall run on a microcontroller with dynamically changing parameters [a,d,e]. All parameters are real. I am searching for the real results, imaginary solutions are to be prevented. When applying Matlab symbolic, The parameters [a,d,e] are simplified and represent longer sub-terms. In accordance to the article Wiki: quartic function, I will receive quite a long solution, that is futile to reproduce here. I used the following short code to generate it: syms x a d e
y= a*x^4+d*x+e
sol=solve(y==0,x,'MaxDegree',4,'ReturnConditions',true)
To check the solution, I tested it on an easier sub-problem: When d=0 is chosen follows:
When chosing a>0, e<0 this clearly yields some real results, besides the imaginary ones. Now the problem: the above given long solution cannot reproduce this result. Even if I force assumptions that should solve it, follows something that does not look equal:
syms x a d e
assume(a>=0)
assume(d>=0)
assume(e<=0)
y= a*x^4+d*x+e
sol=solve(y==0,x,'MaxDegree',4,'ReturnConditions',true)
testresult=simplify(subs(sol.x, d,0))
latex(testresult)
However, if I change the equation before solving the quartic function, the solution of it looks as on paper:
y= a*x^4+e
assume(a>=0)
assume(d>=0)
assume(e<=0)
sol=solve(y==0,x,'MaxDegree',4,'ReturnConditions',true)
testresult2=sol.x
latex(testresult2)
Numerical testing via inserting numbers in the two solutions according to the assumptions a>0, e<0 confirms the difference of the results. Chosing a=1 and e=-2 yields:
1) the general solution of the quartic polynomial (inserting d=0 after solving the quartic polynomial):
vpares1=vpa(subs(testresult,{a,e},{1,-2}))
vpares1 =
0
0
0
0
2) the solution of the simplified quartic polynomial (inserting d=0 before solving):
vpares2=vpa(subs(testresult2,{a,e},{1,-2}))
vpares2 =
1.1892071150027210667174999705605
-1.1892071150027210667174999705605
-1.1892071150027210667174999705605i
1.1892071150027210667174999705605i
Visibly, the trivial solution is not permissible given the solution of case 2). Interestingly, if the requirement is switched from {a>0,e<0} to {a<0, e>0} the solutions match again.
Similar difficulties have shown, when I hand-coded the general solution from the mentioned Wikipedia article. As I need the solution for
, I now have trust-issues with the long solution. Therefore, I ask for your help or comment, why the "general solution" does not end in the same result as the simplified problem. Thank you in advance for your help!