Consider a cubic equation in standard form:
This chapter is the degree-\(3\) special case of the general theory in Introduction to Polynomials, which covers arbitrary degree.
\[ ax^3 + bx^2 + cx + d = 0 \]
where \(a, b, c, d \in \mathbb{R}\). There are several ways to find the roots of such an equation, ranging from numerical methods to exact algebraic formulas. By the Fundamental Theorem of Algebra, a polynomial of degree three has exactly three roots \(x_1, x_2, x_3\), so we can write
\[ (x - x_1)(x - x_2)(x - x_3) = 0 \]
Expanding this product and dividing by \(a\) yields
\[ x^3 + \underbrace{(-x_1 - x_2 - x_3)}_{= \frac{b}{a}} x^2 + \underbrace{(x_1 x_2 + x_1 x_3 + x_2 x_3)}_{= \frac{c}{a}}x + \underbrace{(-x_1 x_2 x_3)}_{= \frac{d}{a}} = 0 \]
Finding the roots from the coefficients \(a, b, c, d\) is therefore non-trivial. The relations between coefficients and roots are simple to state but not simple to invert directly.
Cubic Equation Calculator
\[ ax^3 + bx^2 + cx + d = 0 \]
| \(a\) | \(b\) | \(c\) | \(d\) |
|---|---|---|---|
First Observations
- When \(a = 0\): The cubic equation reduces to a quadratic equation:
\[ bx^2 + cx + d = 0 \]
- When \(d = 0\): The equation simplifies to
\[ ax^3 + bx^2 + cx = 0 \]
Factoring out \(x\), we get
\[ x(ax^2 + bx + c) = 0 \]
This yields one root at \(x = 0\), and the remaining roots come from the quadratic factor
\[ ax^2 + bx + c = 0 \]
More generally, if a polynomial \(p(x)\) of degree \(n \ge 1\) has a root \(x_0\), then the Factor Theorem says that there is a polynomial \(q(x)\) of degree \(n - 1\) such that
\[ p(x) = (x - x_0) \cdot q(x) \]
So once a single root is known, the cubic reduces to a quadratic by polynomial division or synthetic division. The initial root can be guessed graphically or approximated numerically, for example with Newton's method. This works well in practice because every real cubic equation has at least one real root.
Newton's Method
Newton's method refines an initial guess \(x_0\) by the recursive update
\[ x_{n+1} = x_n - \frac{f(x_n)}{f'(x_n)} \]
Here \(x_n\) denotes the \(n\)-th iteration, not the \(n\)-th root. For the cubic function \(f(x) = ax^3 + bx^2 + cx + d\), the derivative is \(f'(x) = 3ax^2 + 2bx + c\). Substituting these into the update formula yields
\[ x_{n+1} = x_n - \frac{ax_n^3 + bx_n^2 + cx_n + d}{3ax_n^2 + 2bx_n + c} = \frac{2ax_n^3 + bx_n^2 - d}{3ax_n^2 + 2bx_n + c} \]
This iteration converges to a real root when the initial guess is chosen well.
Other Numerical Methods
Alternative numerical methods for root finding include:
- Laguerre's method: fast convergence and reliable handling of both real and complex roots.
- Companion matrix method: conversion of the polynomial into a matrix whose eigenvalues are the roots.
Numerical methods are excellent for approximations, but they can suffer from rounding issues, especially for multiple or closely spaced roots. For exact symbolic formulas, Cardano's method is the classical approach.
Derivation of Cardano's Method
Cardano's method solves cubic equations by reducing the general cubic to a simpler depressed cubic and then solving that form directly.
1. Standard Form of a Cubic Equation
The general cubic equation is
\[ ax^3 + bx^2 + cx + d = 0 \]
Dividing by \(a\) gives the normalized form
\[ x^3 + \frac{b}{a}x^2 + \frac{c}{a}x + \frac{d}{a} = 0 \]
Introducing
\[ x^3 + Bx^2 + Cx + D = 0 \quad \text{with} \quad B = \frac{b}{a},\; C = \frac{c}{a},\; D = \frac{d}{a} \]
makes the coefficient relations easier to read.
2. Reducing to a Depressed Cubic
A cubic is point-symmetric about its inflection point. In general this inflection point is shifted horizontally. For
\[f(x)=x^3 + \frac{b}{a}x^2 + \frac{c}{a}x + \frac{d}{a}\]
we compute
\[f'(x)=3x^2+2\frac{b}{a}x+\frac{c}{a}\]
and
\[f''(x)=6x+2\frac{b}{a}=0\]
so the inflection point lies at
\[x = -\frac{b}{3a} = -\frac{B}{3}\]
To eliminate the quadratic term, we shift by the inflection point and substitute
\[ x = t - \frac{b}{3a} \]
Substituting this into the normalized cubic yields
\[ \begin{array}{rrl} &\left(t - \frac{b}{3a}\right)^3 + \frac{b}{a}\left(t - \frac{b}{3a}\right)^2 + \frac{c}{a}\left(t - \frac{b}{3a}\right) + \frac{d}{a} &= 0\\ \Leftrightarrow &t^3 + \left(\frac{c}{a} - \frac{b^2}{3a^2}\right)t + \left(\frac{2b^3}{27a^3} - \frac{bc}{3a^2} + \frac{d}{a}\right) &= 0\\ \Leftrightarrow &t^3 + pt + q &= 0 \end{array} \]
where
\[ p = \frac{3ac - b^2}{3a^2} = C - \frac{B^2}{3} \]
and
\[ q = \frac{27a^2d - 9abc + 2b^3}{27a^3} = \frac{2B^3}{27} - \frac{BC}{3} + D \]
This moves the inflection point onto the y-axis and removes the quadratic term. In this shifted coordinate system, \(q\) is the y-value and \(p\) is the slope-related coefficient at the inflection point.
3. Calculating the Roots of the Depressed Cubic
To solve
\[ t^3 + pt + q = 0 \]
we start from the identity
\[\begin{array}{rl} (u+v)^3 &= u^3+3u^2v+3uv^2+v^3\\ &= 3uv(u+v)+u^3+v^3 \end{array}\]
Matching this with the depressed cubic suggests the substitutions
\[\begin{array}{rl} {\underbrace{(u+v)}_{t}}^3 \underbrace{-3uv}_{p}\underbrace{(u+v)}_{t}\underbrace{-(u^3+v^3)}_{q} &= 0 \end{array}\]
So we read off
\[\begin{array}{rl} t &= u+v\\ p &= -3uv\\ q &= -(u^3+v^3) \end{array}\]
and therefore
\[\begin{array}{rl} uv &= -\frac{p}{3}\\ u^3+v^3 &= -q \end{array}\]
Solving for \(u^3\) and \(v^3\)
Using \(u^3 + v^3 = -q\) and \(uv = -\frac{p}{3}\), we can solve for \(u^3\) and \(v^3\) via a quadratic equation. Cubing \(uv = -\frac{p}{3}\) gives \(u^3v^3 = -\left(\frac{p}{3}\right)^3\). Combining this with \(u^3 + v^3 = -q\) yields
\[ \left(v^3\right)^2 + qv^3 - \left(\frac{p}{3}\right)^3 = 0 \]
Hence
\[ u^3, v^3 = -\frac{q}{2} \pm \sqrt{\left(\frac{q}{2}\right)^2 + \left(\frac{p}{3}\right)^3} \]
Taking cube roots then gives \(u\) and \(v\), so
\[ t = \sqrt[3]{-\frac{q}{2} + \sqrt{\left(\frac{q}{2}\right)^2 + \left(\frac{p}{3}\right)^3}} + \sqrt[3]{-\frac{q}{2} - \sqrt{\left(\frac{q}{2}\right)^2 + \left(\frac{p}{3}\right)^3}} \]
4. Understanding the Discriminant
The discriminant of the depressed cubic is
\[ \Delta = \left(\frac{q}{2}\right)^2 + \left(\frac{p}{3}\right)^3 \]
and it determines the qualitative form of the roots:
- If \(\Delta > 0\): one real root and two complex conjugate roots.
- If \(\Delta = 0\): all roots are real, with at least one repeated root.
- If \(\Delta < 0\): all three roots are real and distinct.
This is useful both analytically and numerically because it predicts the behavior of the solution formula.
5. Efficient Solution to Cubic Equations
In the formula above, the square root can become complex. Then \(u^3\) and \(v^3\) form a conjugate pair in the complex plane.
To find all three roots of the depressed cubic, we rotate by 120 degrees using the complex cube root of unity
\[ \omega = e^{2\pi i / 3} = -\frac{1}{2} + \mathbf{i}\frac{\sqrt{3}}{2} \]
with \(\omega^2 = \overline{\omega}\) and \(\omega^3 = 1\).
The roots of the depressed cubic can then be written as
\[\begin{array}{rl} t_1 &= u + v\\ t_2 &= \omega u + \omega^2 v\\ t_3 &= \omega^2 u + \omega v \end{array}\]
This works because multiplying by \(\omega\) rotates by 120 degrees in the complex plane, matching the threefold symmetry of cubic roots.
6. Transforming Back to \(x_k\)
After computing \(t_1, t_2, t_3\), we return to the original variable using
\[ x_k = t_k - \frac{B}{3}, \quad k = 1, 2, 3 \]
which yields the solutions of the original cubic equation
\[ ax^3 + bx^2 + cx + d = 0 \]
Cubic Roots JavaScript Implementation
The following JavaScript implementation uses Complex.js to handle all cases, including complex roots.
function cubicRoots(a,b,c,d) {
// Make a depressed cubic of the form x^3 + px + q = 0
let p = (3 * a * c - b * b) / (3 * a * a);
let q = (2 * b * b * b - 9 * a * b * c + 27 * a * a * d) / (27 * a * a * a);
// Calculate cube roots of complex numbers
let D = Complex(Math.pow(q / 2, 2) + Math.pow(p / 3, 3));
let sqrtD = D.sqrt();
let u = Complex(-q / 2).add(sqrtD).pow(1 / 3);
// v is not an independent cube root: it must satisfy uv = -p/3,
// otherwise u + v no longer solves the depressed cubic.
let v = Complex(-p / 3).div(u);
// Calculate the roots in t
let omega = Complex(-0.5, Math.sqrt(3) / 2); // Principal cube root of unity
let t1 = u.add(v);
let t2 = v.mul(omega.conjugate()).add(u.mul(omega));
let t3 = u.mul(omega.conjugate()).add(v.mul(omega));
// Transform back to the original variable x
let shift = -b / (3 * a);
return [t1.add(shift), t2.add(shift), t3.add(shift)];
} References
- NickallsR. W. D. Nickalls (1993) A new approach to solving the cubic: Cardan's solution revealed