While the quadratic formula for solving quadratic equations is familiar to everyone who has taken high school math, it seems that the formula for solving cubic equations is not as familiar, but it is occasionally very handy. This formula was first discovered by Girolamo Cardano, Scipione del Ferro and Niccolo Fontana Tartaglia, and first published in Cardano's *Ars Magna* in 1545, and is considered a major result in Renaissance mathematics.

The general cubic equation can be expressed as follows:

x^{3} + bx^{2} + cx + d = 0

We may then calculate the following two values (somewhat analogous to the discriminant of the quadratic formula):

q = (b^{2} - 3c)/9

r = (2b^{3} 9bc + 27d)/54

If the coefficients of the cubic are all real, then the sum p = q^{3} + r^{2} determines what sort of roots the cubic polynomial might possess. If p is greater than 0, then it possesses one real root and two complex conjugate roots. If p is equal to zero, all roots are real, and we have roots of at least multiplicity 2. If p is less than zero, then all three roots are real.

In the latter case, we can proceed by computing:

θ = cos^{-1}(r/sqrt(q^{3}))

The three real roots may then be readily computed as:

x_{1} = -2 sqrt(q) cos(θ/3) - b/3

x_{2} = -2 sqrt(q) cos((θ + 2π)/3) - b/3

x_{3} = -2 sqrt(q) cos((θ - 2π/3) - b/3

If the coefficients are complex, or if either of the other two cases applies, we then compute these two values:

s_{1} = (r + sqrt(q^{3} + r^{2}))^{1/3}

s_{2} = (r - sqrt(q^{3} + r^{2}))^{1/3}

The roots of the cubic are then:

x_{1} = s_{1} + s_{2} - b/3

x_{2} = -(s_{1} + s_{2})/2 - b/3 + (i sqrt(3)/2)(s_{1} - s_{2})

x_{3} = -(s_{1} + s_{2})/2 - b/3 - (i sqrt(3)/2)(s_{1} - s_{2})

In practice, it's usually easier to just use one of these formulas to compute the root (the first one usually), and then remove that root using synthetic division and solve the resultant quadratic equation.

If one is doing these kinds of calculations by hand, a simple check would be to use the symmetric functions generated by the cubic, namely:

x_{1} + x_{2} + x_{3} = -b

x_{1}x_{2} + x_{1}x_{3} + x_{2}x_{3} = c

x_{1}x_{2}x_{3} = -d

and see if these formulas on the roots match with the coefficients of the original cubic.

In the computer age however, this cubic formula is only seldom used to numerically compute the roots of cubic polynomials, as iterative numerical methods like Laguerre's method or the Jenkins-Traub method can generally do the job much more efficiently for equations of this degree and higher.

Sources:

William H. Press, et. al. *Numerical Recipes in FORTRAN*

Milton Abramowitz and Irene A. Stegun, *Handbook of Mathematical Functions*