# 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.
Characteristics of cubic functions
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
Graph of cubic function with coefficient a negative. There is no absolute maximum or absolute minimum.
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
Graph of cubic function with coefficient b missing.
Sum of roots is $0.$
$Y$axis compressed for clarity.
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
Graph of cubic function with 2 stationary points.
Ratio of $r$ to $x_{2}={\frac {\sqrt {3}}{3}}$
Ratio of $q$ to $x_{1}={\frac {\sqrt {3}}{3}}$
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
Graph of cubic function with 2 stationary points.
$(q,f(q)),(r,f(r))$ are stationary points.
$f(s)=f(q).$
Therefore, $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.$
Graph of cubic function and associated quadratic function.
All values of $x$ that produce $f(x)=2.$
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 allequal, see
isclose.
The following python code implements the functionality of this section:
# python code.
TwoRootsOfCubicDebug = 0
def TwoRootsOfCubic (abcd, x1) :
x2,x3 = TwoRootsOfCubic (abcd, x1)
f(x2) = f(x3) = f(x1)
If x1 is a root, then f(x2) = f(x3) = f(x1) = 0, and x2,x3 are roots.
x1 may be complex.
a,b,c,d = abcd
B = a*x1 + b
C = B*x1 + c
disc = B*B - 4*a*C
almostZero = 1e-15
if abs(disc) < almostZero :
x2 = x3 = -B/(2*a)
else :
if isinstance (disc, complex) or (disc > 0) :
root = disc ** .5
else :
root = ((-disc) ** .5)*1j
x2 = (-B - root)/(2*a)
x3 = (-B + root)/(2*a)
if not TwoRootsOfCubicDebug : return x2,x3
sum1,sum2,sum3 = [ (a*x*x*x + b*x*x + c*x + d) for x in (x1,x2,x3) ]
print ('TwoRootsOfCubic:')
print (' y = (',a,')xx + (',B, ')x + (', C, ')')
print (' for x1 =',x1,', sum1 =',sum1)
print (' for x2 =',x2,', sum2 =',sum2)
print (' for x3 =',x3,', sum3 =',sum3)
# sum1,sum2,sum3 should all be equal.
# In practice there may be small rounding errors.
# The following check allows for small errors, but flags
# errors that are not "small".
allEqualDebug = 1
allEqual((sum1,sum2,sum3))
return x2,x3
The example above:
# python code.
print ( TwoRootsOfCubic ((3,-6,-3,22), 1) )
print ( TwoRootsOfCubic ((3,-6,-3,22), -1) )
print ( TwoRootsOfCubic ((3,-6,-3,22), 2) )
(-1.0, 2.0)
(1.0, 2.0)
(-1.0, 1.0)
When 1 root is known:
# python code.
print ( TwoRootsOfCubic ((1,-2,-5,6), 1) )
print ( TwoRootsOfCubic ((1,-3,-9,-5), 5) )
(-2.0, 3.0)
(-1.0, -1.0)
The method works with complex values:
# python code.
TwoRootsOfCubicDebug = 1
print ( TwoRootsOfCubic ((1,0,0,27), -3) )
print ( TwoRootsOfCubic ((1,9,31,39), -3+2j) )
TwoRootsOfCubic:
y = ( 1 )xx + ( -3 )x + ( 9 )
for x1 = -3 , sum1 = 0
for x2 = (1.5-2.598076211353316j) , sum2 = 0j
for x3 = (1.5+2.598076211353316j) , sum3 = 0j
((1.5-2.598076211353316j), (1.5+2.598076211353316j))
TwoRootsOfCubic:
y = ( 1 )xx + ( (6+2j) )x + ( (9+6j) )
for x1 = (-3+2j) , sum1 = 0j
for x2 = (-3-2j) , sum2 = 0j
for x3 = (-3+0j) , sum3 = 0j
((-3-2j), (-3+0j))
Notice complex coefficients: $B,C=6+2j,9+6j.$
Reporting an error:
print(TwoRootsOfCubic ((3,-6,-3,22), -4+3j))
TwoRootsOfCubic:
y = ( 3 )xx + ( (-18+9j) )x + ( (42-90j) )
for x1 = (-4+3j) , sum1 = (124+486j)
for x2 = (0.264468373145825-5.338376386119454j) , sum2 = (124.00000000000007+485.9999999999998j)
for x3 = (5.735531626854176+2.338376386119455j) , sum3 = (124.00000000000017+486.0000000000003j)
allEqual6: 2 values not close. (124.00000000000007+485.9999999999998j) , (124.00000000000017+486.0000000000003j)
abs(a-b) = 5.211723197616109e-13
comparison = 5.015695365550026e-13
((0.264468373145825-5.338376386119454j), (5.735531626854176+2.338376386119455j))
Notice complex coefficients: $B,C=-18+9j,42-90j.$
Function defined by 4 points
Figure 1. Cubic function defined by 4 points Any 4 points on the curve may be used to define the function.
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^{3}a+x^{2}b+xc+1d-y=0.$
For function solveMbyN see
"Solving simultaneous equations" .
# python code
points = ((-4,-2), (-3,3), (2,3), (8,8))
L11 =
for point in points :
x,y = point
L11 += [[x*x*x, x*x, x, 1, -y]]
print (L11)
[[-27, 9, -3, 1, -3], #
[-64, 16, -4, 1, 2], # matrix supplied to function solveMbyN below.
[ 8, 4, 2, 1, -3], # 4 rows by 5 columns.
[512, 64, 8, 1, -8]] #
# python code
output = solveMbyN(L11)
print (output)
# 4 coefficients a, b, c, d:
(0.07575757575757577, -0.4545454545454544, -0.9848484848484848, 6.181818181818182)
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^{3}a+x^{2}b+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 solveMbyN see
"Solving simultaneous equations" .
# python code
points = ((-4,-2), (2,3), (8,8))
L11 =
for point in points :
x,y = point
L11 += [[x*x*x, x*x, x, 1, -y]]
(x,y) = (8,8)
L11 += [[3*x*x, 2*x, 1, 0, -(6 + 19/66)]]
print (L11)
[[-64, 16, -4, 1, 2],
[ 8, 4, 2, 1, -3], # matrix supplied to function solveMbyN below.
[512, 64, 8, 1, -8], # 4 rows by 5 columns.
[192, 16, 1, 0, -6.287878787878788]]
# python code
output = solveMbyN(L11)
print (output)
# 4 coefficients a, b, c, d:
(0.07575757575757572, -0.4545454545454543, -0.9848484848484839, 6.181818181818179)
The 4 coefficients above are in fact the values
${\frac {5}{66}},{\frac {-30}{66}},{\frac {-65}{66}},{\frac {408}{66}}$
(same as above.)
Graphs of 2 different cubic functions that satisfy the same 4 criteria.
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

* Figure 1. The simplest cubic function has coefficients $b=c=0.$
* 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\leq 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
Figure 2. The roots of equal absolute value are $3,-3.$
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

* 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.

# Depressed cubic

* 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.$

# 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^{3}d-bbcc)$
The factor $(27aadd-18abcd+4ac^{3}+4b^{3}d-bbcc)$ is a factor of $C0$ under
"Equal Roots" above.
Discriminant (B² - 4C³) == 0
Figure 5a. Cubic function with 2 equal, real roots at $(-1,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\cdot 5+-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
Figure 5b. Cubic function with discriminant $(B^{2}-4C^{3})$ positive and 1 real root at $(5,0)$.
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
Figure 5c. Cubic function with 3 unique, real roots at $(-2,0),(1,0),(3,0)$.
$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 cosAfrom_cos3A see "Cosine(A/3)" .
# python code
from decimal import *
getcontext.prec = 40
a,b,c,d = [ Decimal(v) for v in (1,-2,-5,6) ]
A = 9*a*c - 3*b*b
B = 27*a*a*d - 9*a*b*c + 2*b*b*b
C = A/-3
Wreal = -B/2
wmod = C.sqrt
Wmod = wmod * wmod * wmod
cosWφ = Wreal/Wmod
data = cosAfrom_cos3A(cosWφ)
for coswφ in data :
wreal = wmod * coswφ
t = 2*wreal
x = (-b+t)/(3*a)
print ('x =', float(x))
Results are:
x = 3.0
x = -2.0
x = 1.0 :

# Review of complex math

* Figure 6a: Components of complex number Z.
* Origin at point $(0,0)$.
* $Z_{real}$ parallel to $X$ axis.
* $Z_{imag}$ parallel to $Y$ axis.
* $r=abs(Z)=Z_{mod}$ = modulus of $Z$$={\sqrt {Z_{real}^{2}+Z_{imag}^{2}}}$
* Angle $\phi$ is the phase of $Z=\arctan {\frac {Z_{imag}}{Z_{real}}}$$$
* $Z=r(\cos \phi +{\sqrt {-1}}\sin \phi )=Z_{real}+{\sqrt {-1}}Z_{imag}$
* Figure 6b: Complex numbers $W$ and $w$.
* Origin at point $(0,0)$.
* $W_{imag}={\frac {\sqrt {4C^{3}-B^{2}}}{2}}$ (off image to left.)
* $w^{3}=(w_{mod}(\cos w_{\phi }+i\sin w_{\phi }))^{3}$
* $=w_{mod}^{3}(\cos(3w_{\phi })+i\sin(3w_{\phi }))$
* $=W_{mod}(\cos W_{\phi }+i\sin W_{\phi })=W$
* 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 Ai\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

* Coefficients of depressed cubic:
* $A=9ac-3b^{2}$
* $B=27a^{2}d-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^{2}d-9abc+2b^{3})+{\sqrt {(27a^{2}d-9abc+2b^{3})^{2}-4(b^{2}-3ac)^{3}}}}{2}}}+{\frac {(b^{2}-3ac)}{\sqrt[{3}]{\frac {-(27a^{2}d-9abc+2b^{3})+{\sqrt {(27a^{2}d-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 t = w + C/w fails with divisor $w=0.$
* Before using this formula, check for equal roots as in "3 equal roots" above.

# 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)
Figure 7a.
Graph 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 ^{3}A+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.$
A3Acos Acos 3A
0011
180180*3-l-1
601800.5-1
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
Figure 7b.
Newton's Method used to calculate $\cos A$ when $\cos 3A=0.1.$
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:
$cos3A = 0.1;
$x = 1; # starting point.
$y = 4*$x*$x*$x - 3*$x - $cos3A;
while(abs($y) > 0.00000000000001){
$s = 12*$x*$x - 3; # slope of curve at x.
$delta_x = $y/$s;
$x -= $delta_x;
$y = 4*$x*$x*$x - 3*$x - $cos3A;
print "
x=$x
y=$y
print "
cos(A) = $x
x=0.9
y=0.116
x=0.882738095238095
y=0.00319753789412588
x=0.882234602936352
y=2.68482638085543e-06
x=0.882234179465815
y=1.89812054962601e-12
x=0.882234179465516
y=-3.60822483003176e-16
cos(A) = 0.882234179465516
When cos(3A) is positive
Figure 7c.
Newton's Method used to calculate $\cos A$ when $\cos 3A=0.4.$
When $\cos(3A)=0.4,$ output of the above code is:
x=0.933333333333333
y=0.0521481481481486
x=0.926336712383224
y=0.000546900278781126
x=0.926261765753783
y=6.24370847246425e-08
x=0.926261757195518
y=7.7715611723761e-16
cos(A) = 0.926261757195518
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^{2}A-3)$
x1 = -0.136742508909433
x2 = -0.789519248286085
Proof:
# python code
values = (0.926261757195518, -0.136742508909433, -0.789519248286085)
for cosA in values :
cos3A_ = 4*cosA*cosA*cosA - 3*cosA
difference = abs (cos3A_ - 0.4)
print ('cosA =',cosA,' difference =',difference)
Results:
cosA = 0.926261757195518 difference = 7.771561172376096e-16
cosA = -0.136742508909433 difference = 1.7208456881689926e-15
cosA = -0.789519248286085 difference = 2.1094237467877974e-15
When cos(3A) is negative
Figure 7d.
Newton's Method used to calculate $\cos A$ when $\cos 3A=-0.2.$
When $\cos 3A$ is negative, the starting value of $x=-1.$
When $\cos 3A=-0.2,$ output of the above code is:
x=-0.911111111111111
y=-0.0920054869684496
x=-0.89789474513884
y=-0.00190051666894692
x=-0.897610005610658
y=-8.73486682706481e-07
x=-0.89760987462259
y=-1.8446355554147e-13
x=-0.897609874622562
y=-1.66533453693773e-16
cos(A) = -0.897609874622562
An example
Figure 7e.
Cubic function with 3 unique, real roots at $(-2,0),(1,0),(3,0)$.
$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:
$cosWphi = -0.338086344651354;
$cos3A = $cosWφ;
$x = -1; # starting point.
$\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^{2}d}{27a^{2}}}.$
From basic principles
Figure 1. 4 points relative to point of inflection.
Relative to point of inflection $(2,3)$:
Points $(-3,3),(7,3)$ have coordinates $(-5,0),(5,0)$.
Points $(-4,-2),(8,8)$ have coordinates $(-6,-5),(6,5)$.
When 2 points are equidistant in terms of $X,$ they are also equidistant in terms of $Y.$
$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^{2}d-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

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

# Translation of axes
## Cubic function relative to (u,v)

* Graphs of 2 cubic functions with same shape.
* Red curve relative to point $(-6,-2)$ is same as blue curve relative to $(0,0).$
* 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)

* Graphs of 2 cubic functions with same shape.
* Red curve moved to $(12,7)$ has equation $y=x^{3}-36x^{2}+428x-1673.$
* Blue curve moved to $(3,4)$ has equation $y=x^{3}-9x^{2}+23x-11.$
* 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}=ax_{poi}^{3}+bx_{poi}^{2}+cx_{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

* Graph of complicated cubic function simplified.
* 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).$