1

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?

Moolan
  • 23
  • I can't perform a goal seek on each point, so I was looking for how to solve the equation "the long way".

    I have researched the general formula for solving these equations however, I have negative numbers in the square root..

    – Moolan Feb 24 '16 at 23:09
  • Excel has trigonometric functions and their inverses. Use this version of cubic formula if negative numbers appear under square root. You'll need an IF statement to use appropriate method in each case. Also, when there are three roots, you'll have to somehow decide which one you want. –  Feb 24 '16 at 23:16
  • 1
    I think it might be easier to either simplify the problem or write a script up to solve these. Can always dump the values back into excel via CSV. Thank you for that pointer! – Moolan Feb 24 '16 at 23:23
  • I do not. I think its time to look at simplifying the problem if it maintains the accuracy I'm looking for. – Moolan Feb 24 '16 at 23:36
  • @Moolan: Wait a few minutes. I'm typing the answer. – Tito Piezas III Feb 24 '16 at 23:48

1 Answers1

2

(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.)