Book contents
Contents
raw Math
RAW Book Algebra Polynomial Equations

Solving Cubic Equations

Robert Eisele

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\)
Calculate

First Observations

  1. When \(a = 0\): The cubic equation reduces to a quadratic equation:

\[ bx^2 + cx + d = 0 \]

  1. 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:

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} \]

The cube roots must be chosen as a compatible pair satisfying \(uv=-p/3\); choosing both principal cube roots independently does not guarantee this condition. With such a pair,

\[ 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:

This is useful both analytically and numerically because it predicts the behavior of the solution formula.

For \(\Delta<0\), the radical expression passes through complex intermediate values even though all roots are real. The equivalent trigonometric form avoids this casus irreducibilis. For \(\Delta=0\), handling the repeated roots directly also avoids the undefined quotient that would arise from computing \(v=-p/(3u)\) when \(u=0\).

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 implementation uses Complex.js for non-real roots and branches on the discriminant before constructing them. This avoids dividing by a vanishing Cardano term when, for example, solving \(x^3+1=0\), and uses the trigonometric form when all three roots are real. A packaged implementation is available as RootFinder.js.

function cubicRoots(a, b, c, d) {
  if (a === 0) return quadratic(b, c, d);

    // Make a depressed cubic of the form x^3 + px + q = 0
  const p = (3 * a * c - b * b) / (3 * a * a);
  const q = (2 * b ** 3 - 9 * a * b * c + 27 * a * a * d) / (27 * a ** 3);
  const D = (q / 2) ** 2 + (p / 3) ** 3;
  const shift = -b / (3 * a);
  const root = (re, im = 0) => Complex(re + shift, im);

  if (Math.abs(D) < 1e-14) {
    // One triple root, or one simple and one double root
    const u = Math.cbrt(-q / 2);
    return [2 * u, -u, -u].map(t => root(t));
  }

  if (D > 0) {
    // One real root and one complex-conjugate pair
    const s = Math.sqrt(D);
    const u = Math.cbrt(-q / 2 + s);
    const v = Math.cbrt(-q / 2 - s);
    const re = -(u + v) / 2;
    const im = Math.sqrt(3) * (u - v) / 2;
    return [root(u + v), root(re, im), root(re, -im)];
  }

  // Three distinct real roots
  const r = Math.sqrt(-p / 3);
  const phi = Math.acos(Math.max(-1, Math.min(1, -q / (2 * r ** 3))));
  return [0, 1, 2].map(k =>
    root(2 * r * Math.cos((phi + 2 * Math.PI * k) / 3)));
}

References