Solving Cubic Equations
If you thought the Quadratic Formula was complicated, the
method for solving Cubic Equations is even more complex. We
will use the example from the Cubic Equation Calculator:
2x3 - 4x2 - 22x + 24 = 0
Cubic equations have to be solved in several steps. First we
define a variable 'f':
f = (3c/a) - (b²/a²)
3
"Plugging in" the numbers from the above equation, we get:
f = ((3 • -22/2) - (16/4)) / 3 = - 12.333333...
Next we define 'g':
g = (2b³/a³) - (9bc/a²) + (27d/a)
27
From this point on, you are expected to "plug in" the numbers:
g = 4.07407407407407....
Then we define 'h':
h = (g²/4) + (f³/27)
h = -65.333333...
If h > 0, there is only 1 real root
and is solved by another method.
(SCROLL down for this method)
For the special case where f=0,
g=0 and h = 0, all 3 roots are real
and equal.
(SCROLL to the bottom for this
method)
When h <= 0, as is the case here,
all 3 roots are real and we
proceed as follows:
ALL 3 Roots Are Real
i = ((g²/4) - h)½
i = 8.33563754151978...
⅓
j = (i)
j = 2.0275875100994063...
NOTE: The following trigonometric calculations are in radians
k = arc cosine (- (g / 2i))
k = 1.817673356517739...
L = j • -1
L = -2.0275875100994...
M = cosine (k/3)
M = 0.8219949365268...
N = (Square Root of 3) • sine (k/3)
N = 0.9863939238321...
P = (b/3a) • -1
P = 0.6666666666666...
x1 = 2j • cosine(k/3) -(b/3a)
x1 = 4
x2 = L • (M + N) + P
x2 = -3
x3 = L • (M - N) + P
x3 = 1
When Only 1 Root Is Real
3x3 - 10x2 + 14x + 27 = 0
f = (3c/a) - (b²/a²)
3
f = .962962962962962...
g = (2b³/a³) - (9bc/a²) + (27d/a)
27
g = 11.441700960219478...
h = (g²/4) + (f³/27)
h = 32.761202560585275...
R = -(g/2) + (h)½
R = .002889779596782...
⅓
S = (R)
S = .142436591824886...
T = -(g/2) - (h)½
T = -11.4445907398163...
⅓
U = (T)
U = -2.25354770293599...
X1 = (S + U) - (b/3a)
X1 = -1
X2 = -(S + U)/2 - (b/3a) + i•(S-U)•(3)½/2
X2 = 2.16666666666... + i•2.07498326633146
X3 = -(S + U)/2 - (b/3a) - i•(S-U)•(3)½/2
X3 = 2.16666666666... - i•2.07498326633146
When All 3 Roots Are Real and
Equal
x3 + 6x2 + 12x + 8 = 0
f = (3c/a) - (b²/a²)
3
f = ((3•12/1)-(36/1)) / 3
f= 0
g = (2b³/a³) - (9bc/a²) + (27d/a)
27
g = ((2•216/1) - (9•6•12/1) + (27•8/1)) / 27
g = (432 - 648 + 216) / 27
g=0
h = (g²/4) + (f³/27)
h=0
x1 = x2 = x3= (d/a)1/3 • -1
x1 = x2 = x3= (8/1)1/3 • -1
x1 = x2 = x3= -2
• The program below perfectly solves the Cubic Equation
of the form Ax^3 + Bx^2 + Cx + D.
• The flawless code is written in .Net C#.
• The real and imaginary roots are separated by black
and red colors respectively.
• Simply update the value of variables A, B, C and D to
see the answers i.e. the solution of the equation.
• To find the 2 roots, solution of a Quadratic equation
please visit here.
• This code is written by Code-Kings exclusively for
YOU! Please like us wherever possible and show some love
in return!
namespace WindowsFormsApplication1
public partial class Form1 : Form
public Form1()
InitializeComponent();
private void CubicCalculations()
try
double a = [Link]([Link]);
double b = [Link]([Link]);
double c = [Link]([Link]);
double d = [Link]([Link]);
double f = (((3 * c) / a) - ((b * b) / (a * a))) / 3;
string f2 = [Link]();
double g = (((2 * ([Link](b, 3))) / ([Link](a, 3))) -
((9 * b * c) / ([Link](a, 2))) + ((27 * d) / a)) / 27;
string g2 = [Link]();
double h = (([Link](g, 2)) / 4) + (([Link](f, 3)) /
27);
string h2 = [Link]();
if (h <= 0)
double i = ((([Link](g, 2)) / 4) - h);
double i2 = [Link](i, 0.5);
string i3 = [Link]();
double j = ([Link](i2,
0.333333333333333333333333));
string j2 = [Link]();
double k = (([Link](0 - (g / (2 * i2)))));
string k2 = [Link]();
double l = (j * (0 - 1));
string l2 = [Link]();
double m = (([Link](k / 3)));
string m2 = [Link]();
double n = (([Link](3, 0.5)) * [Link](k / 3));
string n2 = [Link]();
double p = ((b / (3 * a)) * (0 - 1));
string p2 = [Link]();
double x = ((2 * j) * ([Link](k / 3)) - (b / (3 *
a)));
string x2 = [Link]();
[Link] = x2;
double y = (l * (m + n) + p);
string y2 = [Link]();
[Link] = y2;
double z = (l * (m - n) + p);
string z2 = [Link]();
[Link] = z2;
if (h > 0)
{
double u = 0 - g;
double r = (u / 2) + ([Link](h, 0.5));
string r2 = [Link]();
if (r >= 0)
double s6 = ([Link](r,
0.333333333333333333333333333));
double s8 = s6;
string s9 = [Link]();
double t8 = (u / 2) - ([Link](h, 0.5));
string t9 = [Link]();
double help8 = (1.0 / 3);
string help9 = [Link]();
if (t8 < 0)
double v7 = ([Link]((0 - t8),
0.33333333333333333333));
double v8 = (v7);
string v9 = [Link]();
double x3 = (s8 - v8) - (b / (3 * a));
string x4 = [Link]();
[Link] = x4;
double y3 = ((0 - (s8 - v8)) / 2) - (b / (3 *
a));
double y4 = ((s8 + v8) * ([Link](3) / 2));
string y6 = [Link]();
string y7 = [Link]();
[Link] = y6 + " + " + y7 + "i";
double z3 = ((0 - (s8 - v8)) / 2) - (b / (3 *
a));
double z4 = ((s8 + v8) * ([Link](3)) / 2);
string z6 = [Link]();
string z7 = [Link]();
[Link] = z6 + " - " + z7 + "i";
if (t8 >= 0)
double v6 = ([Link]((0 - (0 - t8)),
0.33333333333333333333));
double v5 = (v6);
string v4 = [Link]();
double x3 = (s8 + v5) - (b / (3 * a));
string x4 = [Link]();
[Link] = x4;
double y3 = ((0 - (s8 + v5)) / 2) - (b / (3 *
a));
double y4 = ((s8 - v5) * ([Link](3) / 2));
string y6 = [Link]();
string y7 = [Link]();
[Link] = y6 + " + " + y7 + "i";
double z3 = ((0 - (s8 + v5)) / 2) - (b / (3 *
a));
double z4 = ((s8 - v5) * ([Link](3)) / 2);
string z6 = [Link]();
string z7 = [Link]();
[Link] = z6 + " - " + z7 + "i";
if (r < 0)
double s3 = ([Link]((0 - r),
0.333333333333333333333333333));
double s = (0 - s3);
string s2 = [Link]();
double t = (u / 2) - ([Link](h, 0.5));
string t2 = [Link]();
double help = (1.0 / 3);
string help2 = [Link]();
if (t < 0)
{
double v = ([Link]((0 - t),
0.33333333333333333333));
double v2 = (v);
string v3 = [Link]();
double x3 = (s - v2) - (b / (3 * a));
string x4 = [Link]();
[Link] = x4;
double y3 = ((0 - (s - v2)) / 2) - (b / (3 *
a));
double y4 = ((s + v2) * ([Link](3) / 2));
string y6 = [Link]();
string y7 = [Link]();
[Link] = y6 + " + " + y7 + "i";
double z3 = ((0 - (s - v2)) / 2) - (b / (3 *
a));
double z4 = ((s + v2) * ([Link](3)) / 2);
string z6 = [Link]();
string z7 = [Link]();
[Link] = z6 + " - " + z7 + "i";
if (t >= 0)
double v = ([Link]((0 - (0 - t)),
0.33333333333333333333));
double v2 = (v);
string v3 = [Link]();
double x3 = (s + v2) - (b / (3 * a));
string x4 = [Link]();
[Link] = x4;
double y3 = ((0 - (s + v2)) / 2) - (b / (3 *
a));
double y4 = ((s - v2) * ([Link](3) / 2));
string y6 = [Link]();
string y7 = [Link]();
[Link] = y6 + " + " + y7 + "i";
double z3 = ((0 - (s + v2)) / 2) - (b / (3 *
a));
double z4 = ((s - v2) * ([Link](3)) / 2);
string z6 = [Link]();
string z7 = [Link]();
[Link] = z6 + " - " + z7 + "i";
if (h == 0 && f == 0 && g == 0)
{
double x5 = (([Link]((d / a),
0.3333333333333333333))) * (0 - 1);
string x6 = [Link]();
[Link] = x6;
[Link] = x6;
[Link] = x6;
catch { }
private void TCubA_TextChanged(object sender, EventArgs e)
CubicCalculations();
private void TCubB_TextChanged(object sender, EventArgs e)
CubicCalculations();
private void TCubC_TextChanged(object sender, EventArgs e)
CubicCalculations();
private void TCubD_TextChanged(object sender, EventArgs e)
{
CubicCalculations();
private void TCubFR_TextChanged(object sender, EventArgs e)
if ([Link]("i"))
[Link] = [Link];
else
[Link] = [Link];
private void TCubSR_TextChanged(object sender, EventArgs e)
if ([Link]("i"))
[Link] = [Link];
else
[Link] = [Link];
}
private void TCubTR_TextChanged(object sender, EventArgs e)
if ([Link]("i"))
[Link] = [Link];
else
[Link] = [Link];