To solve a cubic equation

Cardano's method

Gerolamo Cardano published a method to solve a cubic equation in 1545. There is a description of this method on Wikipedia. But it is not too detailed and on the German Wikipedia even the last part is missing and so it’s impossible to implement a working algorithm by the aid of this. So I thought I try to do a more detailed explanation :-)

The method of Cardano is based on the reduction of the equation polynomia


Cardano
to the form

Cardano
And some variable substitutions as follows:

First of all the entire equation is divided by A to get the form

Cardano

With a = B/A, b = C/A and c = D/A

Now Cardano makes a variable substitution and replaces x by the term y + α. With this the equation becomes:

Cardano

This expanded becomes

Cardano

Given that α = -a/3, the y2 part becomes 0 and we get to the equation

Cardano

With α replaced by -a/3

Cardano


Now there is another substitution: y will be substituted by u + v and we get

Cardano

This equation expanded gives

Cardano

And with some brackets

Cardano

Given that 3uv = - p the part in brackets becomes 0 and for q = - u3 – v3 the entire left part is 0.

This condition for q we put into square now and the one for p divided by 3 to the power of 3 and multiply it by 4.

Cardano

By adding both conditions together we get

Cardano

Let’s say

Cardano

And we have

Cardano

From this two equations we can derive

Cardano

And with the substitution above

y = u + v

and (not to be forgotten :-))

x = y – a/3 = u + v – a/3

As we are looking for x and not for y.


Now there are the 3 possibilities D >= 0 , D = 0 and D < 0:


D > 0
If D > 0 the root of D is real and we get one real solution and two complex solutions for u and v:

Cardano

As real solution.


As the cubic root of a real number can have two complex solutions. One at the complex angle of 120° and the other one at 240°. The two complex solutions are of the same length as u0 and v0, but one has the complex angle 120° and the other one 240°. That means with

Cardano


for the complex angles we get

Cardano

and

Cardano

3 possible solutions for u and 3 possible solutions for v and if we combine them, we get 9 possible solutions. That’s pretty much and not all of them are valid :-) .

Further above we had the clause u*v = - p/3 and this is not the case for all 9 combinations of u and v. Principally it’s valid for the u0 * v0, u1 * v2 and u2 * v1. Let’s have look at u1 * v2. That’s

Cardano

If we separate

Cardano

and

Cardano

That only works for ε1 * ε2. If we combine ε1 * ε1, there remains an imaginary part and that can’t give - p/3. So, given that D > 0 there are the 3 solutions. But only the first one is real.

y1 = u0 + v0
y2 = u1 + v2
y3 = u2 + v1

(and don’t forget x = y – a/3 :-) )



D = 0

If D = 0, we have the same 3 solutions but as D = 0, u0 = v0 and

Cardano

and y3 = y2 we get only 2 solutions.

y1 = u0 + v0
y2 = -(u0 + v0)/2



D < 0
The case D < 0 is the so called “Casus irreducibilis”. Here the root of D becomes complex and the cubic roots for u and v become complex too.

Cardano

To solve this complex root we have to interpret the complex number as number of the length r and complex angle α.

With the substitution from further above

Cardano

We get the same length for u and v:

Cardano

The angle becomes for u:

Cardano

The angle becomes for v:

Cardano

To get the cubic root out of this now we have to calculate the cubic root of r and basically divide α by 3 that’s it. At least for the first solution :-) . The cubic root of a complex number has not just 1 but 3 solutions. The angle α we get once by multiplying α/3 by 3, twice by multiplying (2π + α)/3 by 3 and thirdly by multiplying (4π + α)/3 by 3. That makes 3 solutions for u and 3 solutions for v. They look like:

Cardano

And as αv = 2π - α

Cardano

That would give 9 possible solutions again. But as we are interested in real solutions, we can reduce that to 3 real solutions. For the 3 combinations

u0 + v2
u1 + v1
u2 + v0

the imaginary part becomes 0 and the solutions are

Cardano

That’s it :-)



There is a small online solver in JavaScript for this on Cardano solver).


C# Demo Project Cardano
  • Cardano.zip