# Solve Cubic Equation with Mathematica

I need some help for solving a cubic equation. In this thread there is a solution of how a cubic equation can be solved with Mathematica

The exact real solutions of a cubic polynomial?

I tried this solution but I don't get any output.

Only th is a variable. The rest are constants.

roots = Solve[
s2 +
1/(96 jmax^2 (b1 - b2 + jmax tf)) (b1^4 + b2^4 -
b2^3 jmax (4 tf + 3 th) +
b1^3 (-4 b2 + 4 jmax tf + 3 jmax th) +
3 b2^2 jmax^2 (2 tf^2 + 3 tf th + th^2) +
3 b1^2 (2 b2^2 - b2 jmax (4 tf + 3 th) +
jmax^2 (2 tf^2 + 3 tf th + th^2)) +
3 b2 jmax^2 (32 s1 +
jmax (4 tf^3 - 3 tf^2 th - 2 tf th^2 + th^3) +
32 tf v1) -
b1 (4 b2^3 - 3 b2^2 jmax (4 tf + 3 th) +
6 b2 jmax^2 (-6 tf^2 + 3 tf th + th^2) +
3 jmax^2 (32 s1 +
jmax (4 tf^3 - 3 tf^2 th - 2 tf th^2 + th^3) +
32 tf v2)) -
3 jmax^2 (jmax^2 tf (tf - th)^2 (tf + th) -
16 (v1 - v2)^2 + 16 jmax tf (2 s1 + tf (v1 + v2)))) == 0
, th
, Reals
] // ToRadicals // ComplexExpand // FullSimplify


Hope that somebody can help me Thanks in advance !

• What exactly is your question though? The Solve expression works and returns results as conditional expressions containing Root objects. The rest might take a very long time to execute, but do you need the ToRadicals etc? What do you need to do with the results? Jun 20, 2018 at 17:06
• @MarcoB As Result i want an exact Solution. If i just use Solve i get 3 Solutions for th. These 3 Solutions are really long--> it seems that its an approximation... So i found this Solve Command with Roots. I ran this command but now its running for 20 min ... and i don't think that i will get an solution.... I need the Exact Solution to use it in another Matlab skript to calculate this variable th for different constants... Hope that you understand what i mean Jun 20, 2018 at 17:14
• The Root object result is not an approximation. Jun 20, 2018 at 17:25
• ...Moreover any solution in terms of parametrized radicals will either require a conditional to switch between three values, or else will be incorrect for some values of the parameters (because when there is only one real valued solution, it need not always be in the same radical solution). Jun 20, 2018 at 17:28
• Actually the Wolfram Language also has that built in (with multiple methods). Jun 21, 2018 at 14:16

If I understand you correctly, you can do the following.

First solve for the generic cubic in terms of radicals and then substitute.

subs=Thread[{a0, a1, a2, a3} ->
CoefficientList[
s2 + 1/(96 jmax^2 (b1 - b2 + jmax tf)) (b1^4 + b2^4 -
b2^3 jmax (4 tf + 3 th) +
b1^3 (-4 b2 + 4 jmax tf + 3 jmax th) +
3 b2^2 jmax^2 (2 tf^2 + 3 tf th + th^2) +
3 b1^2 (2 b2^2 - b2 jmax (4 tf + 3 th) +
jmax^2 (2 tf^2 + 3 tf th + th^2)) +
3 b2 jmax^2 (32 s1 +
jmax (4 tf^3 - 3 tf^2 th - 2 tf th^2 + th^3) + 32 tf v1) -
b1 (4 b2^3 - 3 b2^2 jmax (4 tf + 3 th) +
6 b2 jmax^2 (-6 tf^2 + 3 tf th + th^2) +
3 jmax^2 (32 s1 +
jmax (4 tf^3 - 3 tf^2 th - 2 tf th^2 + th^3) +
32 tf v2)) -
3 jmax^2 (jmax^2 tf (tf - th)^2 (tf + th) - 16 (v1 - v2)^2 +
16 jmax tf (2 s1 + tf (v1 + v2)))), th] // FullSimplify]
ToRadicals[Root[a3 #^3 + a2 #^2 + a1 # + a0 &, #]] & /@ {1, 2,3} /. subs

• Thanks for the answer and Help :) Are the three Solutions which i get as output the 3 Solutions for th ? Jun 20, 2018 at 17:47
• Yes. And happy to help. Jun 20, 2018 at 17:48
• One Last Question: This Solution which you have generated is the same as the solution if you just use the solve command... only that the Equations are smaller is that right ? Jun 20, 2018 at 19:39
• @IlPad Yes. This is just a way to bypass too much of simplification that Mathematica would otherwise want to do if you had entered the complicated expression all at once. Jun 21, 2018 at 3:46
• Ok Thanks! and if i change the cubic function to an quadric i just have to add an a4 or ? Jun 21, 2018 at 9:01