A cubic function has an x3 term, its general form is:
a x3 + b x2 + c x + d = 0
The three solutions are:
root1 = -a/3 + ((-2a3 + 9ab - 27c + sqrt((2a3 -9ab +27c)2 + 4(-a2 + 3b)3))/54)1/3 + ((-2a3 + 9ab - 27c - √((2a3 -9ab +27c)2 + 4(-a2 + 3b)3))/54)1/3
root2 = -a/3 - (1 + i sqrt(3))*0.5*((-2a3 + 9ab - 27c + sqrt((2a3 -9ab +27c)2 + 4(-a2 + 3b)3))/54)1/3 + (-1 + i sqrt(3))*0.5*((-2a3 + 9ab - 27c - sqrt((2a3 -9ab +27c)2 + 4(-a2 + 3b)3))/54)1/3
root3 = -a/3 + ((-2a3 + 9ab - 27c + sqrt((2a3 -9ab +27c)2 + 4(-a2 + 3b)3))/54)1/3 + ((-2a3 + 9ab - 27c - √((2a3 -9ab +27c)2 + 4(-a2 + 3b)3))/54)1/3
Methods of solution
- by factors
- by completing the cobe
- by formulae
- by graph
Sum and difference of two cubes
(a + b)(a2 - ab + b2)
= a (a2 - ab + b2) + b (a2 - ab + b2)
= a3 - a2b + ab2 + ba2 - ab2 + b3
= a3 + b3
simarly
(a - b)(a2 + ab + b2) = a3 - b3
Using Symmetry
Instead of using the equation:
a x3 + b x2 + c x + d = 0
= 0
we can use the equation:
(x - x1)*(a' x2 + b' x + c') = 0
where x is our variable and x1, a', b' and c' are constants.
which has solutions at:
x = x1 and
In other words, can we use this to reduce the cubic to a quadratic in this way? First we have to multiply out the terms to see if its a general cubic:
(x - x1)*(a' x2 + b' x + c') = (a' x3 + b' x2 + c' x ) - x1*a' x2 - x1* b' x - x1* c')
= a' x3 + (b' - x1*a')x2 + (c' - x1* b') x - x1* c')
Therefore:
- a = a'
- b = b' - x1*a
- c = c' - x1* b'
- d = - x1* c'
So, puting this in terms of the original equation,
- a' = a
- b' = b + x1*a = b - d*a/c'
- c' = c + x1* b' = c - d*(b - d*a)/c'
- x1 = -d/c'
so:
c'2 - c*c' + d*(b - d*a) = 0
c' = (c± √(c2 - 4*d*(b - d*a)))/2
substituting in above gives:
- a' = a
- b' = b + x1*a = b - d*a/(c± √(c2 - 4*d*(b - d*a)))/2
- c' = (c± √(c2 - 4*d*(b - d*a)))/2
- x1 = -d/(c± √(c2 - 4*d*(b - d*a)))/2
Code
Here is a Java function to return the cubic roots






