22/04/11 14:42
ciaosimo
Sto realizzando un programma in VB.NET con OOP per calcolare le radici di un'equazione del tipo ax^3+bx^2+cx+d=0.
Posso avere tre casi:
- 1 intersezione con l'asse x
- 2 intersezioni con l'asse x
- 3 intersezioni con l'asse x
a parte questo, il programma funziona, però se qualcuno mi volesse DARE QUALCHE SUGGERIMENTO PER MIGLIORARLO, BEN VENGA! grazie
Posso avere tre casi:
- 1 intersezione con l'asse x
- 2 intersezioni con l'asse x
- 3 intersezioni con l'asse x
a parte questo, il programma funziona, però se qualcuno mi volesse DARE QUALCHE SUGGERIMENTO PER MIGLIORARLO, BEN VENGA! grazie
Public Class FrmBisezione Private Sub CmdCalcola_click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CmdCalcola.Click LblX1.Text = "" LblX2.Text = "" LblX3.Text = "" Dim ObjBisezione As ClsBisezione ObjBisezione = New ClsBisezione If TxtA.Text <> "" And TxtB.Text <> "" And TxtC.Text <> "" And TxtD.Text <> "" Then ObjBisezione.A = Convert.ToSingle(TxtA.Text) ObjBisezione.B = Convert.ToSingle(TxtB.Text) ObjBisezione.C = Convert.ToSingle(TxtC.Text) ObjBisezione.D = Convert.ToSingle(TxtD.Text) Else MsgBox("Mancano dei dati!") End If LblX1.Text = ObjBisezione.Calcola(-1, 1) LblX2.Text = ObjBisezione.Calcola(Int(Convert.ToSingle(Rnd() * -15)), -1) LblX3.Text = ObjBisezione.Calcola(1, Int((Convert.ToSingle(Rnd() * 15)))) End Sub End Class
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 Err.Raise(13) 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 Err.Raise(13) 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 Err.Raise(13) 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 Err.Raise(13) 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
Ultima modifica effettuata da ciaosimo 22/04/11 18:19
aaa