Thanks, it works very well for my simple needs. However I found that the solutions had some problems with surtain types of equations, so I decided to make a small update, where you need an extra button and an extra textbox on the xaml form:
Imports System.Numerics
Imports System.Text.RegularExpressions
Imports System.Globalization
Class MainWindow
Dim a, b, c, d, ee As New Complex
Dim Real As String = "(?<!([E][+-][0-9]+))([-]?\d+\.?\d*([E][+-][0-9]+)?(?!([i0-9.E]))|[-]?\d*\.?\d+([E][+-][0-9]+)?)(?![i0-9.E])"
Dim Img As String = "(?<!([E][+-][0-9]+))([-]?\d+\.?\d*([E][+-][0-9]+)?(?![0-9.E])(?:i)|([-]?\d*\.?\d+)?([E][+-][0-9]+)?\s*(?:i)(?![0-9.E]))"
Private Sub Button1_Click(sender As System.Object, e As System.Windows.RoutedEventArgs) Handles Button1.Click
a = GenerateComplexNumberFromString(txtA.Text)
b = GenerateComplexNumberFromString(txtB.Text)
c = GenerateComplexNumberFromString(txtC.Text)
d = GenerateComplexNumberFromString(txtD.Text)
ee = GenerateComplexNumberFromString(txtE.Text)
Dim res As New List(Of Complex)
res = PolynominalEquationSolver(a, b, c, d, ee)
txtResult.Text = "Function: " & vbCrLf & a.Real & "*x^4 + " & b.Real & "*x^3 + " & c.Real & "*x^2 + " & d.Real & "*x + " & ee.Real & " = 0" & vbCrLf & "With the following solutions: " & vbCrLf
For Each f As Complex In res
txtResult.Text &= f.ToString & vbCrLf
Next
End Sub
Public Function GenerateComplexNumberFromString(ByVal input As String) As Complex
input = input.Replace(" ", "")
Dim Number As String = "((?<Real>(" & Real & "))|(?<Imag>(" & Img & ")))"
Dim Re, Im As Double
Re = 0
Im = 0
For Each Match As Match In Regex.Matches(input, Number)
If Not Match.Groups("Real").Value = String.Empty Then
Re = Double.Parse(Match.Groups("Real").Value, CultureInfo.InvariantCulture)
End If
If Not Match.Groups("Imag").Value = String.Empty Then
If Match.Groups("Imag").Value.ToString.Replace(" ", "") = "-i" Then
Im = Double.Parse("-1", CultureInfo.InvariantCulture)
ElseIf Match.Groups("Imag").Value.ToString.Replace(" ", "") = "i" Then
Im = Double.Parse("1", CultureInfo.InvariantCulture)
Else
Im = Double.Parse(Match.Groups("Imag").Value.ToString.Replace("i", ""), CultureInfo.InvariantCulture)
End If
End If
Next
Dim result As New Complex(Re, Im)
Return result
End Function
Public Function PolynominalEquationSolver(ByVal a As Complex, ByVal b As Complex, ByVal c As Complex, ByVal d As Complex, ByVal e As Complex) As List(Of Complex)
Dim result As New List(Of Complex)
Dim x1, x2, x3, x4, x_1, x_2, x_3, x_4 As New Complex
If a <> 0 Then
Dim res2 As New List(Of Complex)
Dim n1, n2, n3, n4 As New Complex
If a.Real <> 0 And b.Real = 0 And c.Real = 0 And d.Real <> 0 Then
n1 = 1 / 2 * Complex.Sqrt(Complex.Pow(Complex.Sqrt(3) * Complex.Sqrt(27 * Complex.Pow(a, 2) * Complex.Pow(d, 4) - 256 * Complex.Pow(e, 3) * Complex.Pow(a, 3)) + 9 * a * Complex.Pow(d, 2), (1 / 3)) / (2 ^ (1 / 3) * 3 ^ (2 / 3) * a) + (4 * (2 / 3) ^ (1 / 3) * e) / Complex.Pow(Complex.Sqrt(3) * Complex.Sqrt(27 * Complex.Pow(a, 2) * Complex.Pow(d, 4) - 256 * Complex.Pow(e, 3) * Complex.Pow(a, 3)) + 9 * a * Complex.Pow(d, 2), (1 / 3))) - 1 / 2 * Complex.Sqrt(-(2 * d) / (a * Complex.Sqrt(Complex.Pow(Complex.Sqrt(3) * Complex.Sqrt(27 * Complex.Pow(a, 2) * Complex.Pow(d, 4) - 256 * Complex.Pow(e, 3) * Complex.Pow(a, 3)) + 9 * a * Complex.Pow(d, 2), (1 / 3)) / (2 ^ (1 / 3) * 3 ^ (2 / 3) * a) + (4 * (2 / 3) ^ (1 / 3) * e) / Complex.Pow(Complex.Sqrt(3) * Complex.Sqrt(27 * Complex.Pow(a, 2) * Complex.Pow(d, 4) - 256 * Complex.Pow(e, 3) * Complex.Pow(a, 3)) + 9 * a * Complex.Pow(d, 2), (1 / 3)))) - Complex.Pow(Complex.Sqrt(3) * Complex.Sqrt(27 * Complex.Pow(a, 2) * Complex.Pow(d, 4) - 256 * Complex.Pow(e, 3) * Complex.Pow(a, 3)) + 9 * a * Complex.Pow(d, 2), (1 / 3)) / (2 ^ (1 / 3) * 3 ^ (2 / 3) * a) - (4 * (2 / 3) ^ (1 / 3) * e) / Complex.Pow(Complex.Sqrt(3) * Complex.Sqrt(27 * Complex.Pow(a, 2) * Complex.Pow(d, 4) - 256 * Complex.Pow(e, 3) * Complex.Pow(a, 3)) + 9 * a * Complex.Pow(d, 2), (1 / 3)))
n2 = 1 / 2 * Complex.Sqrt(Complex.Pow(Complex.Sqrt(3) * Complex.Sqrt(27 * Complex.Pow(a, 2) * Complex.Pow(d, 4) - 256 * Complex.Pow(e, 3) * Complex.Pow(a, 3)) + 9 * a * Complex.Pow(d, 2), (1 / 3)) / (2 ^ (1 / 3) * 3 ^ (2 / 3) * a) + (4 * (2 / 3) ^ (1 / 3) * e) / Complex.Pow(Complex.Sqrt(3) * Complex.Sqrt(27 * Complex.Pow(a, 2) * Complex.Pow(d, 4) - 256 * Complex.Pow(e, 3) * Complex.Pow(a, 3)) + 9 * a * Complex.Pow(d, 2), (1 / 3))) + 1 / 2 * Complex.Sqrt(-(2 * d) / (a * Complex.Sqrt(Complex.Pow(Complex.Sqrt(3) * Complex.Sqrt(27 * Complex.Pow(a, 2) * Complex.Pow(d, 4) - 256 * Complex.Pow(e, 3) * Complex.Pow(a, 3)) + 9 * a * Complex.Pow(d, 2), (1 / 3)) / (2 ^ (1 / 3) * 3 ^ (2 / 3) * a) + (4 * (2 / 3) ^ (1 / 3) * e) / Complex.Pow(Complex.Sqrt(3) * Complex.Sqrt(27 * Complex.Pow(a, 2) * Complex.Pow(d, 4) - 256 * Complex.Pow(e, 3) * Complex.Pow(a, 3)) + 9 * a * Complex.Pow(d, 2), (1 / 3)))) - Complex.Pow(Complex.Sqrt(3) * Complex.Sqrt(27 * Complex.Pow(a, 2) * Complex.Pow(d, 4) - 256 * Complex.Pow(e, 3) * Complex.Pow(a, 3)) + 9 * a * Complex.Pow(d, 2), (1 / 3)) / (2 ^ (1 / 3) * 3 ^ (2 / 3) * a) - (4 * (2 / 3) ^ (1 / 3) * e) / Complex.Pow(Complex.Sqrt(3) * Complex.Sqrt(27 * Complex.Pow(a, 2) * Complex.Pow(d, 4) - 256 * Complex.Pow(e, 3) * Complex.Pow(a, 3)) + 9 * a * Complex.Pow(d, 2), (1 / 3)))
n3 = -1 / 2 * Complex.Sqrt(Complex.Pow(Complex.Sqrt(3) * Complex.Sqrt(27 * Complex.Pow(a, 2) * Complex.Pow(d, 4) - 256 * Complex.Pow(e, 3) * Complex.Pow(a, 3)) + 9 * a * Complex.Pow(d, 2), (1 / 3)) / (2 ^ (1 / 3) * 3 ^ (2 / 3) * a) + (4 * (2 / 3) ^ (1 / 3) * e) / Complex.Pow(Complex.Sqrt(3) * Complex.Sqrt(27 * Complex.Pow(a, 2) * Complex.Pow(d, 4) - 256 * Complex.Pow(e, 3) * Complex.Pow(a, 3)) + 9 * a * Complex.Pow(d, 2), (1 / 3))) - 1 / 2 * Complex.Sqrt((2 * d) / (a * Complex.Sqrt(Complex.Pow(Complex.Sqrt(3) * Complex.Sqrt(27 * Complex.Pow(a, 2) * Complex.Pow(d, 4) - 256 * Complex.Pow(e, 3) * Complex.Pow(a, 3)) + 9 * a * Complex.Pow(d, 2), (1 / 3)) / (2 ^ (1 / 3) * 3 ^ (2 / 3) * a) + (4 * (2 / 3) ^ (1 / 3) * e) / Complex.Pow(Complex.Sqrt(3) * Complex.Sqrt(27 * Complex.Pow(a, 2) * Complex.Pow(d, 4) - 256 * Complex.Pow(e, 3) * Complex.Pow(a, 3)) + 9 * a * Complex.Pow(d, 2), (1 / 3)))) - Complex.Pow(Complex.Sqrt(3) * Complex.Sqrt(27 * Complex.Pow(a, 2) * Complex.Pow(d, 4) - 256 * Complex.Pow(e, 3) * Complex.Pow(a, 3)) + 9 * a * Complex.Pow(d, 2), (1 / 3)) / (2 ^ (1 / 3) * 3 ^ (2 / 3) * a) - (4 * (2 / 3) ^ (1 / 3) * e) / Complex.Pow(Complex.Sqrt(3) * Complex.Sqrt(27 * Complex.Pow(a, 2) * Complex.Pow(d, 4) - 256 * Complex.Pow(e, 3) * Complex.Pow(a, 3)) + 9 * a * Complex.Pow(d, 2), (1 / 3)))
n4 = 1 / 2 * Complex.Sqrt((2 * d) / (a * Complex.Sqrt(Complex.Pow(Complex.Sqrt(3) * Complex.Sqrt(27 * Complex.Pow(a, 2) * Complex.Pow(d, 4) - 256 * Complex.Pow(e, 3) * Complex.Pow(a, 3)) + 9 * a * Complex.Pow(d, 2), (1 / 3)) / (2 ^ (1 / 3) * 3 ^ (2 / 3) * a) + (4 * (2 / 3) ^ (1 / 3) * e) / Complex.Pow(Complex.Sqrt(3) * Complex.Sqrt(27 * Complex.Pow(a, 2) * Complex.Pow(d, 4) - 256 * Complex.Pow(e, 3) * Complex.Pow(a, 3)) + 9 * a * Complex.Pow(d, 2), (1 / 3)))) - Complex.Pow(Complex.Sqrt(3) * Complex.Sqrt(27 * Complex.Pow(a, 2) * Complex.Pow(d, 4) - 256 * Complex.Pow(e, 3) * Complex.Pow(a, 3)) + 9 * a * Complex.Pow(d, 2), (1 / 3)) / (2 ^ (1 / 3) * 3 ^ (2 / 3) * a) - (4 * (2 / 3) ^ (1 / 3) * e) / Complex.Pow(Complex.Sqrt(3) * Complex.Sqrt(27 * Complex.Pow(a, 2) * Complex.Pow(d, 4) - 256 * Complex.Pow(e, 3) * Complex.Pow(a, 3)) + 9 * a * Complex.Pow(d, 2), (1 / 3))) - 1 / 2 * Complex.Sqrt(Complex.Pow(Complex.Sqrt(3) * Complex.Sqrt(27 * Complex.Pow(a, 2) * Complex.Pow(d, 4) - 256 * Complex.Pow(e, 3) * Complex.Pow(a, 3)) + 9 * a * Complex.Pow(d, 2), (1 / 3)) / (2 ^ (1 / 3) * 3 ^ (2 / 3) * a) + (4 * (2 / 3) ^ (1 / 3) * e) / Complex.Pow(Complex.Sqrt(3) * Complex.Sqrt(27 * Complex.Pow(a, 2) * Complex.Pow(d, 4) - 256 * Complex.Pow(e, 3) * Complex.Pow(a, 3)) + 9 * a * Complex.Pow(d, 2), (1 / 3)))
result.Clear()
result.Add(n1)
result.Add(n2)
result.Add(n3)
result.Add(n4)
txtDescription.Text = "The original polynomial were both b*x^3 = 0 and c*x^2 = 0"
ElseIf a.Real <> 0 And b.Real <> 0 And c.Real = 0 And d.Real = 0 Then
n1 = 1 / 2 * Complex.Sqrt((Complex.Pow(e / 2, 1 / 3) * Complex.Pow(Complex.Sqrt(3) * Complex.Sqrt(27 * Complex.Pow(b, 4) - 256 * e * Complex.Pow(a, 3)) + 9 * Complex.Pow(b, 2), (1 / 3))) / (3 ^ (2 / 3) * a) + (4 * (2 / 3) ^ (1 / 3) * Complex.Pow(e, 2 / 3)) / Complex.Pow(Complex.Sqrt(3) * Complex.Sqrt(27 * Complex.Pow(b, 4) - 256 * e * Complex.Pow(a, 3)) + 9 * Complex.Pow(b, 2), (1 / 3)) + Complex.Pow(b, 2) / (4 * Complex.Pow(a, 2))) - 1 / 2 * Complex.Sqrt(-(Complex.Pow(e / 2, 1 / 3) * Complex.Pow(Complex.Sqrt(3) * Complex.Sqrt(27 * Complex.Pow(b, 4) - 256 * e * Complex.Pow(a, 3)) + 9 * Complex.Pow(b, 2), (1 / 3))) / (3 ^ (2 / 3) * a) - (4 * (2 / 3) ^ (1 / 3) * Complex.Pow(e, 2 / 3)) / Complex.Pow(Complex.Sqrt(3) * Complex.Sqrt(27 * Complex.Pow(b, 4) - 256 * e * Complex.Pow(a, 3)) + 9 * Complex.Pow(b, 2), (1 / 3)) + Complex.Pow(b, 2) / (2 * Complex.Pow(a, 2)) - Complex.Pow(b, 3) / (4 * Complex.Pow(a, 3) * Complex.Sqrt((Complex.Pow(e / 2, 1 / 3) * Complex.Pow(Complex.Sqrt(3) * Complex.Sqrt(27 * Complex.Pow(b, 4) - 256 * e * Complex.Pow(a, 3)) + 9 * Complex.Pow(b, 2), (1 / 3))) / (3 ^ (2 / 3) * a) + (4 * (2 / 3) ^ (1 / 3) * Complex.Pow(e, 2 / 3)) / Complex.Pow(Complex.Sqrt(3) * Complex.Sqrt(27 * Complex.Pow(b, 4) - 256 * e * Complex.Pow(a, 3)) + 9 * Complex.Pow(b, 2), (1 / 3)) + Complex.Pow(b, 2) / (4 * Complex.Pow(a, 2))))) - b / (4 * a)
n2 = 1 / 2 * Complex.Sqrt((Complex.Pow(e / 2, 1 / 3) * Complex.Pow(Complex.Sqrt(3) * Complex.Sqrt(27 * Complex.Pow(b, 4) - 256 * e * Complex.Pow(a, 3)) + 9 * Complex.Pow(b, 2), (1 / 3))) / (3 ^ (2 / 3) * a) + (4 * (2 / 3) ^ (1 / 3) * Complex.Pow(e, 2 / 3)) / Complex.Pow(Complex.Sqrt(3) * Complex.Sqrt(27 * Complex.Pow(b, 4) - 256 * e * Complex.Pow(a, 3)) + 9 * Complex.Pow(b, 2), (1 / 3)) + Complex.Pow(b, 2) / (4 * Complex.Pow(a, 2))) + 1 / 2 * Complex.Sqrt(-(Complex.Pow(e / 2, 1 / 3) * Complex.Pow(Complex.Sqrt(3) * Complex.Sqrt(27 * Complex.Pow(b, 4) - 256 * e * Complex.Pow(a, 3)) + 9 * Complex.Pow(b, 2), (1 / 3))) / (3 ^ (2 / 3) * a) - (4 * (2 / 3) ^ (1 / 3) * Complex.Pow(e, 2 / 3)) / Complex.Pow(Complex.Sqrt(3) * Complex.Sqrt(27 * Complex.Pow(b, 4) - 256 * e * Complex.Pow(a, 3)) + 9 * Complex.Pow(b, 2), (1 / 3)) + Complex.Pow(b, 2) / (2 * Complex.Pow(a, 2)) - Complex.Pow(b, 3) / (4 * Complex.Pow(a, 3) * Complex.Sqrt((Complex.Pow(e / 2, 1 / 3) * Complex.Pow(Complex.Sqrt(3) * Complex.Sqrt(27 * Complex.Pow(b, 4) - 256 * e * Complex.Pow(a, 3)) + 9 * Complex.Pow(b, 2), (1 / 3))) / (3 ^ (2 / 3) * a) + (4 * (2 / 3) ^ (1 / 3) * Complex.Pow(e, 2 / 3)) / Complex.Pow(Complex.Sqrt(3) * Complex.Sqrt(27 * Complex.Pow(b, 4) - 256 * e * Complex.Pow(a, 3)) + 9 * Complex.Pow(b, 2), (1 / 3)) + Complex.Pow(b, 2) / (4 * Complex.Pow(a, 2))))) - b / (4 * a)
n3 = -1 / 2 * Complex.Sqrt((Complex.Pow(e / 2, 1 / 3) * Complex.Pow(Complex.Sqrt(3) * Complex.Sqrt(27 * Complex.Pow(b, 4) - 256 * e * Complex.Pow(a, 3)) + 9 * Complex.Pow(b, 2), (1 / 3))) / (3 ^ (2 / 3) * a) + (4 * (2 / 3) ^ (1 / 3) * Complex.Pow(e, 2 / 3)) / Complex.Pow(Complex.Sqrt(3) * Complex.Sqrt(27 * Complex.Pow(b, 4) - 256 * e * Complex.Pow(a, 3)) + 9 * Complex.Pow(b, 2), (1 / 3)) + Complex.Pow(b, 2) / (4 * Complex.Pow(a, 2))) - 1 / 2 * Complex.Sqrt(-(Complex.Pow(e / 2, 1 / 3) * Complex.Pow(Complex.Sqrt(3) * Complex.Sqrt(27 * Complex.Pow(b, 4) - 256 * e * Complex.Pow(a, 3)) + 9 * Complex.Pow(b, 2), (1 / 3))) / (3 ^ (2 / 3) * a) - (4 * (2 / 3) ^ (1 / 3) * Complex.Pow(e, 2 / 3)) / Complex.Pow(Complex.Sqrt(3) * Complex.Sqrt(27 * Complex.Pow(b, 4) - 256 * e * Complex.Pow(a, 3)) + 9 * Complex.Pow(b, 2), (1 / 3)) + Complex.Pow(b, 2) / (2 * Complex.Pow(a, 2)) + Complex.Pow(b, 3) / (4 * Complex.Pow(a, 3) * Complex.Sqrt((Complex.Pow(e / 2, 1 / 3) * Complex.Pow(Complex.Sqrt(3) * Complex.Sqrt(27 * Complex.Pow(b, 4) - 256 * e * Complex.Pow(a, 3)) + 9 * Complex.Pow(b, 2), (1 / 3))) / (3 ^ (2 / 3) * a) + (4 * (2 / 3) ^ (1 / 3) * Complex.Pow(e, 2 / 3)) / Complex.Pow(Complex.Sqrt(3) * Complex.Sqrt(27 * Complex.Pow(b, 4) - 256 * e * Complex.Pow(a, 3)) + 9 * Complex.Pow(b, 2), (1 / 3)) + Complex.Pow(b, 2) / (4 * Complex.Pow(a, 2))))) - b / (4 * a)
n4 = -1 / 2 * Complex.Sqrt((Complex.Pow(e / 2, 1 / 3) * Complex.Pow(Complex.Sqrt(3) * Complex.Sqrt(27 * Complex.Pow(b, 4) - 256 * e * Complex.Pow(a, 3)) + 9 * Complex.Pow(b, 2), (1 / 3))) / (3 ^ (2 / 3) * a) + (4 * (2 / 3) ^ (1 / 3) * Complex.Pow(e, 2 / 3)) / Complex.Pow(Complex.Sqrt(3) * Complex.Sqrt(27 * Complex.Pow(b, 4) - 256 * e * Complex.Pow(a, 3)) + 9 * Complex.Pow(b, 2), (1 / 3)) + Complex.Pow(b, 2) / (4 * Complex.Pow(a, 2))) + 1 / 2 * Complex.Sqrt(-(Complex.Pow(e / 2, 1 / 3) * Complex.Pow(Complex.Sqrt(3) * Complex.Sqrt(27 * Complex.Pow(b, 4) - 256 * e * Complex.Pow(a, 3)) + 9 * Complex.Pow(b, 2), (1 / 3))) / (3 ^ (2 / 3) * a) - (4 * (2 / 3) ^ (1 / 3) * Complex.Pow(e, 2 / 3)) / Complex.Pow(Complex.Sqrt(3) * Complex.Sqrt(27 * Complex.Pow(b, 4) - 256 * e * Complex.Pow(a, 3)) + 9 * Complex.Pow(b, 2), (1 / 3)) + Complex.Pow(b, 2) / (2 * Complex.Pow(a, 2)) + Complex.Pow(b, 3) / (4 * Complex.Pow(a, 3) * Complex.Sqrt((Complex.Pow(e / 2, 1 / 3) * Complex.Pow(Complex.Sqrt(3) * Complex.Sqrt(27 * Complex.Pow(b, 4) - 256 * e * Complex.Pow(a, 3)) + 9 * Complex.Pow(b, 2), (1 / 3))) / (3 ^ (2 / 3) * a) + (4 * (2 / 3) ^ (1 / 3) * Complex.Pow(e, 2 / 3)) / Complex.Pow(Complex.Sqrt(3) * Complex.Sqrt(27 * Complex.Pow(b, 4) - 256 * e * Complex.Pow(a, 3)) + 9 * Complex.Pow(b, 2), (1 / 3)) + Complex.Pow(b, 2) / (4 * Complex.Pow(a, 2))))) - b / (4 * a)
result.Clear()
result.Add(n1)
result.Add(n2)
result.Add(n3)
result.Add(n4)
txtDescription.Text = "The original polynomial were both c*x^2 = 0 and d*x = 0"
ElseIf a.Real <> 0 And b.Real <> 0 And c.Real = 0 And d.Real <> 0 Then
n1 = -1 / 2 * Complex.Sqrt(Complex.Pow(b, 2) / (4 * Complex.Pow(a, 2)) + Complex.Pow(Complex.Sqrt(Complex.Pow(27 * a * Complex.Pow(d, 2) + 27 * e * Complex.Pow(b, 2), 2) - 4 * Complex.Pow(12 * e * a - 3 * b * d, 3)) + 27 * a * Complex.Pow(d, 2) + 27 * e * Complex.Pow(b, 2), (1 / 3)) / (3 * 2 ^ (1 / 3) * a) + (2 ^ (1 / 3) * (4 * e * a - b * d)) / (a * Complex.Pow(Complex.Sqrt(Complex.Pow(27 * a * Complex.Pow(d, 2) + 27 * e * Complex.Pow(b, 2), 2) - 4 * Complex.Pow(12 * e * a - 3 * b * d, 3)) + 27 * a * Complex.Pow(d, 2) + 27 * e * Complex.Pow(b, 2), (1 / 3)))) - 1 / 2 * Complex.Sqrt(Complex.Pow(b, 2) / (2 * Complex.Pow(a, 2)) - (-Complex.Pow(b, 3) / Complex.Pow(a, 3) - (8 * d) / a) / (4 * Complex.Sqrt(Complex.Pow(b, 2) / (4 * Complex.Pow(a, 2)) + Complex.Pow(Complex.Sqrt(Complex.Pow(27 * a * Complex.Pow(d, 2) + 27 * e * Complex.Pow(b, 2), 2) - 4 * Complex.Pow(12 * e * a - 3 * b * d, 3)) + 27 * a * Complex.Pow(d, 2) + 27 * e * Complex.Pow(b, 2), (1 / 3)) / (3 * 2 ^ (1 / 3) * a) + (2 ^ (1 / 3) * (4 * e * a - b * d)) / (a * Complex.Pow(Complex.Sqrt(Complex.Pow(27 * a * Complex.Pow(d, 2) + 27 * e * Complex.Pow(b, 2), 2) - 4 * Complex.Pow(12 * e * a - 3 * b * d, 3)) + 27 * a * Complex.Pow(d, 2) + 27 * e * Complex.Pow(b, 2), (1 / 3))))) - Complex.Pow(Complex.Sqrt(Complex.Pow(27 * a * Complex.Pow(d, 2) + 27 * e * Complex.Pow(b, 2), 2) - 4 * Complex.Pow(12 * e * a - 3 * b * d, 3)) + 27 * a * Complex.Pow(d, 2) + 27 * e * Complex.Pow(b, 2), (1 / 3)) / (3 * 2 ^ (1 / 3) * a) - (2 ^ (1 / 3) * (4 * e * a - b * d)) / (a * Complex.Pow(Complex.Sqrt(Complex.Pow(27 * a * Complex.Pow(d, 2) + 27 * e * Complex.Pow(b, 2), 2) - 4 * Complex.Pow(12 * e * a - 3 * b * d, 3)) + 27 * a * Complex.Pow(d, 2) + 27 * e * Complex.Pow(b, 2), (1 / 3)))) - b / (4 * a)
n2 = -1 / 2 * Complex.Sqrt(Complex.Pow(b, 2) / (4 * Complex.Pow(a, 2)) + Complex.Pow(Complex.Sqrt(Complex.Pow(27 * a * Complex.Pow(d, 2) + 27 * e * Complex.Pow(b, 2), 2) - 4 * Complex.Pow(12 * e * a - 3 * b * d, 3)) + 27 * a * Complex.Pow(d, 2) + 27 * e * Complex.Pow(b, 2), (1 / 3)) / (3 * 2 ^ (1 / 3) * a) + (2 ^ (1 / 3) * (4 * e * a - b * d)) / (a * Complex.Pow(Complex.Sqrt(Complex.Pow(27 * a * Complex.Pow(d, 2) + 27 * e * Complex.Pow(b, 2), 2) - 4 * Complex.Pow(12 * e * a - 3 * b * d, 3)) + 27 * a * Complex.Pow(d, 2) + 27 * e * Complex.Pow(b, 2), (1 / 3)))) + 1 / 2 * Complex.Sqrt(Complex.Pow(b, 2) / (2 * Complex.Pow(a, 2)) - (-Complex.Pow(b, 3) / Complex.Pow(a, 3) - (8 * d) / a) / (4 * Complex.Sqrt(Complex.Pow(b, 2) / (4 * Complex.Pow(a, 2)) + Complex.Pow(Complex.Sqrt(Complex.Pow(27 * a * Complex.Pow(d, 2) + 27 * e * Complex.Pow(b, 2), 2) - 4 * Complex.Pow(12 * e * a - 3 * b * d, 3)) + 27 * a * Complex.Pow(d, 2) + 27 * e * Complex.Pow(b, 2), (1 / 3)) / (3 * 2 ^ (1 / 3) * a) + (2 ^ (1 / 3) * (4 * e * a - b * d)) / (a * Complex.Pow(Complex.Sqrt(Complex.Pow(27 * a * Complex.Pow(d, 2) + 27 * e * Complex.Pow(b, 2), 2) - 4 * Complex.Pow(12 * e * a - 3 * b * d, 3)) + 27 * a * Complex.Pow(d, 2) + 27 * e * Complex.Pow(b, 2), (1 / 3))))) - Complex.Pow(Complex.Sqrt(Complex.Pow(27 * a * Complex.Pow(d, 2) + 27 * e * Complex.Pow(b, 2), 2) - 4 * Complex.Pow(12 * e * a - 3 * b * d, 3)) + 27 * a * Complex.Pow(d, 2) + 27 * e * Complex.Pow(b, 2), (1 / 3)) / (3 * 2 ^ (1 / 3) * a) - (2 ^ (1 / 3) * (4 * e * a - b * d)) / (a * Complex.Pow(Complex.Sqrt(Complex.Pow(27 * a * Complex.Pow(d, 2) + 27 * e * Complex.Pow(b, 2), 2) - 4 * Complex.Pow(12 * e * a - 3 * b * d, 3)) + 27 * a * Complex.Pow(d, 2) + 27 * e * Complex.Pow(b, 2), (1 / 3)))) - b / (4 * a)
n3 = 1 / 2 * Complex.Sqrt(Complex.Pow(b, 2) / (4 * Complex.Pow(a, 2)) + Complex.Pow(Complex.Sqrt(Complex.Pow(27 * a * Complex.Pow(d, 2) + 27 * e * Complex.Pow(b, 2), 2) - 4 * Complex.Pow(12 * e * a - 3 * b * d, 3)) + 27 * a * Complex.Pow(d, 2) + 27 * e * Complex.Pow(b, 2), (1 / 3)) / (3 * 2 ^ (1 / 3) * a) + (2 ^ (1 / 3) * (4 * e * a - b * d)) / (a * Complex.Pow(Complex.Sqrt(Complex.Pow(27 * a * Complex.Pow(d, 2) + 27 * e * Complex.Pow(b, 2), 2) - 4 * Complex.Pow(12 * e * a - 3 * b * d, 3)) + 27 * a * Complex.Pow(d, 2) + 27 * e * Complex.Pow(b, 2), (1 / 3)))) - 1 / 2 * Complex.Sqrt(Complex.Pow(b, 2) / (2 * Complex.Pow(a, 2)) + (-Complex.Pow(b, 3) / Complex.Pow(a, 3) - (8 * d) / a) / (4 * Complex.Sqrt(Complex.Pow(b, 2) / (4 * Complex.Pow(a, 2)) + Complex.Pow(Complex.Sqrt(Complex.Pow(27 * a * Complex.Pow(d, 2) + 27 * e * Complex.Pow(b, 2), 2) - 4 * Complex.Pow(12 * e * a - 3 * b * d, 3)) + 27 * a * Complex.Pow(d, 2) + 27 * e * Complex.Pow(b, 2), (1 / 3)) / (3 * 2 ^ (1 / 3) * a) + (2 ^ (1 / 3) * (4 * e * a - b * d)) / (a * Complex.Pow(Complex.Sqrt(Complex.Pow(27 * a * Complex.Pow(d, 2) + 27 * e * Complex.Pow(b, 2), 2) - 4 * Complex.Pow(12 * e * a - 3 * b * d, 3)) + 27 * a * Complex.Pow(d, 2) + 27 * e * Complex.Pow(b, 2), (1 / 3))))) - Complex.Pow(Complex.Sqrt(Complex.Pow(27 * a * Complex.Pow(d, 2) + 27 * e * Complex.Pow(b, 2), 2) - 4 * Complex.Pow(12 * e * a - 3 * b * d, 3)) + 27 * a * Complex.Pow(d, 2) + 27 * e * Complex.Pow(b, 2), (1 / 3)) / (3 * 2 ^ (1 / 3) * a) - (2 ^ (1 / 3) * (4 * e * a - b * d)) / (a * Complex.Pow(Complex.Sqrt(Complex.Pow(27 * a * Complex.Pow(d, 2) + 27 * e * Complex.Pow(b, 2), 2) - 4 * Complex.Pow(12 * e * a - 3 * b * d, 3)) + 27 * a * Complex.Pow(d, 2) + 27 * e * Complex.Pow(b, 2), (1 / 3)))) - b / (4 * a)
n4 = 1 / 2 * Complex.Sqrt(Complex.Pow(b, 2) / (4 * Complex.Pow(a, 2)) + Complex.Pow(Complex.Sqrt(Complex.Pow(27 * a * Complex.Pow(d, 2) + 27 * e * Complex.Pow(b, 2), 2) - 4 * Complex.Pow(12 * e * a - 3 * b * d, 3)) + 27 * a * Complex.Pow(d, 2) + 27 * e * Complex.Pow(b, 2), (1 / 3)) / (3 * 2 ^ (1 / 3) * a) + (2 ^ (1 / 3) * (4 * e * a - b * d)) / (a * Complex.Pow(Complex.Sqrt(Complex.Pow(27 * a * Complex.Pow(d, 2) + 27 * e * Complex.Pow(b, 2), 2) - 4 * Complex.Pow(12 * e * a - 3 * b * d, 3)) + 27 * a * Complex.Pow(d, 2) + 27 * e * Complex.Pow(b, 2), (1 / 3)))) + 1 / 2 * Complex.Sqrt(Complex.Pow(b, 2) / (2 * Complex.Pow(a, 2)) + (-Complex.Pow(b, 3) / Complex.Pow(a, 3) - (8 * d) / a) / (4 * Complex.Sqrt(Complex.Pow(b, 2) / (4 * Complex.Pow(a, 2)) + Complex.Pow(Complex.Sqrt(Complex.Pow(27 * a * Complex.Pow(d, 2) + 27 * e * Complex.Pow(b, 2), 2) - 4 * Complex.Pow(12 * e * a - 3 * b * d, 3)) + 27 * a * Complex.Pow(d, 2) + 27 * e * Complex.Pow(b, 2), (1 / 3)) / (3 * 2 ^ (1 / 3) * a) + (2 ^ (1 / 3) * (4 * e * a - b * d)) / (a * Complex.Pow(Complex.Sqrt(Complex.Pow(27 * a * Complex.Pow(d, 2) + 27 * e * Complex.Pow(b, 2), 2) - 4 * Complex.Pow(12 * e * a - 3 * b * d, 3)) + 27 * a * Complex.Pow(d, 2) + 27 * e * Complex.Pow(b, 2), (1 / 3))))) - Complex.Pow(Complex.Sqrt(Complex.Pow(27 * a * Complex.Pow(d, 2) + 27 * e * Complex.Pow(b, 2), 2) - 4 * Complex.Pow(12 * e * a - 3 * b * d, 3)) + 27 * a * Complex.Pow(d, 2) + 27 * e * Complex.Pow(b, 2), (1 / 3)) / (3 * 2 ^ (1 / 3) * a) - (2 ^ (1 / 3) * (4 * e * a - b * d)) / (a * Complex.Pow(Complex.Sqrt(Complex.Pow(27 * a * Complex.Pow(d, 2) + 27 * e * Complex.Pow(b, 2), 2) - 4 * Complex.Pow(12 * e * a - 3 * b * d, 3)) + 27 * a * Complex.Pow(d, 2) + 27 * e * Complex.Pow(b, 2), (1 / 3)))) - b / (4 * a)
result.Clear()
result.Add(n1)
result.Add(n2)
result.Add(n3)
result.Add(n4)
txtDescription.Text = "The original polynomial were c*x^2 = 0"
ElseIf a.Real <> 0 And b.Real = 0 And c.Real <> 0 And d.Real <> 0 Then
n1 = 1 / 2 * Complex.Sqrt(Complex.Pow(Complex.Sqrt(Complex.Pow(-72 * e * a * c + 27 * a * Complex.Pow(d, 2) + 2 * Complex.Pow(c, 3), 2) - 4 * Complex.Pow(12 * e * a + Complex.Pow(c, 2), 3)) - 72 * e * a * c + 27 * a * Complex.Pow(d, 2) + 2 * Complex.Pow(c, 3), (1 / 3)) / (3 * 2 ^ (1 / 3) * a) + (2 ^ (1 / 3) * (12 * e * a + Complex.Pow(c, 2))) / (3 * a * Complex.Pow(Complex.Sqrt(Complex.Pow(-72 * e * a * c + 27 * a * Complex.Pow(d, 2) + 2 * Complex.Pow(c, 3), 2) - 4 * Complex.Pow(12 * e * a + Complex.Pow(c, 2), 3)) - 72 * e * a * c + 27 * a * Complex.Pow(d, 2) + 2 * Complex.Pow(c, 3), (1 / 3))) - (2 * c) / (3 * a)) - 1 / 2 * Complex.Sqrt(-Complex.Pow(Complex.Sqrt(Complex.Pow(-72 * e * a * c + 27 * a * Complex.Pow(d, 2) + 2 * Complex.Pow(c, 3), 2) - 4 * Complex.Pow(12 * e * a + Complex.Pow(c, 2), 3)) - 72 * e * a * c + 27 * a * Complex.Pow(d, 2) + 2 * Complex.Pow(c, 3), (1 / 3)) / (3 * 2 ^ (1 / 3) * a) - (2 ^ (1 / 3) * (12 * e * a + Complex.Pow(c, 2))) / (3 * a * Complex.Pow(Complex.Sqrt(Complex.Pow(-72 * e * a * c + 27 * a * Complex.Pow(d, 2) + 2 * Complex.Pow(c, 3), 2) - 4 * Complex.Pow(12 * e * a + Complex.Pow(c, 2), 3)) - 72 * e * a * c + 27 * a * Complex.Pow(d, 2) + 2 * Complex.Pow(c, 3), (1 / 3))) - (2 * d) / (a * Complex.Sqrt(Complex.Pow(Complex.Sqrt(Complex.Pow(-72 * e * a * c + 27 * a * Complex.Pow(d, 2) + 2 * Complex.Pow(c, 3), 2) - 4 * Complex.Pow(12 * e * a + Complex.Pow(c, 2), 3)) - 72 * e * a * c + 27 * a * Complex.Pow(d, 2) + 2 * Complex.Pow(c, 3), (1 / 3)) / (3 * 2 ^ (1 / 3) * a) + (2 ^ (1 / 3) * (12 * e * a + Complex.Pow(c, 2))) / (3 * a * Complex.Pow(Complex.Sqrt(Complex.Pow(-72 * e * a * c + 27 * a * Complex.Pow(d, 2) + 2 * Complex.Pow(c, 3), 2) - 4 * Complex.Pow(12 * e * a + Complex.Pow(c, 2), 3)) - 72 * e * a * c + 27 * a * Complex.Pow(d, 2) + 2 * Complex.Pow(c, 3), (1 / 3))) - (2 * c) / (3 * a))) - (4 * c) / (3 * a))
n2 = 1 / 2 * Complex.Sqrt(Complex.Pow(Complex.Sqrt(Complex.Pow(-72 * e * a * c + 27 * a * Complex.Pow(d, 2) + 2 * Complex.Pow(c, 3), 2) - 4 * Complex.Pow(12 * e * a + Complex.Pow(c, 2), 3)) - 72 * e * a * c + 27 * a * Complex.Pow(d, 2) + 2 * Complex.Pow(c, 3), (1 / 3)) / (3 * 2 ^ (1 / 3) * a) + (2 ^ (1 / 3) * (12 * e * a + Complex.Pow(c, 2))) / (3 * a * Complex.Pow(Complex.Sqrt(Complex.Pow(-72 * e * a * c + 27 * a * Complex.Pow(d, 2) + 2 * Complex.Pow(c, 3), 2) - 4 * Complex.Pow(12 * e * a + Complex.Pow(c, 2), 3)) - 72 * e * a * c + 27 * a * Complex.Pow(d, 2) + 2 * Complex.Pow(c, 3), (1 / 3))) - (2 * c) / (3 * a)) + 1 / 2 * Complex.Sqrt(-Complex.Pow(Complex.Sqrt(Complex.Pow(-72 * e * a * c + 27 * a * Complex.Pow(d, 2) + 2 * Complex.Pow(c, 3), 2) - 4 * Complex.Pow(12 * e * a + Complex.Pow(c, 2), 3)) - 72 * e * a * c + 27 * a * Complex.Pow(d, 2) + 2 * Complex.Pow(c, 3), (1 / 3)) / (3 * 2 ^ (1 / 3) * a) - (2 ^ (1 / 3) * (12 * e * a + Complex.Pow(c, 2))) / (3 * a * Complex.Pow(Complex.Sqrt(Complex.Pow(-72 * e * a * c + 27 * a * Complex.Pow(d, 2) + 2 * Complex.Pow(c, 3), 2) - 4 * Complex.Pow(12 * e * a + Complex.Pow(c, 2), 3)) - 72 * e * a * c + 27 * a * Complex.Pow(d, 2) + 2 * Complex.Pow(c, 3), (1 / 3))) - (2 * d) / (a * Complex.Sqrt(Complex.Pow(Complex.Sqrt(Complex.Pow(-72 * e * a * c + 27 * a * Complex.Pow(d, 2) + 2 * Complex.Pow(c, 3), 2) - 4 * Complex.Pow(12 * e * a + Complex.Pow(c, 2), 3)) - 72 * e * a * c + 27 * a * Complex.Pow(d, 2) + 2 * Complex.Pow(c, 3), (1 / 3)) / (3 * 2 ^ (1 / 3) * a) + (2 ^ (1 / 3) * (12 * e * a + Complex.Pow(c, 2))) / (3 * a * Complex.Pow(Complex.Sqrt(Complex.Pow(-72 * e * a * c + 27 * a * Complex.Pow(d, 2) + 2 * Complex.Pow(c, 3), 2) - 4 * Complex.Pow(12 * e * a + Complex.Pow(c, 2), 3)) - 72 * e * a * c + 27 * a * Complex.Pow(d, 2) + 2 * Complex.Pow(c, 3), (1 / 3))) - (2 * c) / (3 * a))) - (4 * c) / (3 * a))
n3 = -1 / 2 * Complex.Sqrt(Complex.Pow(Complex.Sqrt(Complex.Pow(-72 * e * a * c + 27 * a * Complex.Pow(d, 2) + 2 * Complex.Pow(c, 3), 2) - 4 * Complex.Pow(12 * e * a + Complex.Pow(c, 2), 3)) - 72 * e * a * c + 27 * a * Complex.Pow(d, 2) + 2 * Complex.Pow(c, 3), (1 / 3)) / (3 * 2 ^ (1 / 3) * a) + (2 ^ (1 / 3) * (12 * e * a + Complex.Pow(c, 2))) / (3 * a * Complex.Pow(Complex.Sqrt(Complex.Pow(-72 * e * a * c + 27 * a * Complex.Pow(d, 2) + 2 * Complex.Pow(c, 3), 2) - 4 * Complex.Pow(12 * e * a + Complex.Pow(c, 2), 3)) - 72 * e * a * c + 27 * a * Complex.Pow(d, 2) + 2 * Complex.Pow(c, 3), (1 / 3))) - (2 * c) / (3 * a)) - 1 / 2 * Complex.Sqrt(-Complex.Pow(Complex.Sqrt(Complex.Pow(-72 * e * a * c + 27 * a * Complex.Pow(d, 2) + 2 * Complex.Pow(c, 3), 2) - 4 * Complex.Pow(12 * e * a + Complex.Pow(c, 2), 3)) - 72 * e * a * c + 27 * a * Complex.Pow(d, 2) + 2 * Complex.Pow(c, 3), (1 / 3)) / (3 * 2 ^ (1 / 3) * a) - (2 ^ (1 / 3) * (12 * e * a + Complex.Pow(c, 2))) / (3 * a * Complex.Pow(Complex.Sqrt(Complex.Pow(-72 * e * a * c + 27 * a * Complex.Pow(d, 2) + 2 * Complex.Pow(c, 3), 2) - 4 * Complex.Pow(12 * e * a + Complex.Pow(c, 2), 3)) - 72 * e * a * c + 27 * a * Complex.Pow(d, 2) + 2 * Complex.Pow(c, 3), (1 / 3))) + (2 * d) / (a * Complex.Sqrt(Complex.Pow(Complex.Sqrt(Complex.Pow(-72 * e * a * c + 27 * a * Complex.Pow(d, 2) + 2 * Complex.Pow(c, 3), 2) - 4 * Complex.Pow(12 * e * a + Complex.Pow(c, 2), 3)) - 72 * e * a * c + 27 * a * Complex.Pow(d, 2) + 2 * Complex.Pow(c, 3), (1 / 3)) / (3 * 2 ^ (1 / 3) * a) + (2 ^ (1 / 3) * (12 * e * a + Complex.Pow(c, 2))) / (3 * a * Complex.Pow(Complex.Sqrt(Complex.Pow(-72 * e * a * c + 27 * a * Complex.Pow(d, 2) + 2 * Complex.Pow(c, 3), 2) - 4 * Complex.Pow(12 * e * a + Complex.Pow(c, 2), 3)) - 72 * e * a * c + 27 * a * Complex.Pow(d, 2) + 2 * Complex.Pow(c, 3), (1 / 3))) - (2 * c) / (3 * a))) - (4 * c) / (3 * a))
n4 = 1 / 2 * Complex.Sqrt(-Complex.Pow(Complex.Sqrt(Complex.Pow(-72 * e * a * c + 27 * a * Complex.Pow(d, 2) + 2 * Complex.Pow(c, 3), 2) - 4 * Complex.Pow(12 * e * a + Complex.Pow(c, 2), 3)) - 72 * e * a * c + 27 * a * Complex.Pow(d, 2) + 2 * Complex.Pow(c, 3), (1 / 3)) / (3 * 2 ^ (1 / 3) * a) - (2 ^ (1 / 3) * (12 * e * a + Complex.Pow(c, 2))) / (3 * a * Complex.Pow(Complex.Sqrt(Complex.Pow(-72 * e * a * c + 27 * a * Complex.Pow(d, 2) + 2 * Complex.Pow(c, 3), 2) - 4 * Complex.Pow(12 * e * a + Complex.Pow(c, 2), 3)) - 72 * e * a * c + 27 * a * Complex.Pow(d, 2) + 2 * Complex.Pow(c, 3), (1 / 3))) + (2 * d) / (a * Complex.Sqrt(Complex.Pow(Complex.Sqrt(Complex.Pow(-72 * e * a * c + 27 * a * Complex.Pow(d, 2) + 2 * Complex.Pow(c, 3), 2) - 4 * Complex.Pow(12 * e * a + Complex.Pow(c, 2), 3)) - 72 * e * a * c + 27 * a * Complex.Pow(d, 2) + 2 * Complex.Pow(c, 3), (1 / 3)) / (3 * 2 ^ (1 / 3) * a) + (2 ^ (1 / 3) * (12 * e * a + Complex.Pow(c, 2))) / (3 * a * Complex.Pow(Complex.Sqrt(Complex.Pow(-72 * e * a * c + 27 * a * Complex.Pow(d, 2) + 2 * Complex.Pow(c, 3), 2) - 4 * Complex.Pow(12 * e * a + Complex.Pow(c, 2), 3)) - 72 * e * a * c + 27 * a * Complex.Pow(d, 2) + 2 * Complex.Pow(c, 3), (1 / 3))) - (2 * c) / (3 * a))) - (4 * c) / (3 * a)) - 1 / 2 * Complex.Sqrt(Complex.Pow(Complex.Sqrt(Complex.Pow(-72 * e * a * c + 27 * a * Complex.Pow(d, 2) + 2 * Complex.Pow(c, 3), 2) - 4 * Complex.Pow(12 * e * a + Complex.Pow(c, 2), 3)) - 72 * e * a * c + 27 * a * Complex.Pow(d, 2) + 2 * Complex.Pow(c, 3), (1 / 3)) / (3 * 2 ^ (1 / 3) * a) + (2 ^ (1 / 3) * (12 * e * a + Complex.Pow(c, 2))) / (3 * a * Complex.Pow(Complex.Sqrt(Complex.Pow(-72 * e * a * c + 27 * a * Complex.Pow(d, 2) + 2 * Complex.Pow(c, 3), 2) - 4 * Complex.Pow(12 * e * a + Complex.Pow(c, 2), 3)) - 72 * e * a * c + 27 * a * Complex.Pow(d, 2) + 2 * Complex.Pow(c, 3), (1 / 3))) - (2 * c) / (3 * a))
result.Clear()
result.Add(n1)
result.Add(n2)
result.Add(n3)
result.Add(n4)
txtDescription.Text = "The original polynomial were b*x^3 = 0"
Else
x1 = -1 / 2 * Complex.Sqrt(Complex.Pow(b, 2) / (4 * Complex.Pow(a, 2)) + Complex.Pow(Complex.Sqrt(Complex.Pow(-72 * a * c * e + 27 * a * Complex.Pow(d, 2) + 27 * Complex.Pow(b, 2) * e - 9 * b * c * d + 2 * Complex.Pow(c, 3), 2) - 4 * Complex.Pow(12 * a * e - 3 * b * d + Complex.Pow(c, 2), 3)) - 72 * a * c * e + 27 * a * Complex.Pow(d, 2) + 27 * Complex.Pow(b, 2) * e - 9 * b * c * d + 2 * Complex.Pow(c, 3), (1 / 3)) / (3 * 2 ^ (1 / 3) * a) + (2 ^ (1 / 3) * (12 * a * e - 3 * b * d + Complex.Pow(c, 2))) / (3 * a * Complex.Pow(Complex.Sqrt(Complex.Pow(-72 * a * c * e + 27 * a * Complex.Pow(d, 2) + 27 * Complex.Pow(b, 2) * e - 9 * b * c * d + 2 * Complex.Pow(c, 3), 2) - 4 * Complex.Pow(12 * a * e - 3 * b * d + Complex.Pow(c, 2), 3)) - 72 * a * c * e + 27 * a * Complex.Pow(d, 2) + 27 * Complex.Pow(b, 2) * e - 9 * b * c * d + 2 * Complex.Pow(c, 3), (1 / 3))) - (2 * c) / (3 * a)) _
- 1 / 2 * Complex.Sqrt(Complex.Pow(b, 2) / (2 * Complex.Pow(a, 2)) - (-Complex.Pow(b, 3) / Complex.Pow(a, 3) + (4 * b * c) / Complex.Pow(a, 2) - (8 * d) / a) / (4 * Complex.Sqrt(Complex.Pow(b, 2) / (4 * Complex.Pow(a, 2)) + Complex.Pow(Complex.Sqrt(Complex.Pow(-72 * a * c * e + 27 * a * Complex.Pow(d, 2) + 27 * Complex.Pow(b, 2) * e - 9 * b * c * d + 2 * Complex.Pow(c, 3), 2) - 4 * Complex.Pow(12 * a * e - 3 * b * d + Complex.Pow(c, 2), 3)) - 72 * a * c * e + 27 * a * Complex.Pow(d, 2) + 27 * Complex.Pow(b, 2) * e - 9 * b * c * d + 2 * Complex.Pow(c, 3), (1 / 3)) / (3 * 2 ^ (1 / 3) * a) + (2 ^ (1 / 3) * (12 * a * e - 3 * b * d + Complex.Pow(c, 2))) / (3 * a * Complex.Pow(Complex.Sqrt(Complex.Pow(-72 * a * c * e + 27 * a * Complex.Pow(d, 2) + 27 * Complex.Pow(b, 2) * e - 9 * b * c * d + 2 * Complex.Pow(c, 3), 2) - 4 * Complex.Pow(12 * a * e - 3 * b * d + Complex.Pow(c, 2), 3)) - 72 * a * c * e + 27 * a * Complex.Pow(d, 2) + 27 * Complex.Pow(b, 2) * e - 9 * b * c * d + 2 * Complex.Pow(c, 3), (1 / 3))) - (2 * c) / (3 * a))) - Complex.Pow(Complex.Sqrt(Complex.Pow(-72 * a * c * e + 27 * a * Complex.Pow(d, 2) + 27 * Complex.Pow(b, 2) * e - 9 * b * c * d + 2 * Complex.Pow(c, 3), 2) - 4 * Complex.Pow(12 * a * e - 3 * b * d + Complex.Pow(c, 2), 3)) - 72 * a * c * e + 27 * a * Complex.Pow(d, 2) + 27 * Complex.Pow(b, 2) * e - 9 * b * c * d + 2 * Complex.Pow(c, 3), (1 / 3)) / (3 * 2 ^ (1 / 3) * a) - (2 ^ (1 / 3) * (12 * a * e - 3 * b * d + Complex.Pow(c, 2))) / (3 * a * Complex.Pow(Complex.Sqrt(Complex.Pow(-72 * a * c * e + 27 * a * Complex.Pow(d, 2) + 27 * Complex.Pow(b, 2) * e - 9 * b * c * d + 2 * Complex.Pow(c, 3), 2) - 4 * Complex.Pow(12 * a * e - 3 * b * d + Complex.Pow(c, 2), 3)) - 72 * a * c * e + 27 * a * Complex.Pow(d, 2) + 27 * Complex.Pow(b, 2) * e - 9 * b * c * d + 2 * Complex.Pow(c, 3), (1 / 3))) - (4 * c) / (3 * a)) - b / (4 * a)
x2 = -1 / 2 * Complex.Sqrt(Complex.Pow(b, 2) / (4 * Complex.Pow(a, 2)) + Complex.Pow(Complex.Sqrt(Complex.Pow(-72 * a * c * e + 27 * a * Complex.Pow(d, 2) + 27 * Complex.Pow(b, 2) * e - 9 * b * c * d + 2 * Complex.Pow(c, 3), 2) - 4 * Complex.Pow(12 * a * e - 3 * b * d + Complex.Pow(c, 2), 3)) - 72 * a * c * e + 27 * a * Complex.Pow(d, 2) + 27 * Complex.Pow(b, 2) * e - 9 * b * c * d + 2 * Complex.Pow(c, 3), (1 / 3)) / (3 * 2 ^ (1 / 3) * a) + (2 ^ (1 / 3) * (12 * a * e - 3 * b * d + Complex.Pow(c, 2))) / (3 * a * Complex.Pow(Complex.Sqrt(Complex.Pow(-72 * a * c * e + 27 * a * Complex.Pow(d, 2) + 27 * Complex.Pow(b, 2) * e - 9 * b * c * d + 2 * Complex.Pow(c, 3), 2) - 4 * Complex.Pow(12 * a * e - 3 * b * d + Complex.Pow(c, 2), 3)) - 72 * a * c * e + 27 * a * Complex.Pow(d, 2) + 27 * Complex.Pow(b, 2) * e - 9 * b * c * d + 2 * Complex.Pow(c, 3), (1 / 3))) - (2 * c) / (3 * a)) _
+ 1 / 2 * Complex.Sqrt(Complex.Pow(b, 2) / (2 * Complex.Pow(a, 2)) - (-Complex.Pow(b, 3) / Complex.Pow(a, 3) + (4 * b * c) / Complex.Pow(a, 2) - (8 * d) / a) / (4 * Complex.Sqrt(Complex.Pow(b, 2) / (4 * Complex.Pow(a, 2)) + Complex.Pow(Complex.Sqrt(Complex.Pow(-72 * a * c * e + 27 * a * Complex.Pow(d, 2) + 27 * Complex.Pow(b, 2) * e - 9 * b * c * d + 2 * Complex.Pow(c, 3), 2) - 4 * Complex.Pow(12 * a * e - 3 * b * d + Complex.Pow(c, 2), 3)) - 72 * a * c * e + 27 * a * Complex.Pow(d, 2) + 27 * Complex.Pow(b, 2) * e - 9 * b * c * d + 2 * Complex.Pow(c, 3), (1 / 3)) / (3 * 2 ^ (1 / 3) * a) + (2 ^ (1 / 3) * (12 * a * e - 3 * b * d + Complex.Pow(c, 2))) / (3 * a * Complex.Pow(Complex.Sqrt(Complex.Pow(-72 * a * c * e + 27 * a * Complex.Pow(d, 2) + 27 * Complex.Pow(b, 2) * e - 9 * b * c * d + 2 * Complex.Pow(c, 3), 2) - 4 * Complex.Pow(12 * a * e - 3 * b * d + Complex.Pow(c, 2), 3)) - 72 * a * c * e + 27 * a * Complex.Pow(d, 2) + 27 * Complex.Pow(b, 2) * e - 9 * b * c * d + 2 * Complex.Pow(c, 3), (1 / 3))) - (2 * c) / (3 * a))) - Complex.Pow(Complex.Sqrt(Complex.Pow(-72 * a * c * e + 27 * a * Complex.Pow(d, 2) + 27 * Complex.Pow(b, 2) * e - 9 * b * c * d + 2 * Complex.Pow(c, 3), 2) - 4 * Complex.Pow(12 * a * e - 3 * b * d + Complex.Pow(c, 2), 3)) - 72 * a * c * e + 27 * a * Complex.Pow(d, 2) + 27 * Complex.Pow(b, 2) * e - 9 * b * c * d + 2 * Complex.Pow(c, 3), (1 / 3)) / (3 * 2 ^ (1 / 3) * a) - (2 ^ (1 / 3) * (12 * a * e - 3 * b * d + Complex.Pow(c, 2))) / (3 * a * Complex.Pow(Complex.Sqrt(Complex.Pow(-72 * a * c * e + 27 * a * Complex.Pow(d, 2) + 27 * Complex.Pow(b, 2) * e - 9 * b * c * d + 2 * Complex.Pow(c, 3), 2) - 4 * Complex.Pow(12 * a * e - 3 * b * d + Complex.Pow(c, 2), 3)) - 72 * a * c * e + 27 * a * Complex.Pow(d, 2) + 27 * Complex.Pow(b, 2) * e - 9 * b * c * d + 2 * Complex.Pow(c, 3), (1 / 3))) - (4 * c) / (3 * a)) - b / (4 * a)
x3 = 1 / 2 * Complex.Sqrt(Complex.Pow(b, 2) / (4 * Complex.Pow(a, 2)) + Complex.Pow(Complex.Sqrt(Complex.Pow(-72 * a * c * e + 27 * a * Complex.Pow(d, 2) + 27 * Complex.Pow(b, 2) * e - 9 * b * c * d + 2 * Complex.Pow(c, 3), 2) - 4 * Complex.Pow(12 * a * e - 3 * b * d + Complex.Pow(c, 2), 3)) - 72 * a * c * e + 27 * a * Complex.Pow(d, 2) + 27 * Complex.Pow(b, 2) * e - 9 * b * c * d + 2 * Complex.Pow(c, 3), (1 / 3)) / (3 * 2 ^ (1 / 3) * a) + (2 ^ (1 / 3) * (12 * a * e - 3 * b * d + Complex.Pow(c, 2))) / (3 * a * Complex.Pow(Complex.Sqrt(Complex.Pow(-72 * a * c * e + 27 * a * Complex.Pow(d, 2) + 27 * Complex.Pow(b, 2) * e - 9 * b * c * d + 2 * Complex.Pow(c, 3), 2) - 4 * Complex.Pow(12 * a * e - 3 * b * d + Complex.Pow(c, 2), 3)) - 72 * a * c * e + 27 * a * Complex.Pow(d, 2) + 27 * Complex.Pow(b, 2) * e - 9 * b * c * d + 2 * Complex.Pow(c, 3), (1 / 3))) - (2 * c) / (3 * a)) _
- 1 / 2 * Complex.Sqrt(Complex.Pow(b, 2) / (2 * Complex.Pow(a, 2)) - (-Complex.Pow(b, 3) / Complex.Pow(a, 3) + (4 * b * c) / Complex.Pow(a, 2) - (8 * d) / a) / (4 * Complex.Sqrt(Complex.Pow(b, 2) / (4 * Complex.Pow(a, 2)) + Complex.Pow(Complex.Sqrt(Complex.Pow(-72 * a * c * e + 27 * a * Complex.Pow(d, 2) + 27 * Complex.Pow(b, 2) * e - 9 * b * c * d + 2 * Complex.Pow(c, 3), 2) - 4 * Complex.Pow(12 * a * e - 3 * b * d + Complex.Pow(c, 2), 3)) - 72 * a * c * e + 27 * a * Complex.Pow(d, 2) + 27 * Complex.Pow(b, 2) * e - 9 * b * c * d + 2 * Complex.Pow(c, 3), (1 / 3)) / (3 * 2 ^ (1 / 3) * a) + (2 ^ (1 / 3) * (12 * a * e - 3 * b * d + Complex.Pow(c, 2))) / (3 * a * Complex.Pow(Complex.Sqrt(Complex.Pow(-72 * a * c * e + 27 * a * Complex.Pow(d, 2) + 27 * Complex.Pow(b, 2) * e - 9 * b * c * d + 2 * Complex.Pow(c, 3), 2) - 4 * Complex.Pow(12 * a * e - 3 * b * d + Complex.Pow(c, 2), 3)) - 72 * a * c * e + 27 * a * Complex.Pow(d, 2) + 27 * Complex.Pow(b, 2) * e - 9 * b * c * d + 2 * Complex.Pow(c, 3), (1 / 3))) - (2 * c) / (3 * a))) - Complex.Pow(Complex.Sqrt(Complex.Pow(-72 * a * c * e + 27 * a * Complex.Pow(d, 2) + 27 * Complex.Pow(b, 2) * e - 9 * b * c * d + 2 * Complex.Pow(c, 3), 2) - 4 * Complex.Pow(12 * a * e - 3 * b * d + Complex.Pow(c, 2), 3)) - 72 * a * c * e + 27 * a * Complex.Pow(d, 2) + 27 * Complex.Pow(b, 2) * e - 9 * b * c * d + 2 * Complex.Pow(c, 3), (1 / 3)) / (3 * 2 ^ (1 / 3) * a) - (2 ^ (1 / 3) * (12 * a * e - 3 * b * d + Complex.Pow(c, 2))) / (3 * a * Complex.Pow(Complex.Sqrt(Complex.Pow(-72 * a * c * e + 27 * a * Complex.Pow(d, 2) + 27 * Complex.Pow(b, 2) * e - 9 * b * c * d + 2 * Complex.Pow(c, 3), 2) - 4 * Complex.Pow(12 * a * e - 3 * b * d + Complex.Pow(c, 2), 3)) - 72 * a * c * e + 27 * a * Complex.Pow(d, 2) + 27 * Complex.Pow(b, 2) * e - 9 * b * c * d + 2 * Complex.Pow(c, 3), (1 / 3))) - (4 * c) / (3 * a)) - b / (4 * a)
x4 = 1 / 2 * Complex.Sqrt(Complex.Pow(b, 2) / (4 * Complex.Pow(a, 2)) + Complex.Pow(Complex.Sqrt(Complex.Pow(-72 * a * c * e + 27 * a * Complex.Pow(d, 2) + 27 * Complex.Pow(b, 2) * e - 9 * b * c * d + 2 * Complex.Pow(c, 3), 2) - 4 * Complex.Pow(12 * a * e - 3 * b * d + Complex.Pow(c, 2), 3)) - 72 * a * c * e + 27 * a * Complex.Pow(d, 2) + 27 * Complex.Pow(b, 2) * e - 9 * b * c * d + 2 * Complex.Pow(c, 3), (1 / 3)) / (3 * 2 ^ (1 / 3) * a) + (2 ^ (1 / 3) * (12 * a * e - 3 * b * d + Complex.Pow(c, 2))) / (3 * a * Complex.Pow(Complex.Sqrt(Complex.Pow(-72 * a * c * e + 27 * a * Complex.Pow(d, 2) + 27 * Complex.Pow(b, 2) * e - 9 * b * c * d + 2 * Complex.Pow(c, 3), 2) - 4 * Complex.Pow(12 * a * e - 3 * b * d + Complex.Pow(c, 2), 3)) - 72 * a * c * e + 27 * a * Complex.Pow(d, 2) + 27 * Complex.Pow(b, 2) * e - 9 * b * c * d + 2 * Complex.Pow(c, 3), (1 / 3))) - (2 * c) / (3 * a)) _
+ 1 / 2 * Complex.Sqrt(Complex.Pow(b, 2) / (2 * Complex.Pow(a, 2)) - (-Complex.Pow(b, 3) / Complex.Pow(a, 3) + (4 * b * c) / Complex.Pow(a, 2) - (8 * d) / a) / (4 * Complex.Sqrt(Complex.Pow(b, 2) / (4 * Complex.Pow(a, 2)) + Complex.Pow(Complex.Sqrt(Complex.Pow(-72 * a * c * e + 27 * a * Complex.Pow(d, 2) + 27 * Complex.Pow(b, 2) * e - 9 * b * c * d + 2 * Complex.Pow(c, 3), 2) - 4 * Complex.Pow(12 * a * e - 3 * b * d + Complex.Pow(c, 2), 3)) - 72 * a * c * e + 27 * a * Complex.Pow(d, 2) + 27 * Complex.Pow(b, 2) * e - 9 * b * c * d + 2 * Complex.Pow(c, 3), (1 / 3)) / (3 * 2 ^ (1 / 3) * a) + (2 ^ (1 / 3) * (12 * a * e - 3 * b * d + Complex.Pow(c, 2))) / (3 * a * Complex.Pow(Complex.Sqrt(Complex.Pow(-72 * a * c * e + 27 * a * Complex.Pow(d, 2) + 27 * Complex.Pow(b, 2) * e - 9 * b * c * d + 2 * Complex.Pow(c, 3), 2) - 4 * Complex.Pow(12 * a * e - 3 * b * d + Complex.Pow(c, 2), 3)) - 72 * a * c * e + 27 * a * Complex.Pow(d, 2) + 27 * Complex.Pow(b, 2) * e - 9 * b * c * d + 2 * Complex.Pow(c, 3), (1 / 3))) - (2 * c) / (3 * a))) - Complex.Pow(Complex.Sqrt(Complex.Pow(-72 * a * c * e + 27 * a * Complex.Pow(d, 2) + 27 * Complex.Pow(b, 2) * e - 9 * b * c * d + 2 * Complex.Pow(c, 3), 2) - 4 * Complex.Pow(12 * a * e - 3 * b * d + Complex.Pow(c, 2), 3)) - 72 * a * c * e + 27 * a * Complex.Pow(d, 2) + 27 * Complex.Pow(b, 2) * e - 9 * b * c * d + 2 * Complex.Pow(c, 3), (1 / 3)) / (3 * 2 ^ (1 / 3) * a) - (2 ^ (1 / 3) * (12 * a * e - 3 * b * d + Complex.Pow(c, 2))) / (3 * a * Complex.Pow(Complex.Sqrt(Complex.Pow(-72 * a * c * e + 27 * a * Complex.Pow(d, 2) + 27 * Complex.Pow(b, 2) * e - 9 * b * c * d + 2 * Complex.Pow(c, 3), 2) - 4 * Complex.Pow(12 * a * e - 3 * b * d + Complex.Pow(c, 2), 3)) - 72 * a * c * e + 27 * a * Complex.Pow(d, 2) + 27 * Complex.Pow(b, 2) * e - 9 * b * c * d + 2 * Complex.Pow(c, 3), (1 / 3))) - (4 * c) / (3 * a)) - b / (4 * a)
result.Add(x1)
result.Add(x2)
result.Add(x3)
result.Add(x4)
Dim a0, a1, a2, correction As New Complex
a2 = -3 * b * b / (8 * a * a) + c / a
a1 = b * b * b / (8 * a * a * a) - b * c / (2 * a * a) + d / a
a0 = -3 * b * b * b * b / (256 * a * a * a * a) + c * b * b / (16 * a * a * a) - b * d / (4 * a * a) + e / a
correction = b / (4 * a)
If (a2 * a2 + 12 * a0).Real > 0 And (-2 * a2).Real < Complex.Sqrt(a2 * a2 + 12 * a0).Real And (2 * Complex.Pow(a2 * a2 + 12 * a0, 3 / 2)).Real = (2 * a2 * a2 * a2 - 72 * a2 * a0 + 27 * a1 * a1).Real Then
txtDescription.Text = "The original polynomial has two complex roots and one double real root"
For Each p As Complex In result
Dim x_real, x_Imag As Double
x_real = Math.Round(p.Real, 5)
x_Imag = Math.Round(p.Imaginary, 5)
If x_real <> 0 Then
res2.Add(New Complex(x_real, 0))
Else
res2.Add(New Complex(0, x_Imag))
End If
Next
result = res2
ElseIf a1.Real = 0 And (a2 * a2 - 4 * a0).Real = 0 And a2.Real > 0 Then
txtDescription.Text = "The original polynomial is (x^2+b^2)^2 where b is different from 0"
For Each p As Complex In result
Dim x_real, x_Imag As Double
x_real = Math.Round(p.Real, 5)
x_Imag = Math.Round(p.Imaginary, 5)
res2.Add(New Complex(x_real, x_Imag))
Next
result = res2
ElseIf a2.Real < 0 And (a2 * a2 - a * a0).Real > 0 And (a2 * a2 + 12 * a0).Real > 0 And (2 * Complex.Pow(a2 * a2 + 12 * a0, 3 / 2)).Real = (2 * a2 * a2 * a2 - 72 * a2 * a0 + 27 * a1 * a1).Real Then
txtDescription.Text = "The original polynomial has three different real roots, but among them is only one double root and the other two single rootes are on the same side of the double one"
For Each p As Complex In result
Dim x_real As Double
x_real = Math.Round(p.Real, 5)
res2.Add(New Complex(x_real, 0))
Next
result = res2
ElseIf a2.Real < 0 And (a2 * a2 - a * a0).Real > 0 And (a2 * a2 + 12 * a0).Real > 0 And (2 * Complex.Pow(a2 * a2 + 12 * a0, 3 / 2)).Real = (-2 * a2 * a2 * a2 + 72 * a2 * a0 - 27 * a1 * a1).Real Then
txtDescription.Text = "The original polynomial has three different real roots, but among them is only one double root and the other two single roots are on the opposite sides of the double one"
Dim P, Q, R, U, y, W As New Complex
P = -Complex.Pow(a2, 2) / 12 - a0
Q = -Complex.Pow(a2, 3) / 180 + a2 * a0 / 3 - Complex.Pow(a1, 2) / 8
R = Q / 2 + Complex.Sqrt(Complex.Pow(Q, 2) / 4 + Complex.Pow(P, 3) / 27)
U = Complex.Pow(R, 1 / 3)
If U.Real <> 0 Then
y = -5 / 6 * a2 + U - P / (3 * U)
Else
y = -5 / 6 * a2 + U - Complex.Pow(Q, 1 / 3)
End If
W = Complex.Sqrt(a2 + 2 * y)
result.Clear()
result.Add(-correction + (W + Complex.Sqrt(-(3 * a2 + 2 * y + 2 * a1 / W))) / 2)
result.Add(-correction + (W - Complex.Sqrt(-(3 * a2 + 2 * y + 2 * a1 / W))) / 2)
result.Add(-correction + (-W + Complex.Sqrt(-(3 * a2 + 2 * y - 2 * a1 / W))) / 2)
result.Add(-correction + (-W - Complex.Sqrt(-(3 * a2 + 2 * y - 2 * a1 / W))) / 2)
For Each pr As Complex In result
Dim x_real, x_Imag As Double
x_real = Math.Round(pr.Real, 5)
x_Imag = Math.Round(pr.Imaginary, 5)
res2.Add(New Complex(x_real, x_Imag))
Next
result = res2
ElseIf a1.Real = 0 And (a2 * a2 - 4 * a0).Real = 0 And a2.Real < 0 Then
txtDescription.Text = "The original polynomial has two double real roots"
For Each p As Complex In result
Dim x_real As Double
x_real = Math.Round(p.Real, 5)
res2.Add(New Complex(x_real, 0))
Next
result = res2
ElseIf (a2 * a2 + 12 * a0).Real = 0 And (8 * a2 * a2 * a2 + 27 * a1 * a1).Real = 0 And a2.Real < 0 Then
txtDescription.Text = "The original polynomial has two different real roots and one of them is a triple root"
For Each p As Complex In result
Dim x_real As Double
x_real = Math.Round(p.Real, 5)
res2.Add(New Complex(x_real, 0))
Next
result = res2
ElseIf a0.Real = 0 And a1.Real = 0 And a2.Real = 0 Then
txtDescription.Text = "The original polynomial has only one fourfold real root which is zero"
For Each p As Complex In result
Dim x_real As Double
x_real = Math.Round(p.Real, 5)
res2.Add(New Complex(x_real, 0))
Next
result = res2
ElseIf a1.Real = 0 Then
txtDescription.Text = "The polynomial can be written as a biquadratic equation, and is solved that way."
result.Clear()
result.Add(-correction + Complex.Sqrt((-a2 + Complex.Sqrt(Complex.Pow(a2, 2) - 4 * a0)) / 2))
result.Add(-correction + Complex.Sqrt((-a2 - Complex.Sqrt(Complex.Pow(a2, 2) - 4 * a0)) / 2))
result.Add(-correction - Complex.Sqrt((-a2 + Complex.Sqrt(Complex.Pow(a2, 2) - 4 * a0)) / 2))
result.Add(-correction - Complex.Sqrt((-a2 - Complex.Sqrt(Complex.Pow(a2, 2) - 4 * a0)) / 2))
ElseIf a0.Real = 0 Then
txtDescription.Text = "Its a depressed cubic equation"
result.Clear()
result = PolynominalEquationSolver(0, 0, 1, a2, a1)
result.Add(New Complex(0, 0))
Else
txtDescription.Text = "Description not availiable, calculated by Ferrari's original method"
Dim P, Q, R, U, y, W As New Complex
P = -Complex.Pow(a2, 2) / 12 - a0
Q = -Complex.Pow(a2, 3) / 180 + a2 * a0 / 3 - Complex.Pow(a1, 2) / 8
R = -Q / 2 - Complex.Sqrt(Complex.Pow(Q, 2) / 4 + Complex.Pow(P, 3) / 27)
U = Complex.Pow(R, 1 / 3)
If U.Real <> 0 Then
y = -5 / 6 * a2 + U - P / (3 * U)
Else
y = -5 / 6 * a2 + U - Complex.Pow(Q, 1 / 3)
End If
W = Complex.Sqrt(a2 + 2 * y)
result.Clear()
result.Add(-correction + (W + Complex.Sqrt(-(3 * a2 + 2 * y + 2 * a1 / W))) / 2)
result.Add(-correction + (W - Complex.Sqrt(-(3 * a2 + 2 * y + 2 * a1 / W))) / 2)
result.Add(-correction + (-W + Complex.Sqrt(-(3 * a2 + 2 * y - 2 * a1 / W))) / 2)
result.Add(-correction + (-W - Complex.Sqrt(-(3 * a2 + 2 * y - 2 * a1 / W))) / 2)
For Each pr As Complex In result
Dim x_real, x_Imag As Double
x_real = Math.Round(pr.Real, 5)
x_Imag = Math.Round(pr.Imaginary, 5)
res2.Add(New Complex(x_real, x_Imag))
Next
result = res2
End If
End If
ElseIf a = 0 And b <> 0 Then
If c.Real = 0 And d.Real = 0 Then
result.Add(-Complex.Pow(e, (1 / 3)) / Complex.Pow(b, (1 / 3)))
result.Add((Complex.Pow(-1, 1 / 3) * Complex.Pow(e, 1 / 3)) / Complex.Pow(b, (1 / 3)))
result.Add(-(Complex.Pow(-1, (2 / 3)) * Complex.Pow(e, (1 / 3))) / Complex.Pow(b, (1 / 3)))
Else
x1 = Complex.Pow(Complex.Sqrt(Complex.Pow(-27 * Complex.Pow(b, 2) * e + 9 * b * c * d - 2 * Complex.Pow(c, 3), 2) + 4 * Complex.Pow(3 * b * d - Complex.Pow(c, 2), 3)) - 27 * Complex.Pow(b, 2) * e + 9 * b * c * d - 2 * Complex.Pow(c, 3), (1 / 3)) / (3 * 2 ^ (1 / 3) * b) - (2 ^ (1 / 3) * (3 * b * d - Complex.Pow(c, 2))) / (3 * b * Complex.Pow(Complex.Sqrt(Complex.Pow(-27 * Complex.Pow(b, 2) * e + 9 * b * c * d - 2 * Complex.Pow(c, 3), 2) + 4 * Complex.Pow(3 * b * d - Complex.Pow(c, 2), 3)) - 27 * Complex.Pow(b, 2) * e + 9 * b * c * d - 2 * Complex.Pow(c, 3), (1 / 3))) - c / (3 * b)
result.Add(x1)
result.Add(-((1 - New Complex(0, 1) * Complex.Sqrt(3)) * Complex.Pow(Complex.Sqrt(Complex.Pow(-27 * Complex.Pow(b, 2) * e + 9 * b * c * d - 2 * Complex.Pow(c, 3), 2) + 4 * Complex.Pow(3 * b * d - Complex.Pow(c, 2), 3)) - 27 * Complex.Pow(b, 2) * e + 9 * b * c * d - 2 * Complex.Pow(c, 3), (1 / 3))) / (6 * 2 ^ (1 / 3) * b) + ((1 + New Complex(0, 1) * Complex.Sqrt(3)) * (3 * b * d - Complex.Pow(c, 2))) / (3 * 2 ^ (2 / 3) * b * Complex.Pow(Complex.Sqrt(Complex.Pow(-27 * Complex.Pow(b, 2) * e + 9 * b * c * d - 2 * Complex.Pow(c, 3), 2) + 4 * Complex.Pow(3 * b * d - Complex.Pow(c, 2), 3)) - 27 * Complex.Pow(b, 2) * e + 9 * b * c * d - 2 * Complex.Pow(c, 3), (1 / 3))) - c / (3 * b))
result.Add(-((1 + New Complex(0, 1) * Complex.Sqrt(3)) * Complex.Pow(Complex.Sqrt(Complex.Pow(-27 * Complex.Pow(b, 2) * e + 9 * b * c * d - 2 * Complex.Pow(c, 3), 2) + 4 * Complex.Pow(3 * b * d - Complex.Pow(c, 2), 3)) - 27 * Complex.Pow(b, 2) * e + 9 * b * c * d - 2 * Complex.Pow(c, 3), (1 / 3))) / (6 * 2 ^ (1 / 3) * b) + ((1 - New Complex(0, 1) * Complex.Sqrt(3)) * (3 * b * d - Complex.Pow(c, 2))) / (3 * 2 ^ (2 / 3) * b * Complex.Pow(Complex.Sqrt(Complex.Pow(-27 * Complex.Pow(b, 2) * e + 9 * b * c * d - 2 * Complex.Pow(c, 3), 2) + 4 * Complex.Pow(3 * b * d - Complex.Pow(c, 2), 3)) - 27 * Complex.Pow(b, 2) * e + 9 * b * c * d - 2 * Complex.Pow(c, 3), (1 / 3))) - c / (3 * b))
End If
ElseIf a = 0 And b = 0 And c <> 0 Then
result.Add((-Complex.Sqrt(Complex.Pow(d, 2) - 4 * c * e) - d) / (2 * c))
result.Add((Complex.Sqrt(Complex.Pow(d, 2) - 4 * c * e) - d) / (2 * c))
ElseIf a = 0 And b = 0 And c = 0 And d <> 0 Then
result.Add(-e / d)
Else
result.Add(New Complex(0, 0))
End If
Dim res As New List(Of Complex)
For Each p As Complex In result
res.Add(New Complex(Math.Round(p.Real, 5), Math.Round(p.Imaginary, 5)))
Next
Return res
End Function
Private Sub btnClear_Click(sender As System.Object, e As System.Windows.RoutedEventArgs) Handles btnClear.Click
Dim s As New List(Of Complex)
s = Jenkins_Traub_RootFindingAlgorithm(txtA.Text, txtA.Text, txtC.Text, txtD.Text, txtE.Text)
txtDescription.Text = s.ToString
txtA.Text = ""
txtB.Text = ""
txtC.Text = ""
txtD.Text = ""
txtE.Text = ""
txtA.Focus()
End Sub
It should be more stable, the trouble with the formulas are that they often suffer from rounding off errors that can make the polynomial error too large to make any sence. If you want a more stable approch you could use the http://en.wikipedia.org/wiki/Jenkins%E2%80%93Traub_algorithm[^]
|