How to solve cubic equations with given coefficients?

1.7k Views Asked by At

I have a large data set that requires a cubic equation to be solved for each point. There are too many points to use Goal Seek (numerical Excel method) on them all.

For example:

$$y=7\cdot 10^{-7}x^3-8\cdot10^{-4}x^2+0.2862x$$

I need to solve for $x$ with a known $y$ each time. I found the general formula for solving cubic equations, but when using it, I get negative numbers under the square root. How to calculate with this formula then?

1

There are 1 best solutions below

0
On BEST ANSWER

(Since the OP doesn't know how to depress a cubic.)

Given the general cubic $Ax^3+Bx^2+Cx+D=0$, divide by $A$ to get the simpler,

$$x^3+ax^2+bx+c = 0\tag1$$

Define the important values $p,q$ as,

$$p = \frac{1}{3}(-a^2+3b)$$

$$q = \frac{1}{27}(2a^3-9ab+27c)$$

Case $1$. When $4p^3+27q^2>0$

Then $(1)$ has only one real root given by,

$$x_1 = -\frac{a}{3}+z_1^{1/3}+z_2^{1/3}\tag2$$

where the $z_i$ are the two roots of the quadratic,

$$z^2+qz-\frac{p^3}{27}=0$$

To find the two complex roots, use a complex cube root of unity $\zeta = e^{2\pi\, i/3}$,

$$x_k = -\frac{a}{3}+\color{brown}{z_1^{1/3}}\zeta^k+\frac{-p}{3}\frac{1}{\color{brown}{z_1^{1/3}}\zeta^k}\quad \text{for}\; k = 0,1,2$$

and $k=0$ also yields the real root.

Case $2$. When $4p^3+27q^2<0$

Then $(1)$ has three real roots given by,

$$x_k = -\frac{a}{3}+2\sqrt{\frac{-p}{3}}\cos(\theta_k)\tag3$$

where,

$$\theta_k = \frac{1}{3}\arccos\left(\frac{3q}{2p}\sqrt{\frac{3}{-p}}\right)-\frac{2\pi\,k}{3},\quad \text{for}\; k = 0,1,2$$

Your difficulty was with Case $2$ when you got a minus sign within the square root. Using trigonometric functions bypasses that. (Note that $p$ is always negative for this case.)