Public Class ClsBisezione
Private mA, mB, mC, mD, Xm, l, m, Fl, Fm, FXm As Single
Public Sub New()
mA = mB = mC = mD = 1
End Sub
Public Property A() As Single
Get
Return mA
End Get
Set(ByVal Dato As Single)
If Dato <> 0 Or Dato = 0 Then
mA = Dato
Else
End If
End Set
End Property
Public Property B() As Single
Get
Return mB
End Get
Set(ByVal Dato As Single)
If Dato <> 0 Or Dato = 0 Then
mB = Dato
Else
End If
End Set
End Property
Public Property C() As Single
Get
Return mC
End Get
Set(ByVal Dato As Single)
If Dato <> 0 Or Dato = 0 Then
mC = Dato
Else
End If
End Set
End Property
Public Property D() As Single
Get
Return mD
End Get
Set(ByVal Dato As Single)
If Dato <> 0 Or Dato = 0 Then
mD = Dato
Else
End If
End Set
End Property
Public Function Calcola(ByRef l As Single, ByRef m As Single) As String
Dim n As Byte = 50
Do
Fl = A * (l ^ 3) + B * (l ^ 2) + C * l + D
Fm = A * (m ^ 3) + B * (m ^ 2) + C * m + D
If Fl * Fm < 0 Then
n = 50
'MsgBox("I [" & Int(l) & ";" & Int(m) & "]")
Exit Do
Else
n -= 1
If n = 0 Then
Return "..."
Exit Do
End If
End If
Loop
For i = 0 To 300
Xm = (l + m) / 2
FXm = A * (Xm ^ 3) + B * (Xm ^ 2) + C * Xm + D
If FXm = 0 Then
Exit For
Else
If FXm > 0 Then
m = Xm
Else
l = Xm
End If
End If
Next
Return Convert.ToString(Math.Round(Xm, 2))
End Function
End Class