clear all
; General cubic formula.
; Formula for the 3 roots (solutions for x) of the general cubic equation.
;
; This is currently the only way to solve cubic polynomials in Mathomatic.
; This is also a good test of the optimize and "simplify quick" commands.
; Try "optimize all".

a x^3 + b x^2 + c x + d = 0 ; The general cubic equation.
x_1=-b/{3 a}-1/{3 a} {{2 b^3-9 a b c+27 a^2 d+{(2 b^3-9 a b c+27 a^2 d)^2-4 (b^2-3 a c)^3}^.5}/{2}}^(1/3)-1/{3 a} {{2 b^3-9 a b c+27 a^2 d-{(2 b^3-9 a b c+27 a^2 d)^2-4 (b^2-3 a c)^3}^.5}/2}^(1/3)
x_2=-b/{3 a}+{1+i 3^.5}/{6 a} {{2 b^3-9 a b c+27 a^2 d+{(2 b^3-9 a b c+27 a^2 d)^2-4 (b^2-3 a c)^3}^.5}/{2}}^(1/3)+{1-i 3^.5}/{6 a} {{2 b^3-9 a b c+27 a^2 d-{(2 b^3-9 a b c+27 a^2 d)^2-4 (b^2-3 a c)^3}^.5}/2}^(1/3)
x_3=-b/{3 a}+{1-i 3^.5}/{6 a} {{2 b^3-9 a b c+27 a^2 d+{(2 b^3-9 a b c+27 a^2 d)^2-4 (b^2-3 a c)^3}^.5}/{2}}^(1/3)+{1+i 3^.5}/{6 a} {{2 b^3-9 a b c+27 a^2 d-{(2 b^3-9 a b c+27 a^2 d)^2-4 (b^2-3 a c)^3}^.5}/2}^(1/3)
; Equations #2, #3, and #4 are the solutions to the cubic equation in #1.
; Use the calculate command to temporarily plug in coefficients.
