- Public Function Rac3(ByVal P3 As Double) As Double
- Rac3 = Math.Pow(Math.Abs(P3), 1 / 3) * Math.Sign(P3)
- End Function
-
- Public Function RacineDegré3(ByVal a, ByVal b, ByVal c, ByVal d) As Collection
- 'Resolution d'une équation du troisieme degre
- 'a x^3 + b x^2 + c x + d = 0
- Dim q, Dtrm As Double
- Dim y, p, Cosinus, alpha As Double
-
- RacineDegré3 = New Collection
- y = -b / (3 * a)
-
- p = c / a - b ^ 2 / (3 * a ^ 2)
- q = b ^ 3 / (a ^ 3 * 13.5) + (d / a) - b * c / (3 * a ^ 2)
- Dtrm = (q ^ 2 / 4) + (p ^ 3 / 27)
-
- If Math.Abs(p) < 0.0000000001 Then p = 0
- If Math.Abs(Dtrm) < 0.0000000001 Then Dtrm = 0
-
- If (Dtrm < 0) Then ' Trois racines
- If (p <> 0) Then Cosinus = (-q / 2) / Math.Sqrt(-p ^ 3 / 27)
- If (Math.Abs(Cosinus) > 1) Then Cosinus = Math.Sign(Cosinus)
- For k As Short = 0 To 2
- RacineDegré3.Add(2 * Math.Sqrt(-p / 3) * Math.Cos((Math.Acos(Cosinus) + 2 * k * Math.Pi) / 3) + y)
- Next k
- ElseIf Dtrm = 0 Then ' Deux racines
- RacineDegré3.Add((-3 * q) / (2 * p) + y)
- RacineDegré3.Add(3 * q / p + y)
- Else ' une racine
- RacineDegré3.Add(Rac3(-q / 2 + Math.Sqrt(Dtrm)) + Rac3(-q / 2 - Math.Sqrt(Dtrm)) + y)
- End If
- End Function
Public Function Rac3(ByVal P3 As Double) As Double
Rac3 = Math.Pow(Math.Abs(P3), 1 / 3) * Math.Sign(P3)
End Function
Public Function RacineDegré3(ByVal a, ByVal b, ByVal c, ByVal d) As Collection
'Resolution d'une équation du troisieme degre
'a x^3 + b x^2 + c x + d = 0
Dim q, Dtrm As Double
Dim y, p, Cosinus, alpha As Double
RacineDegré3 = New Collection
y = -b / (3 * a)
p = c / a - b ^ 2 / (3 * a ^ 2)
q = b ^ 3 / (a ^ 3 * 13.5) + (d / a) - b * c / (3 * a ^ 2)
Dtrm = (q ^ 2 / 4) + (p ^ 3 / 27)
If Math.Abs(p) < 0.0000000001 Then p = 0
If Math.Abs(Dtrm) < 0.0000000001 Then Dtrm = 0
If (Dtrm < 0) Then ' Trois racines
If (p <> 0) Then Cosinus = (-q / 2) / Math.Sqrt(-p ^ 3 / 27)
If (Math.Abs(Cosinus) > 1) Then Cosinus = Math.Sign(Cosinus)
For k As Short = 0 To 2
RacineDegré3.Add(2 * Math.Sqrt(-p / 3) * Math.Cos((Math.Acos(Cosinus) + 2 * k * Math.Pi) / 3) + y)
Next k
ElseIf Dtrm = 0 Then ' Deux racines
RacineDegré3.Add((-3 * q) / (2 * p) + y)
RacineDegré3.Add(3 * q / p + y)
Else ' une racine
RacineDegré3.Add(Rac3(-q / 2 + Math.Sqrt(Dtrm)) + Rac3(-q / 2 - Math.Sqrt(Dtrm)) + y)
End If
End Function