The cubic function is the sum of powers of
x
{\displaystyle x}
from
0
{\displaystyle 0}
through
3
{\displaystyle 3}
:
y
=
f
(
x
)
=
a
x
3
+
b
x
2
+
c
x
1
+
d
x
0
{\displaystyle y=f(x)=ax^{3}+bx^{2}+cx^{1}+dx^{0}}
usually written as:
y
=
f
(
x
)
=
a
x
3
+
b
x
2
+
c
x
+
d
.
{\displaystyle y=f(x)=ax^{3}+bx^{2}+cx+d.}
If
d
==
0
{\displaystyle d==0}
the function becomes
x
(
a
x
2
+
b
x
+
c
)
.
{\displaystyle x(ax^{2}+bx+c).}
Within this page we'll say that:
both coefficients
a
,
d
{\displaystyle a,d}
must be non-zero,
coefficient
a
{\displaystyle 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:
a
x
3
+
b
x
2
+
c
x
+
d
=
0
{\displaystyle ax^{3}+bx^{2}+cx+d=0}
.
Roots of the function are values of
x
{\displaystyle 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
edit
Coefficient c missing
edit
The cubic function may be expressed as
x
=
a
y
3
+
b
y
2
+
c
y
+
d
.
{\displaystyle x=ay^{3}+by^{2}+cy+d.}
Unless otherwise noted, references to "cubic function" on this page refer to function of form
y
=
a
x
3
+
b
x
2
+
c
x
+
d
.
{\displaystyle y=ax^{3}+bx^{2}+cx+d.}
Coefficient a negative
edit
Ratio of stationary points to roots
edit
Graph of cubic function with 2 stationary points.
(
q
,
f
(
q
)
)
,
(
r
,
f
(
r
)
)
{\displaystyle (q,f(q)),(r,f(r))}
are stationary points.
f
(
s
)
=
f
(
q
)
.
{\displaystyle f(s)=f(q).}
Therefore,
s
=
2
r
.
{\displaystyle s=2r.}
Equation of red curve in diagram:
y
=
f
(
x
)
=
a
x
3
−
c
x
,
{\displaystyle y=f(x)=ax^{3}-cx,}
where
a
,
b
,
c
=
a
,
0
,
−
c
{\displaystyle a,b,c=a,0,-c}
Aim of this section is to calculate
s
{\displaystyle s}
so that
f
(
s
)
=
f
(
q
)
.
{\displaystyle f(s)=f(q).}
Associated quadratic when
x
=
q
:
{\displaystyle x=q:}
A
=
a
{\displaystyle A=a}
B
=
A
q
+
b
{\displaystyle B=Aq+b}
C
=
B
q
+
c
{\displaystyle C=Bq+c}
q
{\displaystyle q}
is a root of this function. Divide
A
x
2
+
B
x
+
C
{\displaystyle Ax^{2}+Bx+C}
by
x
−
q
.
{\displaystyle x-q.}
Quotient is
A
x
+
A
q
+
B
.
{\displaystyle Ax+Aq+B.}
Remainder is
A
q
2
+
B
q
+
C
{\displaystyle Aq^{2}+Bq+C}
which equals
0.
{\displaystyle 0.}
A
x
+
A
q
+
B
=
0.
{\displaystyle Ax+Aq+B=0.}
Therefore:
s
=
−
A
q
−
B
A
=
−
A
q
−
A
q
A
=
−
2
q
.
{\displaystyle s={\frac {-Aq-B}{A}}={\frac {-Aq-Aq}{A}}=-2q.}
r
=
−
q
.
{\displaystyle r=-q.}
Therefore
s
=
−
2
(
−
r
)
=
2
r
.
{\displaystyle s=-2(-r)=2r.}
Function as product of 3 linear functions
edit
The function may be expressed as:
y
=
(
x
−
p
)
(
x
−
q
)
(
x
−
r
)
{\displaystyle y=(x-p)(x-q)(x-r)}
where
p
,
q
,
r
{\displaystyle p,q,r}
are roots of the function, in which case
y
=
x
3
−
(
p
+
q
+
r
)
x
2
+
(
p
q
+
q
r
+
r
p
)
x
−
p
q
r
{\displaystyle y=x^{3}-(p+q+r)x^{2}+(pq+qr+rp)x-pqr}
where:
a
=
1
;
b
=
−
(
p
+
q
+
r
)
;
c
=
p
q
+
q
r
+
r
p
;
d
=
−
p
q
r
{\displaystyle a=1;\ b=-(p+q+r);\ c=pq+qr+rp;\ d=-pqr}
Solving the cubic equation means that, given
a
,
b
,
c
,
d
{\displaystyle a,b,c,d}
, at least one of
p
,
q
,
r
{\displaystyle p,q,r}
must be calculated.
Given
b
,
c
,
d
{\displaystyle b,c,d}
, I found that
r
{\displaystyle r}
can be calculated as:
r
8
+
2
b
r
7
+
(
b
b
+
3
c
)
r
6
+
(
4
b
c
+
2
d
)
r
5
+
(
b
b
c
+
2
b
d
+
3
c
c
)
r
4
+
(
2
b
c
c
+
4
c
d
)
r
3
+
(
2
b
c
d
+
c
3
+
d
d
)
r
2
+
2
c
c
d
r
+
c
d
d
=
0
{\displaystyle 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
edit
When
p
{\displaystyle p}
is a root of the function, the function may be expressed as:
(
x
−
p
)
(
A
x
2
+
B
x
+
C
)
{\displaystyle (x-p)(Ax^{2}+Bx+C)}
where
A
=
a
;
B
=
A
p
+
b
;
C
=
B
p
+
c
.
{\displaystyle A=a;\ B=Ap+b;\ C=Bp+c.}
When one real root
p
{\displaystyle p}
is known, the other two roots may be calculated as roots
of the quadratic function
A
x
2
+
B
x
+
C
{\displaystyle Ax^{2}+Bx+C}
.
f
(
x
)
=
(
x
−
p
)
(
a
x
2
+
B
x
+
C
)
{\displaystyle f(x)=(x-p)(ax^{2}+Bx+C)}
=
a
x
3
+
b
x
2
+
c
x
−
(
a
p
3
+
b
p
2
+
c
p
)
.
{\displaystyle =ax^{3}+bx^{2}+cx-(ap^{3}+bp^{2}+cp).}
When
p
{\displaystyle p}
is a root of the function,
a
p
3
+
b
p
2
+
c
p
+
d
=
0
{\displaystyle ap^{3}+bp^{2}+cp+d=0}
or
a
p
3
+
b
p
2
+
c
p
=
−
d
.
{\displaystyle ap^{3}+bp^{2}+cp=-d.}
Therefore the expansion of
(
x
−
p
)
(
a
x
2
+
B
x
+
C
)
{\displaystyle (x-p)(ax^{2}+Bx+C)}
=
a
x
3
+
b
x
2
+
c
x
−
(
−
d
)
{\displaystyle =ax^{3}+bx^{2}+cx-(-d)}
=
a
x
3
+
b
x
2
+
c
x
+
d
.
{\displaystyle =ax^{3}+bx^{2}+cx+d.}
Generally, if point
(
p
,
q
)
{\displaystyle (p,q)}
is any point on the curve and it is desired to calculate the other values of
x
{\displaystyle x}
that produce
y
=
q
,
{\displaystyle y=q,}
then:
a
p
3
+
b
p
2
+
c
p
+
d
=
q
{\displaystyle ap^{3}+bp^{2}+cp+d=q}
or
a
p
3
+
b
p
2
+
c
p
=
q
−
d
{\displaystyle ap^{3}+bp^{2}+cp=q-d}
and
f
(
x
)
=
a
x
3
+
b
x
2
+
c
x
−
(
a
p
3
+
b
p
2
+
c
p
)
{\displaystyle f(x)=ax^{3}+bx^{2}+cx-(ap^{3}+bp^{2}+cp)}
=
a
x
3
+
b
x
2
+
c
x
−
(
q
−
d
)
{\displaystyle =ax^{3}+bx^{2}+cx-(q-d)}
=
a
x
3
+
b
x
2
+
c
x
+
d
−
q
.
{\displaystyle =ax^{3}+bx^{2}+cx+d-q.}
When
f
(
x
)
=
0
,
{\displaystyle f(x)=0,}
a
x
3
+
b
x
2
+
c
x
+
d
−
q
=
0
{\displaystyle ax^{3}+bx^{2}+cx+d-q=0}
and
a
x
3
+
b
x
2
+
c
x
+
d
=
q
.
{\displaystyle ax^{3}+bx^{2}+cx+d=q.}
Let
a
x
2
+
B
x
+
C
=
0
…
(
1
)
{\displaystyle ax^{2}+Bx+C=0\dots \ (1)}
where
B
=
a
p
+
b
;
C
=
B
p
+
c
.
{\displaystyle B=ap+b;C=Bp+c.}
If point
(
p
,
q
)
{\displaystyle (p,q)}
is any point on the curve of
y
=
a
x
3
+
b
x
2
+
c
x
+
d
,
{\displaystyle y=ax^{3}+bx^{2}+cx+d,}
then the solution of
(
1
)
{\displaystyle (1)}
provides the other values of
x
{\displaystyle x}
that produce
y
=
q
.
{\displaystyle y=q.}
Graph of cubic function and associated quadratic function. All values of
x
{\displaystyle x}
that produce
f
(
x
)
=
2.
{\displaystyle f(x)=2.}
An example:
Let
f
(
x
)
=
3
x
3
−
6
x
2
−
3
x
+
22
8
{\displaystyle f(x)={\frac {3x^{3}-6x^{2}-3x+22}{8}}}
It is known that point
(
1
,
2
)
{\displaystyle (1,2)}
satisfies
y
=
f
(
x
)
.
{\displaystyle y=f(x).}
Let associated quadratic function
=
g
(
x
)
=
3
x
2
−
3
x
−
6
8
.
{\displaystyle =g(x)={\frac {3x^{2}-3x-6}{8}}.}
Roots of
g
(
x
)
,
−
1
,
2
,
{\displaystyle g(x),\ -1,2,}
show that when
x
=
−
1
{\displaystyle x=-1}
or
x
=
2
,
f
(
x
)
=
2.
{\displaystyle x=2,f(x)=2.}
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 ) * 1 j
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 ) )
The method works with complex values:
# python code.
TwoRootsOfCubicDebug = 1
print ( TwoRootsOfCubic (( 1 , 0 , 0 , 27 ), - 3 ) )
print ( TwoRootsOfCubic (( 1 , 9 , 31 , 39 ), - 3 + 2 j ) )
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
+
2
j
,
9
+
6
j
.
{\displaystyle B,C=6+2j,9+6j.}
Reporting an error:
print ( TwoRootsOfCubic (( 3 , - 6 , - 3 , 22 ), - 4 + 3 j ))
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:
B
,
C
=
−
18
+
9
j
,
42
−
90
j
.
{\displaystyle B,C=-18+9j,42-90j.}
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:
(
−
4
,
2
)
,
(
−
3
,
3
)
,
(
2
,
3
)
,
(
8
,
8
)
{\displaystyle (-4,2),(-3,3),(2,3),(8,8)}
Rearrange the standard cubic function to prepare for the calculation of
a
,
b
,
c
,
d
:
{\displaystyle a,b,c,d:}
x
3
a
+
x
2
b
+
x
c
+
1
d
−
y
=
0.
{\displaystyle 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
5
66
,
−
30
66
,
−
65
66
,
408
66
.
{\displaystyle {\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
)
{\displaystyle (-4,2),(-3,3),(2,3),(8,8)}
is
y
=
5
x
3
−
30
x
2
−
65
x
+
408
66
.
{\displaystyle y={\frac {5x^{3}-30x^{2}-65x+408}{66}}.}
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:
(
−
4
,
2
)
,
(
2
,
3
)
,
(
8
,
8
)
{\displaystyle (-4,2),(2,3),(8,8)}
It is known that the slope at point
(
8
,
8
)
{\displaystyle (8,8)}
is
6
+
19
66
.
{\displaystyle 6+{\frac {19}{66}}.}
Rearrange the standard cubic function to prepare for the calculation of
a
,
b
,
c
,
d
:
{\displaystyle a,b,c,d:}
x
3
a
+
x
2
b
+
x
c
+
1
d
−
y
=
0.
{\displaystyle x^{3}a+x^{2}b+xc+1d-y=0.}
Equation of slope:
s
=
3
a
x
2
+
2
b
x
+
c
{\displaystyle s=3ax^{2}+2bx+c}
Rearrange the equation of slope to prepare for the calculation of
a
,
b
,
c
,
d
:
{\displaystyle a,b,c,d:}
3
x
2
a
+
2
x
b
+
1
c
+
0
d
−
s
=
0.
{\displaystyle 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
5
66
,
−
30
66
,
−
65
66
,
408
66
{\displaystyle {\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
{\displaystyle y}
is the independent variable, result is:
x
=
−
0.020819277108433898
y
3
{\displaystyle x=-0.020819277108433898y^{3}}
+
0.1873734939759051
y
2
{\displaystyle +0.1873734939759051y^{2}}
+
1.1583614457831322
y
{\displaystyle +1.1583614457831322y}
−
2.599325301204827.
{\displaystyle -2.599325301204827.}
Both curves satisfy the points
(
−
4
,
−
3
)
,
(
2
,
3
)
,
(
8
,
8
)
{\displaystyle (-4,-3),(2,3),(8,8)}
and have the same slope at point
(
8
,
8
)
.
{\displaystyle (8,8).}
(In fact
f
(
y
)
=
−
1.728
y
3
+
15.552
y
2
+
96.144
y
−
215.744
83
.
{\displaystyle f(y)={\frac {-1.728y^{3}+15.552y^{2}+96.144y-215.744}{83}}.}
)