1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169
|
Imports System.Text
Public Class frmNewton
'------degre fonction--------------------------------------
Private degre As Integer
Private precision As Double = Math.Pow(10, -14.0)
Private maxIter As Integer = 20
Private nr As RaphsonNewton
Private initialX As Double
Private coeffs As New List(Of Double)
Private EstValide As Boolean
'------- stringbuilder ----------
'-------- collecte tous les resultats string pour affichage
' ------- sur le txBoxResultat ---------
Private sbGlobal As StringBuilder = Nothing
Public Sub New()
' Cet appel est requis par le concepteur.
InitializeComponent()
' Ajoutez une initialisation quelconque après l'appel InitializeComponent().
HideDegre()
HideCoeffs()
End Sub
'------------affiche saisie du degre equation ---------------------
Private Sub btnAfficherDegre_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAfficherDegre.Click
VisibleDegre()
' ------------ desactive l'execution ------------------------
btnExecute.Enabled = False
btnExecute.BackColor = Color.Beige
End Sub
'------------affiche controles de saisie coeffients -------------
Private Sub txtDegre_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtDegre.TextChanged
HideCoeffs()
degre = 0
If Integer.TryParse(txtDegre.Text, degre) Then 'verifie saisie user
If degre < 2 Then
MessageBox.Show("degre doit etre >=2...")
Return
End If
If degre > GrpCoeffs.Controls.Count Then
MessageBox.Show("degre trop grand...")
Return
End If
VisibleCoeffs(degre)
Else
MessageBox.Show("entrer un nbre svp")
End If
End Sub
Private Sub btnValider_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnValider.Click
coeffs.Clear()
Dim temp As Double = 0.0
Dim ctrl As Control = Nothing
For i As Integer = 0 To GrpCoeffs.Controls.Count - 1
temp = 0.0
ctrl = GrpCoeffs.Controls(i)
If Double.TryParse(ctrl.Text, temp) Then 'verifie saisie user
If ctrl.Visible Then coeffs.Add(temp)
Else
MessageBox.Show("Saisir un nbr svp...!!! position : " + ctrl.Name.ToString())
End If
Next
AfficherFonction()
AfficherDerivee()
EstValide = True
End Sub
Private Sub btnEvaluateFNDFN_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnEvaluateFNDFN.Click
If Not EstValide Then Return
initialX = 0.0
If Not Double.TryParse(txtInitialX.Text, initialX) Then
MessageBox.Show("Saisir valeur initiale X0 svp...!!!")
btnExecute.Enabled = False
End If
If Not Integer.TryParse(txtMaxIter.Text, maxIter) Then
MessageBox.Show("Saisir nbre d'iterations N svp...!!!")
Return
End If
'Init les coefficients dans prop shared du class RaphsonNewton
RaphsonNewton.listCoeffs = coeffs
'Evalue FX et fdx et collecte resultats
sbGlobal = New StringBuilder
sbGlobal.AppendLine("FX Value : " + RaphsonNewton.UtilFX(initialX).ToString)
sbGlobal.AppendLine("FDX Value : " + RaphsonNewton.UtilFDX(initialX).ToString)
'Update txtResultat
txtResultat.Clear()
txtResultat.Text = sbGlobal.ToString
'Enable btnExecute
btnExecute.Enabled = True
btnExecute.BackColor = Color.Red
End Sub
Private Sub btnExecute_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExecute.Click
Dim racine As Double = RaphsonNewton.Solve(initialX, maxIter)
' collecte resultats
sbGlobal.AppendLine("Racine :" + racine.ToString)
sbGlobal.AppendLine("************************************")
sbGlobal.AppendLine(RaphsonNewton.sb.ToString)
'Update txtResultat
txtResultat.Clear()
txtResultat.Text = sbGlobal.ToString
'Disable btnExecute
btnExecute.Enabled = False
btnExecute.BackColor = Color.Beige
End Sub
' expression "textuelle" du polynome FX
Private Sub AfficherFonction()
Dim ch As String
ch = ""
'Dim n As Integer = degre
For n As Integer = degre To 1 Step -1
ch = ch & coeffs(n).ToString() & "*x^" & (n).ToString() & "+"
Next
lblAfficheFNX.Text = ch & coeffs(0).ToString()
End Sub
' expression "textuelle" du polynome derive FDX
Private Sub AfficherDerivee()
Dim dh As String
dh = ""
'Dim m As Integer = degre
For n As Integer = degre To 1 Step -1
dh = dh & (n * coeffs(n)).ToString() & "*x^" & (n - 1).ToString() & "+"
Next
lblAfficheFNXDER.Text = dh.Substring(0, dh.Length - 1)
End Sub
'-----------------fonctions utilitaires ou helpers-----------------
Private Sub HideDegre()
lblDegre.Visible = False
txtDegre.Visible = False
End Sub
Private Sub HideCoeffs()
For Each ctrl As Control In GrpCoeffs.Controls
ctrl.Visible = False
Next
End Sub
Private Sub VisibleDegre()
lblDegre.Visible = True
txtDegre.Visible = True
End Sub
Private Sub VisibleCoeffs(ByVal n As Integer)
For i As Integer = 0 To n
GrpCoeffs.Controls(i).Visible = True
Next
End Sub
End Class |
Partager