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 edit

 
  • 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 edit

Introduction edit

The cubic function is the sum of powers of   from   through  :

 

usually written as:

 

If   the function becomes  

Within this page we'll say that:

  • both coefficients   must be non-zero,
  • coefficient   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:

 .

Roots of the function are values of   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 edit

Coefficient c missing edit

 

If coefficient   is missing, the cubic function becomes   and

 

For a stationary point  

When coefficient   is missing, there is always a stationary point at  

x = f(y) edit

 

The cubic function may be expressed as  

Unless otherwise noted, references to "cubic function" on this page refer to function of form  

Coefficient a negative edit

 
Graph of cubic function with coefficient a negative.
There is no absolute maximum or absolute minimum.

Coefficient   may be negative as shown in diagram.


As   increases, the value of   is dominated by the term  

When   has a very large negative value,   is always positive.

When   has a very large positive value,   is always negative.


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

Sum of roots 0 edit

 
Graph of cubic function with coefficient b missing.
Sum of roots is  
 axis compressed for clarity.

When sum of roots is   coefficient  


In the diagram, roots of   are  

Sum of roots  

Therefore coefficient  

Ratio of stationary points to roots edit

 
Graph of cubic function with 2 stationary points.
Ratio of   to  
Ratio of   to  

Stationary points relative to roots:


Consider cubic function:  

Roots of function are:  

Derivative of function:  

Stationary points of function are roots of   or  

Ratio of   to    

Ratio of   to    

s = 2r edit

 
Graph of cubic function with 2 stationary points.
  are stationary points.
 
Therefore,  

Equation of red curve in diagram:   where  

Aim of this section is to calculate   so that  

Associated quadratic when  

 

 

 

  is a root of this function. Divide   by  

Quotient is  

Remainder is   which equals  

  Therefore:

 

  Therefore  

Function as product of 3 linear functions edit

The function may be expressed as:

  where   are roots of the function, in which case

  where:  

Solving the cubic equation means that, given  , at least one of   must be calculated.

Given  , I found that   can be calculated as:

 

This approach was not helpful.

Function as product of linear function and quadratic edit

When   is a root of the function, the function may be expressed as:

  where

 

When one real root   is known, the other two roots may be calculated as roots of the quadratic function  .

   

When   is a root of the function,   or  

Therefore the expansion of      

Generally, if point   is any point on the curve and it is desired to calculate the other values of   that produce   then:

  or   and

     

When     and  

Let  

where  

If point   is any point on the curve of   then the solution of   provides the other values of   that produce  

 
Graph of cubic function and associated quadratic function.
All values of   that produce  

An example:

Let  

It is known that point   satisfies  

Let associated quadratic function  

Roots of   show that when   or  

General case edit

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:  


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)
allEqual()6: 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:  

Function defined by 4 points edit

 
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:

 

Rearrange the standard cubic function to prepare for the calculation of  

 

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  

Cubic function defined by the 4 points   is  

Function defined by 3 points and 1 slope edit

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:

 

It is known that the slope at point   is  

Rearrange the standard cubic function to prepare for the calculation of  

 

Equation of slope:  

Rearrange the equation of slope to prepare for the calculation of  

 

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   (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   is the independent variable, result is:

     

Both curves satisfy the points   and have the same slope at point  

(In fact  )

The simplest cubic function edit

 
Figure 1.

The simplest cubic function has coefficients  

The simplest cubic function has coefficients  , for example:

 .

To solve the equation:

 

 

 

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

  

     


Curve   is useful for finding the cube root of a real number.


Solve:  

 

 

This is equivalent to finding a root of function  


If you use Newton's method to solve   it may be advantageous to put   in form   where  

Then   Remember to preserve correct sign of result.

Roots of equal absolute value edit

The cubic function  

Let one value of   be   and another be  .

Substitute these values into the original function in   and expand.

 

 

 

 

Reduce   and   and substitute   for  :

 

 

Combine   and   to eliminate   and produce a function in  :

 

From  

If   is a solution and function   becomes:

 

 

  and two roots of   are  .

An example edit

 
Figure 2.

The roots of equal absolute value are  

See Figure 2.


 

 

The function has roots of equal absolute value.

 

The roots of equal absolute value are  .

This method works with complex roots of equal absolute value.


Consider function:  

 

 

  has roots of equal absolute value.

 

 

Roots of equal absolute value are:  

Equal Roots edit

Combine   and   from above to eliminate   and produce a function in  :


         


From   above:    


If  , then   is a solution ,   and   become:

 

 

If   because  , there is a stationary point where  .

Note:

  •   is a factor of discriminant of cubic formula below. If   because the discriminant is  , function   contains at least 2 roots equal to   when both functions   are  .
  •   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.

  and   can be combined to produce:

 

 


  and   can be combined to produce:

 

 


If the original function   contains 3 unique roots, then   are numerically different.


If the original function   contains exactly 2 equal roots, then   are numerically identical, and the 2 roots have the value   in  .


If the original function   contains 3 equal roots, then   are both null,   are numerically identical and  .


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

     

Examples edit

No equal roots edit

 
Figure 3a.

Cubic function with 3 unique, real roots at  .

Consider function  

from  

from  

  are numerically different.

Exactly 2 equal roots edit

 
Figure 3b.

Cubic function with 2 equal, real roots at  .

Consider function  

from  

from  

There are 2 equal roots at  

See Function_as_product_of_linear_function_and_quadratic above.

To calculate all roots:

# python code.
a,b,c,d = 1,-3,-9,-5

# Associated quadratic:
p = -1
A = a
B = A*p + b
C = B*p + c

# Associated linear function:
a1 = A
b1 = a1*p + B

print ('x3 =', -b1/a1)
x3 = 5.0

Roots of cubic function   are  

3 equal roots edit

 
Figure 3c.

Cubic function with 3 equal, real roots at  .

Consider function  

from  

from  

from  

  are numerically identical, the discriminant of each is   and  

Depressed cubic edit

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

In the cubic function:   let  , substitute for   and expand:

 

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

  where

  and

 

In the depressed equation the coefficient of   is   and the coefficient of   is  .

 

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

Let  

Then point of inflection has coordinates   and  

When  

If coefficient   is missing, the cubic function becomes   and

  • point of inflection has coordinates   and
  • slope at point of inflection  

Be prepared for the possibility that one or both of   may be zero.

6 examples edit

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

When A = 0 edit

 
Figure 4a.

Cubic function with slope 0 at point of inflection  .

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

 

 

 

 

The other roots may be derived from the associated quadratic:

  

       

When B = 0 edit

 
Figure 4b.

Cubic function with point of inflection   on   axis.

This condition occurs when the cubic function in   is of format   or when point of inflection is on the   axis.

 

 

 

 

 

When A = B = 0 edit

 
Figure 4c (same as 3c above).

Cubic function with:
* point of inflection   on   axis,
* slope   at point of inflection.

This condition occurs when:

  • slope at point of inflection is  , and
  • point of inflection is on   axis.


Consider function  

     

 

Vieta's substitution edit

See Vieta's Substitution.

Let the depressed cubic be written as:   where   and  

Let  

Substitute for   in the depressed function:

 

  where   and  .

From the quadratic formula:  

The discriminant  . Substitute for   and expand:

This discriminant =  

The factor   is a factor of   under "Equal Roots" above.

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

 
Figure 5a.

Cubic function with 2 equal, real roots at  .

If discriminant  , the function contains at least 2 equal, real roots.

Consider function   

 

 

 

 

Associated quadratic    

The 2 equal roots are:  .


Discriminant (B² - 4C³) positive edit

 
Figure 5b.

Cubic function with discriminant   positive
and 1 real root at  .

If discriminant   is positive, the function contains exactly 1 real root.

Consider function  

discriminant  

 

 

 

 

or:

 

 

 


 

The associated quadratic is:  

and the two complex roots are:      

Discriminant (B² - 4C³) negative edit

If discriminant   is negative, the function contains 3 real roots and   becomes the complex number  .


Let   be the modulus of  .

Let   be the real part of  .

Let   be the imaginary part of  .

Then  

 

 

 

Let   be the phase of  .

Then   and  .

 . Therefore:

 

 

 

 

An example edit

 
Figure 5c.

Cubic function with 3 unique, real roots at  .

  in which  

 

 

 

 

 

  radians.

  radians.

 

 

 

 

 

Using Cosine (A/3) edit

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 edit

 
Figure 6a: Components of complex number Z.

Origin at point  .
  parallel to   axis.
  parallel to   axis.
  = modulus of   
Angle   is the phase of    


 
Figure 6b: Complex numbers   and  .

Origin at point  .
  (off image to left.)
 
 
 

A complex number contains a real part and an imaginary part, eg:  

In theoretical math the value   is usually written as  . In the field of electrical engineering and computer language Python it is usually written as  .


The value   is a complex number expressed in rectangular format.

The value   is a complex number expressed in polar format where   is the modulus of   or   and   is the phase of   or  

     

Multiplication of complex numbers edit

       

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

Complex number cubed edit

             


Generally    

For the cube of a complex number in polar format,  

Cube root of complex number W edit

Let   and  

If   then:

  and

 

Complex number w + C/w edit

Let   where  

 

If  

 

In the case of 3 real roots,  

Cubic formula edit

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

Given cubic equation:   calculate the 3 values of  

  where:

Coefficients of depressed cubic:

 

 

One root of cubic function:

 

 

 

 

 

 

Formula incorporating all eight statements above is:

 

Cube roots of unity are:   See "Cube roots of 1."


Therefore   has 3 values:

 

 

 

It is not necessary to use both values of  

Choose either   or  

If   contains 3 equal roots,   and line t = w + C/w fails with divisor  

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

Using cubic formula edit

2 equal roots edit

 
Graph of cubic function with 2 equal roots at  
Y axis compressed for clarity.

Calculate roots of  

# python code
a,b,c,d = 1, -7, -5, 75
A = 9*a*c - 3*b*b
B = 27*a*a*d - 9*a*b*c + 2*b*b*b
C = -A/3
Δ = B*B - 4*C*C*C
print ('Δ =', Δ)
W = -B/2
# The following 2 lines ensure that cube root of negative
# real number is real number.
if W < 0 : w_ = -((-W)**(1/3))
else : w_ = W**(1/3)
r3 = 3**(0.5)
values_of_w = (w_, 
               w_*(-1 + 1j*r3)/2, 
               w_*(-1 - 1j*r3)/2)
for w in values_of_w :
    print ()
    print ('w =', w)
    t = w + C/w
    print ('t =', t)
    x = (-b + t)/(3*a)
    print ('x =', x)
Δ = 0.0

w = -8
t = -16
x = -3

w = (4-6.928203230275509j)
t = 8
x = 5

w = (4+6.928203230275508j)
t = 8
x = 5

Notice that:

  •   is zero.
  •  
  •  

1 real root edit

 
Graph of cubic function with 1 real root at  
Y axis compressed for clarity.

Calculate roots of  

# python code
a,b,c,d = 1, -7, -1, 87
A = 9*a*c - 3*b*b
B = 27*a*a*d - 9*a*b*c + 2*b*b*b
C = -A/3
Δ = B*B - 4*C*C*C
print ('Δ =', Δ)
δ = (Δ)**.5
W = (-B+δ)/2
if W < 0 : w_ = -((-W)**(1/3))
else : w_ = W**(1/3)
r3 = 3**(0.5)
values_of_w = (w_, 
               w_*(-1 + 1j*r3)/2, 
               w_*(-1 - 1j*r3)/2)
for w in values_of_w :
    print ()
    print ('w =', w)
    t = w + C/w
    print ('t =', t)
    x = (-b + t)/(3*a)
    print ('x =', x)
Δ = 1997568.0

w = -4.535898384862245
t = -16
x = -3

w = (2.2679491924311215-3.9282032302755088j)
t = (8.0+6.0j)
x = (5.0+2.0j)

w = (2.267949192431123+3.9282032302755083j)
t = (8.0-6.0j)
x = (5.0-2.0j)

Notice that:

  •   is positive.
  •  
  •   does not equal  

3 real roots edit

 
Graph of cubic function with 3 real roots,  
Y axis compressed for clarity.

Calculate roots of  

# python code
a,b,c,d = 5, -62, 11, 726
A = 9*a*c - 3*b*b
B = 27*a*a*d - 9*a*b*c + 2*b*b*b
C = -A/3
Δ = B*B - 4*C*C*C
print ('Δ =', Δ)
δ = (Δ)**.5
W = (-B-δ)/2
w_ = W**(1/3)
r3 = 3**(0.5)
values_of_w = (w_, 
               w_*(-1 + 1j*r3)/2, 
               w_*(-1 - 1j*r3)/2)
for w in values_of_w :
    print ()
    print ('w =', w)
    t = w + C/w
    print ('t =', t)
    x = (-b + t)/(3*a)
    print ('x =', x)
Δ = -197238264300.0

w = (51.5-32.042939940024226j)
t = 103
x = 11

w = (2.0+60.62177826491069j)
t = 4.0
x = 4.4

w = (-53.5-28.578838324886462j)
t = -107
x = -3

Notice that:

  •   is negative
  •  
  •   equals  

cos (A/3) edit

The method above for calculating   depends upon calculating the value of angle  

However,   may be calculated from   because  

Generally, when   is known, there are 3 possible values of the third angle because  

This suggests that there is a cubic relationship between   and  

Expansion of cos (3A) edit

 
Figure 7a.

Graph of  

The well known identity for   is:

 

The derivation of this identity may help understanding and interpreting the curve of  

Let  

  and  

Therefore the point   is on the curve and  

A 3A cos A cos 3A
0 0 1 1
180 180*3 -l -1
60 180 0.5 -1

Three simultaneous equations may be created from the above table:

 

 

Therefore  

 

 

  and  

When   is known,  

Newton's Method edit

 
Figure 7b.

Newton's Method used to calculate   when  

Newton's method is a simple and fast root finding method that can be applied effectively to the calculation of   when   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   when   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 edit

 
Figure 7c.

Newton's Method used to calculate   when  

When   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   are required, the other 2 values can be calculated as roots of the associated quadratic function with coefficients  

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 edit

 
Figure 7d.

Newton's Method used to calculate   when  

When   is negative, the starting value of  

When   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 edit

 
Figure 7e.

Cubic function with 3 unique, real roots at  .

  in which  

 

 

 

 

 

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

$cosWphi = -0.338086344651354;

$cos3A = $cosWφ;

$x = -1; # starting point.

 

 

 

 

 

Point of Inflection edit

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

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

 

The slope at point of inflection is:

 

Value   at point of inflection is:

 

From basic principles edit

 
Figure 1. 4 points relative to point of inflection.

Relative to point of inflection  :
Points   have coordinates  .
Points   have coordinates  .
When 2 points are equidistant in terms of   they are also equidistant in terms of  

  may be calculated from basic principles.

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

Let   and let   be non-zero.

Then   where   is point of inflection.

Let   and  

Then  

 

Let   be   relative to  

Then  

Similarly  

  therefore:

   

 

 

 

 

 

Depressed cubic edit

Recall from "Depressed cubic" above:

 

 

Therefore:

 

 

Coefficients   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   is zero, the cubic equation may be solved as under "Depressed cubic" above.

Newton's Method edit

If both   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 edit

 
Figure 8a.

 
Cubic function with positive slope at Point of Inflection  

 

 

 

 

 

slope at PoI negative edit

PoI above X axis edit

 
Figure 8b.

 
Cubic function with negative slope at Point of Inflection  
and PoI above   axis.

 

 

 

 

 

When   the other 2 intercepts may be calculated as roots of the associated quadratic with coefficients:

     

 

($a,$b,$c,$d) = (0.1,0.9,0.2,-2.8);
($x,$y) = ($x1a,$ypoi);

while(abs($y) > 1e-14){
    $s = 3*$a*$x*$x + 2*$b*$x + $c;
    $delta_x = $y/$s;
    $x -= $delta_x ;
    $y = $a*$x*$x*$x + $b*$x*$x + $c*$x + $d;
    print "
x=$x,y=$y
";
}

print "
x=$x
";
x=-8.4,y=-0.246400000000004

x=-8.36056338028169,y=-0.00251336673084257

x=-8.36015274586958,y=-2.7116352896428e-07

x=-8.36015270155726,y=-8.88178419700125e-16

x=-8.36015270155726
 
Graphs of 3 different cubic functions all solved with the same technique.

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

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

PoI below X axis edit

 
Figure 8c.

 
Cubic function with negative slope at Point of Inflection  
and PoI below   axis.

 

 

 

 

 

When   the other 2 intercepts may be calculated as roots of the associated quadratic with coefficients:

   

 

 
Graphs of 3 different cubic functions all solved with the same technique.

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

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

Using Newton's method edit

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  


The method above uses Newton's method to calculate   from   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   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 TwoRootsOfCubic() see General_case above.

Calculate roots of cubic function:  

# python code

a,b,c,d = abcd = 2, -33, -6164, -65760

# Coefficients of depressed cubic:
A = 9*a*c - 3*b*b
B = 27*a*a*d - 9*a*b*c + 2*b*b*b

# The point of inflection:
ypoi = B/(27*a*a)
xpoi = -b/(3*a)
spoi = A/(9*a)
print ('xpoi =',xpoi)
print ('ypoi =',ypoi)
print ('spoi =',spoi)
xpoi = 5.5
ypoi = -100327.5
spoi = -6345.5

  is negative.   will not be used as starting point.

 
Figure 1: Diagram illustrating relationship between   and  
Roots of   are 2 possible starting points.
Because   is below   axis,   is chosen.

The associated quadratic when  

Find 2 possible starting points   to left and right of  

TwoRootsOfCubicDebug = 1

x11,x12 = TwoRootsOfCubic((a,b,c,d), xpoi)
print ('x11,x12 =',x11,x12)
TwoRootsOfCubic ():
    y = ( 2 )xx + ( -22.0 )x + ( -6285.0 )
    for x1 = 5.5 , sum1 = -100327.5
    for x2 = -50.82716928800878 , sum2 = -100327.5
    for x3 = 61.82716928800878 , sum3 = -100327.50000000006
    
x11,x12 = -50.82716928800878 61.82716928800878

Execute newton's method:

if ypoi > 0 : start = x11
else : start = x12

# The differential function
_a = 3*a
_b = 2*b
_c = c

x = start
y = ypoi
while abs(y) > 1e-24 :
    print ('x,y =',x,y)
    s = _a*x*x + _b*x + _c
    deltax = y/s
    x -= deltax
    y = a*x*x*x + b*x*x + c*x + d
x1 = x
print ('x1 =',x1)
x,y = 61.82716928800878 -100327.5
x,y = 69.7325746934142 22109.249048075755
x,y = 68.53160134747581 552.4056893695961
x,y = 68.50002158732813 0.3770984176080674
x,y = 68.50000000001009 1.762527972459793e-07

x1 = 68.5

The starting point   start  is close to   which was found quickly.

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

 
Figure 2: Diagram illustrating relationship between   and  
Roots of   are 2 roots of  

The associated quadratic when  

x2,x3 = TwoRootsOfCubic(abcd, x1)

print ('3 roots:', x1,x2,x3)
TwoRootsOfCubic ():
    y = ( 2 )xx + ( 104.0 )x + ( 960.0 )
    for x1 = 68.5 , sum1 = 0.0
    for x2 = -40.0 , sum2 = 0.0
    for x3 = -12.0 , sum3 = 0.0
    
3 roots: 68.5 -40.0 -12.0

In practice edit

Much interesting theory concerning complex numbers and Vieta's substitution has been presented above. The formula for   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, oneRootOfCubic (), 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.

# Python code
newtonDebug = 0

def newton (abcd, startx) :
    '''
x = newton (abcd, startx)
Values a,b,c,d,startx may be Decimal or non-Decimal, but not a mixture of both.
x is float or None.
Newton's method for finding 1 root of cubic function.
2 global variables are needed: newtonDebug
                               almostZero (same as relative tolerance)
'''

    if newtonDebug : print ('newton() 1: a,b,c,d =',abcd)
    a,b,c,d = abcd
    x = startx ; xx = x*x
    y = a*xx*x + b*xx +  c*x + d
    if newtonDebug : print ('newton() 2: x,y =', x,y)

# The differential function
# slope = 3*a*x*x + 2*b*x + c
    _a = 3*a
    _b = 2*b
    _c = c

    count = 0 ; L1 = []
    while 1 :
        count += 1
        if count >= 51 :
            print ('newton() 3: count expired.')
            return None
        slope = _a*xx + _b*x + _c
        delta_x = y/slope
        x -= delta_x
        xx = x*x
        t3,t2,t1 = a*xx*x, b*xx, c*x
        y = t3 + t2 + t1 + d
# Yes. This calculation of y is slightly faster than:
#        y = a*x*x*x + b*x*x + c*x + d
        if newtonDebug : print ('newton() 4: x,y =', x,y)
        if abs(y) <= almostZero : break
        max = sorted([ abs(v) for v in (t3,t2,t1,d) ])[-1]
        if abs(y)/max <= almostZero : break
        if x in L1[-1::-1] :
            if newtonDebug : print ('newton() 5: Endless loop detected.')
            return None
        L1 += [x]

    if newtonDebug : print ('newton() 6: count =', count)

    return x

# Python code
import decimal
D = decimal.Decimal

oneRootOfCubicDebug = 0

def oneRootOfCubic (abcd) :
    '''
x1 = oneRootOfCubic (abcd)
Each member of a,b,c,d must be int or float or Decimal.
If any member is Decimal, this function ensures that all are Decimal.
x1 may be None.
'''
    useDecimal = False
    for v in abcd :
        if isinstance (v,D) :
            useDecimal = True; continue
        if type(v) not in (int,float) :
            print ('oneRootOfCubic() 1: Each member of input (abcd) must be int, float or Decimal.')
            return None

    if useDecimal : a,b,c,d = [ D(str(v)) for v in abcd ]
    else : a,b,c,d = abcd

    if a == 0 :
        print ('oneRootOfCubic() 2: a must be non-zero.')
        return None

    if d == 0 : return 0

    if a != 1 :
        divider = a
        a,b,c,d = [ v/divider for v in (a,b,c,d) ] # a is now +1.

    if b == c == 0 :
        # This is effectively the calculation of cube root.
        if oneRootOfCubicDebug : print ('oneRootOfCubic() 3: Cube root of', -d)
        root3 = simpleCubeRoot(-d)
        if useDecimal : return D(str(root3))
        return float(root3)

    xpoi = -b/3 # Point of inflection.

    # Coefficient B of depressed cubic. B = 27*a*a*d - 9*a*b*c + 2*b*b*b
    B = 27*d - 9*b*c + 2*b*b*b
    if B == 0 :
        # Point of inflection is on X axis.
        if oneRootOfCubicDebug : print ('oneRootOfCubic() 4: Found B=0.')
        return xpoi

    A = 3*c - b*b # Coefficient A of depressed cubic. A = 9*a*c - 3*b*b
    if A == 0 :
        # Slope at Point of inflection is 0.
        if oneRootOfCubicDebug : print ('oneRootOfCubic() 5: Found A=0.')
        t = simpleCubeRoot (-B)
        if not useDecimal : t = float(t)
        x = (-b + t)/3
        return x

    if A > 0 :
        # Slope at Point of inflection is positive.
        return newton((a,b,c,d),xpoi)

    # Slope at Point of inflection is negative.
    x1,x2 = TwoRootsOfCubic ( [ float(v) for v in (a,b,c,d) ], float(xpoi) )
    if oneRootOfCubicDebug : print ('oneRootOfCubic() 6: x1,x2 =',x1,x2)
    if useDecimal : x1,x2 = [ D(str(v)) for v in (x1,x2) ]

    if B > 0 :
        # Point of inflection is above X axis.
        return newton((a,b,c,d),x1)

    # Point of inflection is below X axis.
    return newton((a,b,c,d),x2)

For function TwoRootsOfCubic () see General case above.

For function simpleCubeRoot (N), see Implementation.

Translation of axes edit

Cubic function relative to (u,v) edit

 
Graphs of 2 cubic functions with same shape.
Red curve relative to point   is same as blue curve relative to  

The familiar equation of the cubic function:   This is the equation of   relative to origin   However,   need not be constrained as always relative to origin. It is always possible, and sometimes desirable, to express   relative to any other point   in the two dimensional plane. The process of producing a new function   that is   relative to   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   (red curve) is   Relative to point   red curve is located at   Relative to   blue curve is located at   and equation of blue curve is   or  


Equation of   relative to   is:  


  •  


  where:

 

 

 

 

Move cubic function to (u,v) edit

 
Graphs of 2 cubic functions with same shape.
Red curve moved to   has equation  
Blue curve moved to   has equation  

When a cubic function is moved to point   the point of inflection is moved from present position   to   and the amount of movement is:

 

 


Equation of function after being moved is:

  or   where:

 

 

 

 

 

 

Describing a cubic function edit

 
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   This can be done by:

  • moving function to   or
  • calculating equation of function relative to point of inflection  

Consider function  

Point of inflection is  

Equation of   relative to point of inflection is:

  See red curve in diagram.

  may be described as   moved to point