Cubic function

It is not the purpose of this page to repeat good information available elsewhere. However, it seems to the author that other descriptions of the cubic function are more complicated than they need to be. This page attempts to demystify elementary but essential information concerning the cubic function.

=Objective=


 * Present cubic function and cubic equation.
 * Introduce the concept of roots of equal absolute value.
 * Show how to predict and calculate equal roots, techniques that will be useful when applied to higher order functions.
 * Simplify the depressed cubic.
 * Simplify Vieta's substitution.
 * Review complex numbers as they apply to a complex cube root.
 * Present cubic formula simplified.
 * Show that the cubic equation is effectively solved when at least one real root is known.
 * Use Newton's Method to calculate one real root.
 * Show that the cubic equation can be solved with high-school math.

=Lesson=

Introduction
The cubic function is the sum of powers of $$x$$ from $$0$$ through $$3$$:

$$y = f(x) = ax^3 + bx^2 + cx^1 + dx^0$$

usually written as:

$$y = f(x) = ax^3 + bx^2 + cx + d.$$

If $$d == 0$$ the function becomes $$x(ax^2 + bx + c).$$

Within this page we'll say that:


 * both coefficients $$a, d$$ must be non-zero,
 * coefficient $$a$$ must be positive (simply for our convenience),
 * all coefficients must be real numbers, accepting that the function may contain complex roots.

The cubic equation is the cubic function equated to zero:

$$ax^3 + bx^2 + cx + d = 0$$.

Roots of the function are values of $$x$$ that satisfy the cubic equation.

Because all coefficients must be real numbers, the cubic function must have 3 real roots or exactly 1 real root.

Other combinations of real and complex roots are possible, but they produce complex coefficients.

Coefficient c missing
If coefficient $$c$$ is missing, the cubic function becomes $$y = ax^3 + bx^2 + d,$$ and

$$y' = 3ax^2 + 2bx = x(3ax + 2b).$$

For a stationary point $$y' = x(3ax + 2b) = 0.$$

When coefficient $$c$$ is missing, there is always a stationary point at $$x = 0.$$

x = f(y)
The cubic function may be expressed as $$x = ay^3 + by^2 + cy + d.$$

Unless otherwise noted, references to "cubic function" on this page refer to function of form $$y = ax^3 + bx^2 + cx + d.$$

Coefficient a negative
Coefficient $$a$$ may be negative as shown in diagram.

As $$abs(x)$$ increases, the value of $$f(x)$$ is dominated by the term $$-ax^3.$$

When $$x$$ has a very large negative value, $$f(x)$$ is always positive.

When $$x$$ has a very large positive value, $$f(x)$$ is always negative.

Unless stated otherwise, any reference to "cubic function" on this page will assume coefficient $$a$$ positive.

Sum of roots 0
When sum of roots is $$0,$$ coefficient $$b = 0.$$

In the diagram, roots of $$f(x)$$ are $$-8, 2.4, 5.6.$$

Sum of roots $$= 0.$$

Therefore coefficient $$b = 0.$$

Ratio of stationary points to roots
Stationary points relative to roots:

Consider cubic function: $$f(x) = ax^3 - cx.$$

Roots of function are: $$0,\ x_1,x_2\ =\ \pm\sqrt{\frac{c}{a}}.$$

Derivative of function: $$g(x) = 3ax^2 - c.$$

Stationary points of function are roots of $$g(x):\ q,r\ =\ \frac{-0 \pm \sqrt{0^2 - 4(3a)(-c)}}{6a}$$ or $$\frac{\pm \sqrt{3}\sqrt{ac}}{3a}.$$

Ratio of $$r$$ to $$x_2\ =\ \frac{\sqrt{3}\sqrt{ac}}{3a} \cdot \sqrt{\frac{a}{c}}$$ $$\ =\ \frac{\sqrt{3}}{3}.$$

Ratio of $$q$$ to $$x_1\ =\ -\frac{\sqrt{3}\sqrt{ac}}{3a} \cdot -\sqrt{\frac{a}{c}}$$ $$\ =\ \frac{\sqrt{3}}{3}.$$

s = 2r
Equation of red curve in diagram: $$y =f(x) = ax^3 - cx,$$ where $$a, b, c = a, 0, -c$$

Aim of this section is to calculate $$s$$ so that $$f(s) = f(q).$$

Associated quadratic when $$x = q:$$

$$A = a$$

$$B = Aq + b$$

$$C = Bq + c$$

$$q$$ is a root of this function. Divide $$Ax^2 + Bx + C$$ by $$x - q.$$

Quotient is $$Ax + Aq + B.$$

Remainder is $$Aq^2 + Bq + C$$ which equals $$0.$$

$$Ax + Aq + B = 0.$$ Therefore:

$$s = \frac{-Aq - B}{A} = \frac{-Aq -Aq}{A} = -2q.$$

$$r=-q.$$ Therefore $$s = -2(-r) = 2r.$$

Function as product of 3 linear functions
The function may be expressed as:

$$y = (x - p)(x - q)(x - r)$$ where $$p, q, r$$ are roots of the function, in which case

$$y = x^3 - (p + q + r)x^2 + (pq + qr + rp)x - pqr$$ where: $$a = 1;\ b = -(p + q + r);\ c = pq + qr + rp;\ d = -pqr$$

Solving the cubic equation means that, given $$a, b, c, d$$, at least one of $$p, q, r$$ must be calculated.

Given $$b, c, d$$, I found that $$r$$ can be calculated as:

$$r^8 + 2br^7 + (bb+3c)r^6 + (4bc+2d)r^5 + (bbc+2bd+3cc)r^4 + (2bcc+4cd)r^3 + (2bcd+c^3+dd)r^2 + 2ccdr + cdd = 0$$

This approach was not helpful.

Function as product of linear function and quadratic
When $$p$$ is a root of the function, the function may be expressed as:

$$(x - p)(Ax^2 + Bx + C)$$ where

$$A = a;\ B = Ap+b;\ C = Bp+c.$$

When one real root $$p$$ is known, the other two roots may be calculated as roots of the quadratic function $$Ax^2 + Bx + C$$.

$$f(x) = (x - p)(ax^2 + Bx + C)$$ $$= ax^3 + bx^2 + cx - (ap^3 + bp^2 + cp).$$

When $$p$$ is a root of the function, $$ap^3 + bp^2 + cp + d = 0$$ or $$ap^3 + bp^2 + cp = -d.$$

Therefore the expansion of $$(x - p)(ax^2 + Bx + C)$$ $$= ax^3 + bx^2 + cx - (-d)$$ $$= ax^3 + bx^2 + cx + d.$$

Generally, if point $$(p, q)$$ is any point on the curve and it is desired to calculate the other values of $$x$$ that produce $$y = q,$$ then:

$$ap^3 + bp^2 + cp + d = q$$ or $$ap^3 + bp^2 + cp = q - d$$ and

$$f(x) = ax^3 + bx^2 + cx - (ap^3 + bp^2 + cp)$$ $$= ax^3 + bx^2 + cx - (q - d)$$ $$= ax^3 + bx^2 + cx + d - q.$$

When $$f(x) = 0,$$ $$ax^3 + bx^2 + cx + d - q = 0$$ and $$ax^3 + bx^2 + cx + d = q.$$

Let $$ax^2 + Bx + C = 0 \dots\ (1)$$

where $$B = ap + b; C = Bp + c.$$

If point $$(p,q)$$ is any point on the curve of $$y = ax^3 + bx^2 + cx + d,$$ then the solution of $$(1)$$ provides the other values of $$x$$ that produce $$y = q.$$

An example:

Let $$f(x) = \frac{3x^3 - 6x^2 - 3x + 22}{8}$$

It is known that point $$(1,2)$$ satisfies $$y = f(x).$$

Let associated quadratic function $$= g(x) = \frac{3x^2 - 3x - 6}{8}.$$

Roots of $$g(x),\ -1,2,$$ show that when $$x = -1$$ or $$x = 2, f(x) = 2.$$

General case
For function  see isclose.

The following python code implements the functionality of this section: The example above: When 1 root is known: The method works with complex values: Notice complex coefficients: $$B, C = 6+2j, 9+6j.$$

Reporting an error: Notice complex coefficients: $$B, C = -18+9j, 42-90j.$$

Function defined by 4 points
Because the cubic function contains 4 coefficients, 4 simultaneous equations are needed to define the function.

See Figure 1. The cubic function may be defined by any 4 unique points on the curve.

For example, let us choose the four points:

$$(-4,2), (-3,3), (2,3), (8,8)$$

Rearrange the standard cubic function to prepare for the calculation of $$a,b,c,d:$$

$$x^3a + x^2b + xc + 1d - y = 0.$$

For function  see "Solving simultaneous equations".

The 4 coefficients above are in fact the values $$\frac{5}{66}, \frac{-30}{66}, \frac{-65}{66}, \frac{408}{66}.$$

Cubic function defined by the 4 points $$(-4,2), (-3,3), (2,3), (8,8)$$ is $$y = \frac{5x^3 - 30x^2 - 65x + 408}{66}.$$

Function defined by 3 points and 1 slope
The cubic function may be defined by any 3 unique points on the curve and the slope at any 1 of these points.

For example, let us choose the three points:

$$(-4,2), (2,3), (8,8)$$

It is known that the slope at point $$(8,8)$$ is $$6 + \frac{19}{66}.$$

Rearrange the standard cubic function to prepare for the calculation of $$a,b,c,d:$$

$$x^3a + x^2b + xc + 1d - y = 0.$$

Equation of slope: $$s = 3ax^2 + 2bx + c$$

Rearrange the equation of slope to prepare for the calculation of $$a,b,c,d:$$

$$3x^2 a + 2xb + 1c + 0d - s = 0.$$

For function  see "Solving simultaneous equations".

The 4 coefficients above are in fact the values $$\frac{5}{66}, \frac{-30}{66}, \frac{-65}{66}, \frac{408}{66}$$ (same as above.)

If these 4 criteria (3 points and 1 slope) are used to define the cubic in which $$y$$ is the independent variable, result is:

$$x = -0.020819277108433898y^3$$$$ + 0.1873734939759051y^2$$ $$ + 1.1583614457831322y$$$$ - 2.599325301204827.$$

Both curves satisfy the points $$(-4,-3), (2,3), (8,8)$$ and have the same slope at point $$(8,8).$$

(In fact $$f(y) = \frac{-1.728y^3 + 15.552y^2 + 96.144y - 215.744}{83}.$$)

=The simplest cubic function=



The simplest cubic function has coefficients $$b = c = 0$$, for example:

$$y = f(x) = 2x^3 + 54$$.

To solve the equation:

$$2x^3 = -54$$

$$x^3 = \frac{-54}{2} = -27$$

$$x = \sqrt[3]{-27} = -3$$

The function also contains two complex roots that may be found as solutions of the associated quadratic:

$$ax^2 + (ap+b)x + ap^2 + bp + c = 2x^2 + (-6)x + (18) $$$$= x^2 - 3x + 9 = 0$$

$$x = \frac{3 \pm \sqrt{9 - 36}}{2} $$$$= \frac{3 \pm \sqrt{-27}}{2} $$ $$= \frac{3 \pm \sqrt{27}\sqrt{-1}}{2}$$$$= \frac{3 \pm (3\sqrt{3})\sqrt{-1}}{2}$$

Curve $$f(x)$$ is useful for finding the cube root of a real number.

Solve: $$x = \sqrt[3]{N}.$$

$$x^3 = N$$

$$x^3 - N = 0.$$

This is equivalent to finding a root of function $$y = g(x) = x^3 - N.$$

If you use Newton's method to solve $$g(x),$$ it may be advantageous to put $$N$$ in form $$n(10^{3p})$$ where $$1 \le n < 1000.$$

Then $$\sqrt[3]{N} = \sqrt[3]{n}(10^p).$$ Remember to preserve correct sign of result.

=Roots of equal absolute value=

The cubic function $$ax^3 + bx^2 + cx + d\ \dots\ (1)$$

Let one value of $$x$$ be $$p + q$$ and another be $$p - q$$.

Substitute these values into the original function in $$x\ (1)$$ and expand.

$$+ appp + 3appq + 3apqq + aqqq + bpp + 2bpq + bqq + cp + cq + d \ \dots\ (2a)$$

$$+ appp - 3appq + 3apqq - aqqq + bpp - 2bpq + bqq + cp - cq + d \ \dots\ (3a)$$

$$(2a)+(3a), + 2appp + 6apqq + 2bpp + 2bqq + 2cp + 2d \ \dots\ (4)$$

$$(2a)-(3a), + 6appq + 2aqqq + 4bpq + 2cq \ \dots\ (5)$$

Reduce $$(4)$$ and $$(5)$$ and substitute $$Q$$ for $$qq$$:

$$+ 3Qap + Qb + appp + bpp + cp + d \ \dots\ (4a)$$

$$+ Qa + 3app + 2bp + c \ \dots\ (5a)$$

Combine $$(4a)$$ and $$(5a)$$ to eliminate $$Q$$ and produce a function in $$p$$:

$$(- 8aa)p^3+ (- 8ab)p^2+ (- 2ac - 2bb)p+ (+ ad - bc)\ \dots\ (6)$$

From $$(6),\ c0 = ad - bc.$$

If $$c0 == 0,\ p = 0$$ is a solution and function $$(5a)$$ becomes:

$$Qa + c = 0\ \dots\ (5d)$$

$$Q = \frac{-c}{a}$$

$$q = \sqrt{Q}$$ and two roots of $$(1)$$ are $$0 \pm q$$.

An example


See Figure 2.

$$y = x^3 + 2x^2 -9x - 18$$

$$c0 = ad - bc = 1(-18) - 2(-9) = 0.$$

The function has roots of equal absolute value.

$$Q = \frac{-c}{a} = \frac{9}{1} = 9;\ q = \sqrt{Q} = \sqrt{9} = \pm 3$$

The roots of equal absolute value are $$3, -3$$.

This method works with complex roots of equal absolute value.

Consider function: $$y = f(x) = 2x^3 - 11x^2 + 98x - 539$$

$$a, b, c, d = 2, -11, 98, -539$$

$$c_0 = ad - bc = 2(-539) - (-11)98 = - 1078 + 1078 = 0.$$

$$f(x)$$ has roots of equal absolute value.

$$Q = \frac{-c}{a} = \frac{-98}{2} = -49$$

$$q = \sqrt{Q} = \sqrt{-49} = \pm 7i$$

Roots of equal absolute value are: $$7i, -7i.$$

=Equal Roots=

Combine $$4(a)$$ and $$5(a)$$ from above to eliminate $$p$$ and produce a function in $$Q$$:

$$(64aaaaa)Q^4 + $$ $$(160aaaac - 32aaabb)Q^3 + $$ $$(132aaacc - 56aabbc + 4abbbb)Q^2 + $$ $$(27aaadd - 18aabcd + 40aaccc + 4abbbd - 25abbcc + 4bbbbc)Q + $$ $$(27aacdd - 18abccd + 4acccc + 4bbbcd - bbccc)\ \dots\ (8)$$

From $$(8)$$ above: $$C0 = 27aacdd - 18abccd + 4ac^4 + 4b^3cd - bbc^3$$ $$= c(27aadd - 18abcd + 4ac^3 + 4b^3d - bbcc)$$

If $$C0 == 0$$, then $$Q = 0$$ is a solution , $$x = p \pm 0 = p$$ and $$(4a), (5a)$$ become:

$$ax^3 + bx^2 + cx + d\ \dots\ (4e)$$

$$3ax^2 + 2bx + c\ \dots\ (5e)$$

If $$C0 == 0$$ because $$c = 0$$, there is a stationary point where $$x = 0$$.

Note:


 * $$27aadd -18abcd +4accc +4bbbd -bbcc$$ is a factor of discriminant of cubic formula below. If $$C0 == 0$$ because the discriminant is $$0$$, function $$(1)$$ contains at least 2 roots equal to $$x \pm 0$$ when both functions $$(4e), (5e)$$ are $$0$$.


 * $$(4e), (5e)$$ are functions of the curve and the slope of the curve. In other words, equal roots occur where the curve and the slope of the curve are both zero.

$$(4e)$$ and $$(5e)$$ can be combined to produce:

$$(ac)x^2 + (- 3ad + bc)x + (- 2bd + cc)\ \dots\ (4f)$$

$$(3a)x^2 + (2b)x + (c)\ \dots\ (5f)$$

$$(4f)$$ and $$(5f)$$ can be combined to produce:

$$(- 9ad + bc)x + (- 6bd + 2cc)\ \dots\ (4g)$$

$$(+ 6abd - 2acc)x + (- 3acd + 4bbd - bcc)\ \dots\ (5g)$$

If the original function $$(1)$$ contains 3 unique roots, then $$(4g), (5g)$$ are numerically different.

If the original function $$(1)$$ contains exactly 2 equal roots, then $$(4g), (5g)$$ are numerically identical, and the 2 roots have the value $$x$$ in $$(4g)$$.

If the original function $$(1)$$ contains 3 equal roots, then $$(4g), (5g)$$ are both null, $$(4f), (5f)$$ are numerically identical and $$x = \frac{-b}{3a}$$.

From equations (4g) and (5g):

$$-(+ 6abd - 2acc) (- 6bd + 2cc) + (- 3acd + 4bbd - bcc)  (- 9ad + bc)$$ $$= + 27aacdd - 18abccd + 4acccc + 4bbbcd - bbccc$$ $$= C0$$

No equal roots


Consider function $$y = x^3 - 2x^2 - 5x + 6 = (x + 2)(x - 1)(x - 3)$$

from $$4(g),\ x = \frac{-(- 9ad + bc)}{(- 6bd + 2cc)} = \frac{44}{122}$$

from $$5(g),\ x = \frac{-(+ 6abd - 2acc)}{(- 3acd + 4bbd - bcc)} = \frac{122}{236}$$

$$4(g), 5(g)$$ are numerically different.

Exactly 2 equal roots


Consider function $$y = f(x) = x^3 - 3x^2 - 9x - 5 = (x+1)(x+1)(x-5)$$

from $$4(g),\ x = \frac{-72}{72} = -1$$

from $$5(g),\ x = \frac{72}{-72} = -1$$

There are 2 equal roots at $$x = -1.$$

See Function_as_product_of_linear_function_and_quadratic above.

To calculate all roots: Roots of cubic function $$f(x) = x^3 - 3x^2 - 9x - 5$$ are $$-1, -1, 5.$$

3 equal roots


Consider function $$y = x^3 + 9x^2 + 27x + 27 = (x+3)(x+3)(x+3)$$

from $$4(g), x = \frac{0}{0}$$

from $$4(f),\ 27x^2 + 162x + 243 = x^2 + 6x + 9 = 0$$

from $$5(f),\ 3x^2 + 18x + 27 = x^2 + 6x + 9 = 0$$

$$4(f), 5(f)$$ are numerically identical, the discriminant of each is $$0$$ and $$x = \frac{-6}{2} = -3$$

=Depressed cubic=

The depressed cubic may be used to solve the cubic equation.

In the cubic function: $$y = f(x) = ax^3 + bx^2 + cx + d$$ let $$x = \frac{-b+t}{3a}$$, substitute for $$x$$ and expand:

$$y = \frac{t^3 + (9ac - 3bb)t + (27aad - 9abc + 2b^3 )}{27a^2}$$

When the function is equated to $$0$$, the depressed equation is:

$$t^3 + At + B = 0$$ where

$$A = (9ac - 3bb)$$ and

$$B = (27aad - 9abc + 2b^3 )$$

In the depressed equation the coefficient of $$t^3$$ is $$1$$ and the coefficient of $$t^2$$ is $$0$$.

The depressed function is a specific case of the general function in which coefficient $$b$$ is missing.

Let $$y = ax^3 + cx + d.$$

Then point of inflection has coordinates $$(0, d),$$ and $$y' = 3ax^2 + c.$$

When $$x == 0,\ y' = c.$$

If coefficient $$b$$ is missing, the cubic function becomes $$y = ax^3 + cx + d,$$ and


 * point of inflection has coordinates $$(0, d)$$ and


 * slope at point of inflection $$= c.$$

Be prepared for the possibility that one or both of $$A, B$$ may be zero.

6 examples
Six simple depressed cubic functions illustrate all the possible shapes of all cubic functions:

When A = 0


This condition occurs when the cubic function in $$x$$ has exactly one stationary point or when slope at point of inflection is zero.

$$f(x) = 4x^3 - 6x^2 + 3x - 1$$

$$f(t) = t^3 - 216$$

$$t = \sqrt[3]{216} = 6$$

$$x = \frac{-b+t}{3a} = \frac{6+6}{3(4)} = 1$$

The other roots may be derived from the associated quadratic:

$$y = 4x^2 + (4(1) + (-6))x + 4(1)(1) + (-6)(1) + 3 $$$$= 4x^2 - 2x + 1$$

$$x = \frac{2 \pm \sqrt{4-16}}{8} $$ $$= \frac{2 \pm \sqrt{12}\sqrt{-1}}{8} $$ $$= \frac{2 \pm (2\sqrt{3})\sqrt{-1}}{8}$$ $$= \frac{1 \pm \sqrt{3}\sqrt{-1}}{4}$$

When B = 0


This condition occurs when the cubic function in $$x$$ is of format $$(x+g)(x+g+h)(x+g-h)$$ or when point of inflection is on the $$X$$ axis.

$$f(x) = x^3 + 9x^2 + 31x + 39$$

$$f(t) = t^3 + 36t = t(t^2 + 36)$$

$$x = \frac{-b}{3a} = \frac{-9}{3(1)} = -3$$

$$t^2 = -36;\ t = \sqrt{-36} = \sqrt{36(-1)} = \pm6\sqrt{-1}$$

$$x = \frac{-b+t}{3a} = \frac{-9 \pm 6\sqrt{-1}}{3(1)} = -3 \pm 2\sqrt{-1}$$

When A = B = 0

 * point of inflection $$(-3,0)$$ on $$X$$ axis,
 * slope $$0$$ at point of inflection.

This condition occurs when:
 * slope at point of inflection is $$0$$, and
 * point of inflection is on $$X$$ axis.

Consider function $$y = x^3 + 9x^2 + 27x + 27 = (x+3)(x+3)(x+3)$$

$$f(t) = t^3 + (9ac - 3bb)t + (27aad - 9abc + 2b^3 )$$ $$= t^3 + (9\cdot 1\cdot 27 - 3\cdot 9\cdot 9)t + (27\cdot 1\cdot 1\cdot 27 - 9\cdot 1\cdot 9\cdot 27 + 2\cdot 9\cdot 9\cdot 9)$$ $$= t^3 + (0)t + (0)$$

$$x = \frac{-b+t}{3a} = \frac{-b}{3a} = \frac{-9}{3} = -3$$

=Vieta's substitution=

See Vieta's Substitution.

Let the depressed cubic be written as: $$t^3 - 3Ct + B$$ where $$C = b^2 - 3ac$$ and $$A = -3C$$

Let $$t = w + \frac{C}{w} = \frac{w^2 + C}{w}$$

Substitute for $$t$$ in the depressed function:

$$f(w) = w^6 + Bw^3 + C^3$$

$$f(W) = W^2 + BW + C^3$$ where $$W = w^3$$ and $$w = \sqrt[3]{W}$$.

From the quadratic formula: $$W = \frac{-B \pm \sqrt{B^2 - 4C^3}}{2}$$

The discriminant $$= B^2 - 4C^3$$. Substitute for $$B, C$$ and expand:

This discriminant = $$27a^2( 27aadd - 18abcd + 4ac^3 + 4b^3d - bbcc )$$

The factor $$( 27aadd - 18abcd + 4ac^3 + 4b^3d - bbcc )$$ is a factor of $$C0$$ under "Equal Roots" above.

Discriminant (B² - 4C³)
0==



If discriminant $$(B^2 - 4C^3) == 0$$, the function contains at least 2 equal, real roots.

Consider function $$y = x^3 - 3x^2 - 9x - 5 $$$$= (x+1)(x+1)(x-5)$$

$$W = \frac{-B}{2} = 216$$

$$w = \sqrt[3]{216} = 6$$

$$t = w + \frac{C}{w} = 6 + \frac{36}{6} = 12$$

$$x = \frac{-b+t}{3a} = \frac{3+12}{3} = 5$$

Associated quadratic $$= x^2 + (1\cdot 5 + -3)x + (1\cdot 5\cdot5 + -3\cdot 5 + -9) $$ $$= x^2 + 2x + 1 = (x+1)(x+1)$$

The 2 equal roots are: $$(-1,0),(-1,0)$$.

Discriminant (B² - 4C³) positive


If discriminant $$(B^2 - 4C^3)$$ is positive, the function contains exactly 1 real root.

Consider function $$y = x^3 - 3x^2 - 5x - 25$$

discriminant $$= B^2 - 4C^3 = 691200$$

$$r = \sqrt{691200} = 831.3843876330611$$

$$W = \frac{-B+r}{2} = 847.6921938165306$$

$$w = \sqrt[3]{W} = 9.464101615137753$$

$$t = w + \frac{C}{w} = 12$$

or:

$$W = \frac{-B-r}{2} = 16.307806183469438$$

$$w = \sqrt[3]{W} = 2.5358983848622447$$

$$t = w + \frac{C}{w} = 12$$

$$x = \frac{-b+t}{3a} = 5$$

The associated quadratic is: $$x^2 + (1\cdot 5 + -3)x + (1\cdot 5\cdot 5 + -3\cdot 5 + -5) = x^2 + 2x + 5$$

and the two complex roots are: $$\frac{-2 \pm \sqrt{ 4-20 }}{2} $$ $$= \frac{-2 \pm 4\sqrt{-1}}{2}$$ $$= -1 \pm 2\sqrt{-1}$$

Discriminant (B² - 4C³) negative
If discriminant $$(B^2 - 4C^3)$$ is negative, the function contains 3 real roots and $$W$$ becomes the complex number $$\frac{-B}{2} \pm \frac{\sqrt{4C^3 - B^2}}{2}\sqrt{-1}$$.

Let $$W_{mod}$$ be the modulus of $$W$$.

Let $$W_{real}$$ be the real part of $$W$$.

Let $$W_{imag}$$ be the imaginary part of $$W$$.

Then $$W_{real} = \frac{-B}{2}$$

$$W_{imag} = \frac{\sqrt{4C^3 - B^2}}{2}$$

$$W_{mod}^2 = W_{real}^2 + W_{imag}^2 = \frac{B^2}{4} + \frac{4C^3 - B^2}{4} = C^3.$$

$$W_{mod} = \sqrt{C^3}$$

Let $$W_{\phi}$$ be the phase of $$W$$.

Then $$\cos W_{\phi} = \frac{W_{real}}{W_{mod}}$$ and $$W_{\phi} = \arccos ( \cos W_{\phi} )$$.

$$w = \sqrt[3]{W}$$. Therefore:

$$w_{mod} = \sqrt[3]{W_{mod}} = \sqrt{C}$$

$$w_{\phi} = \frac{W_{\phi}}{3}$$

$$w_{real} = w_{mod} * \cos(w_{\phi})$$

$$t = 2*w_{real}$$

An example


$$y = f(x) = x^3 - 2x^2 - 5x + 6$$ in which $$a,b,c,d = 1,-2,-5,6.$$

$$B = 56$$

$$C = 19$$

$$W_{real} = \frac{-B}{2} = -28$$

$$W_{mod} = \sqrt{C^3} = 82.8190799272728$$

$$\cos W_{\phi} = \frac{W_{real}}{W_{mod}} = -0.338086344651354$$

$$W_{\phi} = 1.91567908829702$$ radians.

$$w_{\phi} = \frac{W_\phi}{3} = 0.638559696099005$$ radians.

$$\cos w_{\phi} = 0.802955068546966$$

$$w_{mod} = \sqrt{C} = 4.35889894354067$$

$$w_{real} = w_{mod} * \cos w_{\phi} = 3.5$$

$$t = 2 * w_{real} = 7$$

$$x = \frac{-b+t}{3a} = 3$$

Using Cosine (A/3)
For function  see  "Cosine(A/3)".

Results are:

=Review of complex math=





A complex number contains a real part and an imaginary part, eg: $$\sqrt{2} + \sqrt{2}\sqrt{-1}.$$

In theoretical math the value $$\sqrt{-1}$$ is usually written as $$i$$. In the field of electrical engineering and computer language Python it is usually written as $$j$$.

The value $$\sqrt{2} + \sqrt{2}\sqrt{-1}$$ is a complex number expressed in rectangular format.

The value $$w = 2(\cos 45^\circ + \sqrt{-1}\sin 45^\circ )$$ is a complex number expressed in polar format where $$2$$ is the modulus of $$w$$ or $$w_{mod}$$ and $$45$$ is the phase of $$w$$ or $$w_{\phi}.$$

$$2(\cos 45^\circ + \sqrt{-1}\sin 45^\circ )$$ $$= 2(\frac{\sqrt{2}}{2} + \sqrt{-1}\frac{\sqrt{2}}{2} )$$ $$= \sqrt{2} + \sqrt{-1}\sqrt{2} )$$

Multiplication of complex numbers
$$p(\cos A + i\sin A)q(\cos B + i\sin B)$$ $$= pq(\cos A \cos B + \cos A i\sin B + i\sin A \cos B + i^2 \sin A \sin B)$$ $$= pq( \cos A \cos B - \sin A \sin B + i ( \sin A \cos B + \cos A \sin B ) )$$ $$= pq( \cos(A+B) + i\sin(A+B) )$$

To multiply complex numbers, multiply the moduli and add the phases.

Complex number cubed
$$(p( \cos A + i \sin A ))^3$$ $$= p( \cos A + i \sin A )p( \cos A + i \sin A )p( \cos A + i \sin A )$$ $$= p^2( \cos 2A + i \sin 2A )p( \cos A + i \sin A )$$ $$= p^3( \cos 2A \cdot \cos A + \cos 2A \cdot i \cdot \sin A  + i \cdot\sin 2A \cdot\cos A + i \cdot\sin 2A \cdot i \cdot\sin A )$$ $$= p^3( \cos 2A \cdot \cos A + i^2 \cdot\sin 2A \cdot\sin A  + i(\cos 2A \cdot  \sin A   + \sin 2A \cdot\cos A) )$$ $$= p^3( (\cos 2A \cdot \cos A -\sin 2A \cdot\sin A)  + i( \sin 2A \cdot\cos A + \cos 2A \cdot  \sin A) )$$ $$= p^3( \cos 3A + i \sin 3A )$$

Generally $$(p( \cos A + i \sin A ))^n$$ $$= p^n( \cos (nA) + i \sin (nA) ).$$

For the cube of a complex number in polar format, $$n = 3.$$

Cube root of complex number W
Let $$W = W_{mod}(\cos W_{\phi} + \sqrt{-1} \sin W_{\phi})$$ and $$w = w_{mod}(\cos w_{\phi} + \sqrt{-1} \sin w_{\phi})$$

If $$w = \sqrt[3]{W}$$ then:

$$w_{mod} = \sqrt[3]{W_{mod}}$$ and

$$w_{\phi} = \frac{W_{\phi}}{3}.$$

Complex number w + C/w
Let $$w = k + mi$$ where $$k = w_{real}, m = w_{imag}.$$

$$w + \frac{C}{w} = \frac{ k(C + k^2 + m^2) + im(k^2 + m^2 - C)}{k^2 + m^2}$$

If $$k^2 + m^2 == C:$$

$$w + \frac{C}{w} = \frac{ k(C + C) + im(C - C)}{C} = \frac{2Ck}{C} = 2k$$

In the case of 3 real roots, $$t = 2\cdot w_{real}$$

=Cubic formula=

The substitutions made above can be used to produce a formula for the solution of the cubic equation.

Given cubic equation: $$y = f(x) = ax^3 + bx^2 + cx + d = 0,$$ calculate the 3 values of $$x.$$

$$x = \frac{-b + t}{3a}$$ where:

Coefficients of depressed cubic:

$$A = 9ac - 3b^2$$

$$B = 27a^2d - 9abc + 2b^3$$

One root of cubic function:

$$C = \frac{-A}{3} = b^2 - 3ac$$

$$\Delta = B^2 - 4C^3$$

$$\delta = \sqrt{\Delta}$$

$$W = \frac{-B + \delta}{2}$$

$$w = \sqrt[3]{W}$$

$$t = w + \frac{C}{w}$$

Formula incorporating all eight statements above is:

$$x = \frac{-b+\sqrt[3]{\frac{-(27a^2d-9abc+2b^3)+\sqrt{(27a^2d-9abc+2b^3)^2-4(b^2-3ac)^3}}{2}}+\frac{(b^2-3ac)}{\sqrt[3]{\frac{-(27a^2d-9abc+2b^3)+\sqrt{(27a^2d-9abc+2b^3)^2-4(b^2-3ac)^3}}{2}}}}{3a}$$

Cube roots of unity are: $$1,\ -\cos 60^\circ \pm i \sin 60^\circ.$$ See "Cube roots of 1."

Therefore $$\sqrt[3]{W}$$ has 3 values:

$$w_1 = w$$

$$w_2 = w\cdot \frac{-1 + i\sqrt{3}}{2}$$

$$w_3 = w\cdot \frac{-1 - i\sqrt{3}}{2}$$

It is not necessary to use both values of $$\pm \delta.$$

Choose either $$W = \frac{-B + \delta}{2}$$ or $$W = \frac{-B - \delta}{2}.$$

If $$f(x)$$ contains 3 equal roots, $$A=B=0$$ and line  fails with divisor $$w = 0.$$

Before using this formula, check for equal roots as in "3 equal roots" above.

2 equal roots
Calculate roots of $$f(x) = x^3 - 7x^2 - 5x + 75.$$

Notice that:


 * $$\Delta$$ is zero.


 * $$W = \frac{-B}{2}.$$


 * $$t = 2\cdot w_{real}.$$

1 real root
Calculate roots of $$f(x) = x^3 - 7x^2 - x + 87.$$

Notice that:


 * $$\Delta$$ is positive.


 * $$W = \frac{-B + \delta}{2}.$$


 * $$t$$ does not equal $$2 \cdot w_{real}.$$

3 real roots
Calculate roots of $$f(x) = 5x^3 - 62x^2 + 11x + 726.$$

Notice that:


 * $$\Delta$$ is negative


 * $$W = \frac{-B - \delta}{2}.$$


 * $$t$$ equals $$2 \cdot w_{real}.$$

=cos (A/3)=

The method above for calculating $$\cos w_{\phi}$$ depends upon calculating the value of angle $$w_{\phi}.$$

However, $$\cos w_{\phi}$$ may be calculated from $$\cos W_{\phi}$$ because $$w_{\phi} = \frac{W_{\phi}}{3}.$$

Generally, when $$\cos A$$ is known, there are 3 possible values of the third angle because $$\cos 3(\frac{A}{3} \pm 120^\circ) = \cos( A \pm 360^\circ ) = \cos(A).$$

This suggests that there is a cubic relationship between $$\cos \frac{A}{3}$$ and $$\cos A.$$

Expansion of cos (3A)


The well known identity for $$\cos 3A$$ is:

$$\cos 3A = 4 \cos^3 A - 3 \cos A.$$

The derivation of this identity may help understanding and interpreting the curve of $$\cos 3A.$$

Let $$\cos 3A = a \cos^3A + b \cos^2 A + c \cos A + d.$$

$$\cos 90^\circ = 0$$ and $$\cos 270^\circ = 0$$

Therefore the point $$(0,0)$$ is on the curve and $$d = 0.$$

Three simultaneous equations may be created from the above table:

$$1 = 1a + 1b + 1c$$

$$-1 = -1a + 1b - 1c$$

Therefore $$b = 0.$$

$$1 = 1a + 1c$$

$$-1 = \frac{a}{8} + \frac{c}{2}$$

$$a = 4$$ and $$c = -3.$$

When $$\cos 3A$$ is known, $$4\cos^3 A - 3\cos A - \cos 3A = 0.$$

Newton's Method


Newton's method is a simple and fast root finding method that can be applied effectively to the calculation of $$\cos A$$ when $$\cos 3A$$ is known because:


 * the function is continuous in the area under search.
 * the derivative of the function is continuous in the area under search.
 * the method avoids proximity to stationary points.
 * a suitable starting point is easily chosen.

See Figure 7b.

Perl code used to calculate $$\cos A$$ when $$\cos 3A = 0.1$$ is:

When cos(3A) is positive


When $$\cos (3A) = 0.4,$$ output of the above code is:

If all 3 values of $$\cos A$$ are required, the other 2 values can be calculated as roots of the associated quadratic function with coefficients $$(a1,b1,c1) = (4, 4cosA, 4cos^2A - 3)$$

Proof: Results:

When cos(3A) is negative


When $$\cos 3A$$ is negative, the starting value of $$x = -1.$$

When $$\cos 3A = -0.2,$$ output of the above code is:

An example


$$y = f(x) = x^3 - 2x^2 - 5x + 6$$ in which $$a,b,c,d = 1,-2,-5,6.$$

$$B = 56$$

$$C = 19$$

$$W_{real} = \frac{-B}{2} = -28$$

$$W_{mod} = \sqrt{C^3} = 82.8190799272728$$

$$\cos W_{\phi} = \frac{W_{real}}{W_{mod}} = -0.338086344651354$$

Use the code beside Figure 7b above with initial conditions:

$$\cos w_{\phi} = -0.917662935482248$$

$$w_{mod} = \sqrt{C} = 4.35889894354067$$

$$w_{real} = w_{mod} * \cos w_{\phi} = -4$$

$$t = 2 * w_{real} = -8$$

$$x = \frac{-b+t}{3a} = -2$$

=Point of Inflection=

The Point of Inflection is the point at which the slope of the curve is minimum.

After taking the first and second derivatives value $$x$$ at point of inflection is:

$$x_{poi} = \frac{-b}{3a}.$$

The slope at point of inflection is:

$$s_{poi} = \frac{3ac - b^2}{3a}.$$

Value $$y$$ at point of inflection is:

$$y_{poi} = \frac{2b^3 - 9abc + 27a^2d}{27a^2}.$$

From basic principles


$$x_{poi}$$ may be calculated from basic principles.

Let us define the point of inflection as the point about which the curve is symmetric.

Let $$x_{poi} = X$$ and let $$p$$ be non-zero.

Then $$Y = aX^3 + bX^2 + cX + d$$ where $$(X, Y)$$ is point of inflection.

Let $$X_p = X + p$$ and $$X_n = X - p.$$

Then $$Y_p = a(X_p)^3 + b(X_p)^2 + c(X_p) + d$$

$$= XXXa + 3XXap + XXb + 3Xapp + 2Xbp + Xc + appp + bpp + cp + d.$$

Let $$d_p$$ be $$Y_p$$ relative to $$Y.$$

Then $$d_p = Y_p - Y = 3XXap + 3Xapp + 2Xbp + appp + bpp + cp.$$

Similarly $$d_n = Y - Y_n = 3XXap - 3Xapp + 2Xbp + appp - bpp + cp.$$

$$d_p   =   d_n$$ therefore:

$$3XXap + 3Xapp + 2Xbp + appp + bpp + cp $$ $$= 3XXap - 3Xapp + 2Xbp + appp - bpp + cp$$

$$ + 3Xapp + bpp  =  - 3Xapp  - bpp $$

$$ + 3Xa + b  =  - 3Xa  - b $$

$$ + 3Xa + b  + 3Xa + b  = 0$$

$$ + 3Xa + b   = 0$$

$$X = \frac{-b}{3a}$$

Depressed cubic
Recall from "Depressed cubic" above:

$$A = 9ac - 3b^2$$

$$B = 27a^2d - 9abc + 2b^3$$

Therefore:

$$s_{poi} = \frac{A}{9a}$$

$$y_{poi} = \frac{B}{27a^2}$$

Coefficients $$A, B$$ of the depressed cubic show immediately:


 * If slope at point of inflection is positive, zero or negative, and


 * If point of inflection is above, on or below X axis.

If 1 of $$A, B$$ is zero, the cubic equation may be solved as under "Depressed cubic" above.

=Newton's Method=

If both $$A,B$$ of the depressed function are non-zero, Newton's method may be applied to the original cubic function, and the Point of Inflection offers a convenient starting point.

When implemented as described below, Newton's Method always avoids that part of the curve where there might be equal roots.

slope at PoI positive


$$A = 0.36$$

$$B = 0.0864$$

$$x_{poi} = -3$$

$$s_{poi} = 1$$

$$y_{poi} = 2$$

PoI above X axis


$$A = -2.25$$

$$B = 0.54$$

$$x_{poi} = -3$$

$$s_{poi} = -2.5$$

$$y_{poi} = 2$$

When $$y == y_{poi},$$ the other 2 intercepts may be calculated as roots of the associated quadratic with coefficients:

$$(a_1,\ b_1,\ c_1) $$ $$= (a,\ ax_{poi} + b,\ ax_{poi}^2 + bx_{poi} + c)$$ $$= (0.1, 0.6, -1.6).$$

$$(x_{1a}, x_{1b}) = (-8,2).$$

The figure shows all possible considerations if point of inflection is above $$X$$ axis.

The same technique using Newton's Method works well with all conditions.

PoI below X axis


$$A = -2.25$$

$$B = -1.35$$

$$x_{poi} = 2$$

$$s_{poi} = -2.5$$

$$y_{poi} = -5$$

When $$y == y_{poi},$$ the other 2 intercepts may be calculated as roots of the associated quadratic with coefficients:

$$(a_1,\ b_1,\ c_1) $$ $$= (0.1, -0.4, -2.1).$$

$$(x_{1a}, x_{1b}) = (-3,7).$$

The figure shows all possible considerations if point of inflection is below $$X$$ axis.

The same technique using Newton's Method works well with all conditions.

Using Newton's method
The method used to solve the cubic equation (as presented here) depends on the value of the discriminant (B² - 4C³). If this value is non-negative, the value of 1 root is easily calculated and the other 2 roots are solutions of the associated quadratic described under "linear and quadratic" above. If this value is negative, the use of this value leads to some interesting theory of complex numbers and the solution depends on the calculation of $$\cos \frac{\theta}{3}.$$

The method above uses Newton's method to calculate $$\cos \theta$$ from $$\cos (3\theta).$$ Newton's method is very fast and more than adequate to do the job. However, the purist might say that the solution of a cubic equation must not depend on the solution of a cubic equation. The solution offered under "Cosine(A/3)" above satisfies the purist.

Also, if you're going to use Newton's method to calculate $$\cos \frac{\theta}{3},$$ why not use Newton's method to calculate one real root of the original cubic?

One of the objectives above is to show that the cubic equation can be solved with high school math. Newton's method can be implemented with a good knowledge of high school calculus and the starting point may depend on the solution of a quadratic equation, also understood with a good knowledge of high school algebra.

The example presented below shows how to solve the cubic equation with high school math.

For function  see  General_case above.

Calculate roots of cubic function: $$y = f(x) = 2x^3 - 33x^2 - 6164x - 65760.$$

$$s_{poi}$$ is negative. $$x_{poi}$$ will not be used as starting point.

The associated quadratic when $$p = x_{poi}:$$

Find 2 possible starting points $$(x_{11},\ x_{12})$$ to left and right of $$x_{poi}.$$

Execute newton's method:

The starting point $$(x =$$ start$$)$$ is close to $$x_1,$$ which was found quickly.

If only one root is required (as in calculation of roots of quartic function), $$x_1$$ may be used, in which case calculations below are not necessary. The big advantage of using $$x_1$$ is that $$x_1$$ is guaranteed to be a real number.

The associated quadratic when $$p = x_1:$$

In practice
Much interesting theory concerning complex numbers and Vieta's substitution has been presented above. The formula for $$x,$$ a root of the cubic equation, is already appearing to be too complicated. Using the formula usually involves calculation of square root and cube root, possibly a complex cube root. How are these values calculated? Possibly by using Newton's method.

Every cubic function is guaranteed to contain at least one real root. The function below, is an attempt at almost extreme simplicity. Considerations such as equal roots or complex cube root are ignored. After a few simple decisions, Newton's method is used to derive one real root of the given cubic.

For function  see  General case above.

For function  see  Implementation.

=Translation of axes=

Cubic function relative to (u,v)
The familiar equation of the cubic function: $$y = f(x) = ax^3 + bx^2 + cx + d.$$ This is the equation of $$f(x)$$ relative to origin $$(0,0).$$ However, $$f(x)$$ need not be constrained as always relative to origin. It is always possible, and sometimes desirable, to express $$f(x)$$ relative to any other point $$(u,v)$$ in the two dimensional plane. The process of producing a new function $$g(x)$$ that is $$f(x)$$ relative to $$(u,v)$$ is called "Translation of axes."

On this page the point of reference of any cubic function is the point of inflection.

Point of inflection of $$f(x)$$ (red curve) is $$(0,0).$$ Relative to point $$(-6,-2)$$ red curve is located at $$(6,2).$$ Relative to $$(0,0)$$ blue curve is located at $$(6,2)$$ and equation of blue curve is $$y-2 = (x-6)^3 - 4(x-6)$$ or $$y = x^3 - 18x^2 + 104x - 190.$$

Equation of $$f(x)$$ relative to $$(-6,-2)$$ is: $$y = x^3 - 18x^2 + 104x - 190.$$


 * $$y + v = f(x+u).$$

$$y = Ax^3 + Bx^2 + Cx + D$$ where:

$$A = a$$

$$B = 3au + b$$

$$C = 3au^2 + 2bu +c$$

$$D = au^3 + bu^2 +cu + d - v$$

Move cubic function to (u,v)
When a cubic function is moved to point $$(u,v),$$ the point of inflection is moved from present position $$(x_{poi}, y_{poi})$$ to $$(u,v),$$ and the amount of movement is:

$$\Delta x = u - x_{poi}$$

$$\Delta y = v - y_{poi}.$$

Equation of function after being moved is:

$$y - \Delta y = f(x - \Delta x),$$ or $$y = Ax^3 + Bx^2 + Cx + D$$ where:

$$x_{poi} = \frac{-b}{3a}$$

$$y_{poi} = a x_{poi}^3 + b x_{poi}^2 + c x_{poi} + d$$

$$A = a$$

$$B = -3a\Delta x + b$$

$$C = 3a\Delta x^2 - 2b \Delta x + c$$

$$D = -a\Delta x^3 + b \Delta x^2 - c\Delta x + d + \Delta y.$$

Describing a cubic function
Given a random cubic function, particularly those with large coefficients, it's usually difficult to visualize the function. One way to simplify our perception of a random cubic function is to consider the function at origin $$(0,0).$$ This can be done by:


 * moving function to $$(0,0),$$ or


 * calculating equation of function relative to point of inflection $$(x_{poi},y_{poi}).$$

Consider function $$y = f(x) = x^3 - 214035x^2 + 15270327066x - 363153827650064.$$

Point of inflection is $$(71345,96456).$$

Equation of $$f(x)$$ relative to point of inflection is:

$$y = g(x) = x^3 - 9x.$$ See red curve in diagram.

$$f(x)$$ may be described as $$g(x)$$ moved to point $$(71345,96456).$$