0
$\begingroup$

The standard cubic polynomial is: $ax^3+bx^2+cx + d$.

And when I used my function:

piecewiseForm[equation_,solvingVariable_,domain_]:=
Module[{solutions,radicalSolutions,piecewiseList},
solutions = Solve[equation, solvingVariable, domain];
radicalSolutions = ToRadicals[Normal @ x /. solutions];
piecewiseList = Piecewise[Table[
  {First[radicalSolutions[[i]]], Last[radicalSolutions[[i]]]},
  {i, 1, Length[radicalSolutions]}
]];
piecewiseList//TraditionalForm
]

with:

piecewiseForm[a*x^3+b*x^2+c*x+d==0,x,Reals]

I got:

$$\begin{cases} -\frac{b}{3 a}+\frac{\sqrt[3]{-2 b^3+9 a c b-27 a^2 d+\sqrt{4 \left(3 a c-b^2\right)^3+\left(-2 b^3+9 a c b-27 a^2 d\right)^2}}}{3 \sqrt[3]{2} a}-\frac{\sqrt[3]{2} \left(3 a c-b^2\right)}{3 a \sqrt[3]{-2 b^3+9 a c b-27 a^2 d+\sqrt{4 \left(3 a c-b^2\right)^3+\left(-2 b^3+9 a c b-27 a^2 d\right)^2}}} & \left(3 a-\frac{b^2}{c}>0\land c>0\right)\lor \left(3 a-\frac{b^2}{c}>0\land c<0\land \frac{2 b^3}{a^2}-\frac{9 c b}{a}+27 d+2 \sqrt{\frac{\left(b^2-3 a c\right)^3}{a^4}}>0\land -\frac{2 b^3}{a^2}+\frac{9 c b}{a}-27 d+2 \sqrt{\frac{\left(b^2-3 a c\right)^3}{a^4}}>0\right)\lor \left(3 a-\frac{b^2}{c}>0\land c<0\land \frac{2 b^3}{a^2}-\frac{9 c b}{a}+27 d+2 \sqrt{\frac{\left(b^2-3 a c\right)^3}{a^4}}<0\right)\lor \left(3 a-\frac{b^2}{c}>0\land c<0\land -\frac{2 b^3}{a^2}+\frac{9 c b}{a}-27 d+2 \sqrt{\frac{\left(b^2-3 a c\right)^3}{a^4}}<0\right)\lor \left(3 a-\frac{b^2}{c}<0\land c>0\land \frac{2 b^3}{a^2}-\frac{9 c b}{a}+27 d+2 \sqrt{\frac{\left(b^2-3 a c\right)^3}{a^4}}>0\land -\frac{2 b^3}{a^2}+\frac{9 c b}{a}-27 d+2 \sqrt{\frac{\left(b^2-3 a c\right)^3}{a^4}}>0\right)\lor \left(3 a-\frac{b^2}{c}<0\land c>0\land \frac{2 b^3}{a^2}-\frac{9 c b}{a}+27 d+2 \sqrt{\frac{\left(b^2-3 a c\right)^3}{a^4}}<0\right)\lor \left(3 a-\frac{b^2}{c}<0\land c>0\land -\frac{2 b^3}{a^2}+\frac{9 c b}{a}-27 d+2 \sqrt{\frac{\left(b^2-3 a c\right)^3}{a^4}}<0\right)\lor \left(3 a-\frac{b^2}{c}<0\land c<0\right) \\ -\frac{b}{3 a}-\frac{\left(1-i \sqrt{3}\right) \sqrt[3]{-2 b^3+9 a c b-27 a^2 d+\sqrt{4 \left(3 a c-b^2\right)^3+\left(-2 b^3+9 a c b-27 a^2 d\right)^2}}}{6 \sqrt[3]{2} a}+\frac{\left(1+i \sqrt{3}\right) \left(3 a c-b^2\right)}{3\ 2^{2/3} a \sqrt[3]{-2 b^3+9 a c b-27 a^2 d+\sqrt{4 \left(3 a c-b^2\right)^3+\left(-2 b^3+9 a c b-27 a^2 d\right)^2}}} & \left(3 a-\frac{b^2}{c}>0\land \frac{2 b^3}{a^2}-\frac{9 c b}{a}+27 d+2 \sqrt{\frac{\left(b^2-3 a c\right)^3}{a^4}}>0\land -\frac{2 b^3}{a^2}+\frac{9 c b}{a}-27 d+2 \sqrt{\frac{\left(b^2-3 a c\right)^3}{a^4}}>0\land c<0\right)\lor \left(3 a-\frac{b^2}{c}<0\land \frac{2 b^3}{a^2}-\frac{9 c b}{a}+27 d+2 \sqrt{\frac{\left(b^2-3 a c\right)^3}{a^4}}>0\land -\frac{2 b^3}{a^2}+\frac{9 c b}{a}-27 d+2 \sqrt{\frac{\left(b^2-3 a c\right)^3}{a^4}}>0\land c>0\right) \end{cases}$$

but when I try:

piecewiseForm[a*x^3+b*x^2+c*x+d==0,x,NonNegativeReals]

I just get $0$ and even:

Solve[a*x^3+b*x^2+c*x+d==0,x,NonNegativeReals]

gives: $\{\}$

but I know there are obviously non-negative solutions for the general cubic polynomial. How do I find this formula using Mathematica?

$\endgroup$
6
  • 2
    $\begingroup$ solutions = equation, solvingVariable, domain] is wrong syntax. $\endgroup$ Jan 22 at 16:34
  • $\begingroup$ I will correct it right now. Sorry. $\endgroup$
    – Teg Louis
    Jan 22 at 16:36
  • 1
    $\begingroup$ LogicalExpand[Reduce[a*x^3+b*x^2+c*x+d==0&&x>=0,x,Reals]] and LogicalExpand[Simplify[Reduce[a*x^3+b*x^2+c*x+d==0&&x>=0,x,Reals]]] reduces the size by 25% at the cost making the result less explicit for x in some cases. Maybe you can eliminate some cases that you consider not interesting and find the solution you are looking for in that. $\endgroup$
    – Bill
    Jan 22 at 16:37
  • $\begingroup$ Thanks. I want it to be an explicit piecewise function for personal reasons. I didn't know about LogicalExpand though. Thanks. $\endgroup$
    – Teg Louis
    Jan 22 at 16:42
  • 1
    $\begingroup$ See NeatExamples at resources.wolframcloud.com/FunctionRepository/resources/… and you will see that function used on this problem. $\endgroup$
    – Ted Ersek
    Jan 22 at 17:50

1 Answer 1

1
$\begingroup$
$Version

(* "14.0.0 for Mac OS X ARM (64-bit) (December 13, 2023)" *)

Clear["Global`*"]

sol1 = Assuming[
  x ∈ NonNegativeReals && {a, b, c, d} ∈ Reals,
  SolveValues[a*x^3 + b*x^2 + c*x + d == 0, x] // ToRadicals // 
   Simplify]

enter image description here

sol2 = Piecewise[List @@@ sol1]

enter image description here

$\endgroup$
1
  • $\begingroup$ It worked for Mathematica Online as well. $\endgroup$
    – Teg Louis
    Jan 22 at 19:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.