I’m failing to solve a cubic equation

cubics

SOLUTION:
Because I made the substition of $t = x + \frac {b}{3a}$, I had to substract $\frac {b}{3a}$ from my final answer, giving me the formula for x: $x = u + v – \frac {b}{3a}$.

I'm trying to write my own cubic equation solver program using C#, but I am getting the wrong answer. I'm pretty sure all my code is correct, so I suspect I'm doing something wrong with the calculations itself. I suspect I'm just missing a step or made a fundamental mistake in solving the cubic equation. Please keep in mind I have never solved a cubic equation before.

I will thoroughly explain all the steps I have taken, in the hopes of you finding the mistake.

First, I depressed the cubic from the standard form of $ax^3 + bx^2 + cx + d$ into $x^3 + px + q$.
From this video by Mathologer, I learned how to do this (he explains it at 16:05).

He stated that p and q should be set equal to these values:

$$p = \frac ca – \frac {b^2}{3a^2}$$

$$q = \frac {2b^3}{27a^3} – \frac{bc}{3a^2} + \frac da$$

So you would get the formula:
$$x^3 + (\frac ca – \frac {b^2}{3a^2})x + (\frac {2b^3}{27a^3} – \frac{bc}{3a^2} + \frac da)$$
After that, I calculated the discriminant, with the method show in Mathologer's video at 19:00:
$$(\frac q2)^2 + (\frac p3)^3$$

With the discriminant calculated, I could move on to the next step, in which I check if the discriminant is positive, zero or negative. Right now I'm having issues with the answer I get from the positive discriminant.

I then calculated the values for u and v (method shown at 23:00) and added them together to get the value of x.
$$u = \sqrt[3]{-\frac q2 + \sqrt{(\frac q2)^2 + (\frac p3)^3}}$$
$$v = \sqrt[3]{-\frac q2 – \sqrt{(\frac q2)^2 + (\frac p3)^3}}$$
$$x = u + v$$

When I input: a = 2, b = 3, c = 4, d = 5. I get the result: $x = -0.8711$. But when I graphed $2x^3 + 3x^2 + 4x + 5$ in Desmos, I found that it should be: $x = -1.3711$. I tripled checked all the steps with my calculator, so I don't think it's just a calculation error.

I tested all the steps I took, and found that:

$p = 1.25$

$q = 1.75$

$discriminant = 0.8379$

$u = 0.3431$

$v = -1.2142$

Something interesting I noticed was that my answer is exactly 0.5 higher than what it should be. Coincidence?

Does anyone see what I did wrong here?

Best Answer

When you depress a cubic, you make the substitution $t = x+b/3a$. For your example that would be $t = x+3/(2\cdot 3) =x + 1/2$.

You're using $x$ in two ways. In your depressed equation, the $x$ should be a different variable, say $t$. You're getting $-0.8711$ for $t$. But $t=x+1/2$, so....

Related Question