I have been working on a script in Java to solve cubic equations. I've been following along with Mathematics and Physics for Programmers to teach my self about, well maths and physics.
As far as I can test it is working correctly, but I have not been able to find an equation with a discriminant of zero to test that case.
The equation that the code is based on is as follows:
If the discriminant is > 0:
if the discriminant = 0 (I do not know an equation to test this):
if the discriminant < 0:
After finding t transform it by:
I'd be very grateful if someone can help me work out how to test this is working correctly.
For anyone interested my code is here: https://github.com/sarcoma/Java-Algorithms/blob/master/src/com/oacc/maths/SolveCubic.java
I figured I'd expand on my comment. If you have a polynomial $f(x) = a_{n}x^n + \cdots + a_{0}$ and its roots are $r_{1}, \dots, r_{n}$ then the discriminant $D$ is equal to $$ D = a_{n}^{2n - 2} \prod_{i < j} (r_{i} - r_{j})^2.$$
From this definition, it is immediate that $f$ has discriminant 0 if and only if it has a repeated root.
So if you want a cubic with discriminant zero, try something like $(x - 4)^2(x + 5)$ such as John Gowers suggested in the comments.