Iteration

Iteration - VB/VBA/VBS - Programmation

Marsh Posté le 08-12-2006 à 23:14:25    

Bonjour,
 
Alors voilà j'ai fait un calcul itératif pour pouvoir résoudre un système de trois équations à trois inconnues.
 
A terme il me faut 10*10
 
Et ça ne marche pas les chiffres partent vers + ou - infini
 
Merci de votre aide
 
le code :
 
Private Sub CommandButton1_Click()
 
Dim i As Integer
Dim j As Integer
Dim a(10, 10) As Double ' matrice d'entrée 1 Equation
dim b(10) as double 'matrice d'entrée 2 Egualité
Dim p(10) As Double 'matrice de solution
Dim p1 As Double
Dim p2 As Double
Dim p3 As Double
 
b(1)=1
b(2)=2
b(3)=3
 
compteur=0
For i = 1 To 3
    For j = 1 To 3
        a(i, j) = Cells(i + 1, j + 1).Value
    Next j
Next i
p1 = 10
p2 = 10
p3 = 10
p(1) = 0 'inconnue 1
p(2) = 0 'inconnue 2
p(3) = 0 ''inconnue 3
 
        While (Abs(p(1) - p1)) > (10 ^ -2) Or (Abs(p(2) - p2)) > 10 ^ -2 Or (Abs(p(3) - p3)) > 10 ^ -2
            p1 = p(1)
            p2 = p(2)
            p3 = p(3)
            p(1) = (b(1) - p(2) * a(1, 2) - p(3) * a(1, 3)) / a(1, 1)
            p(2) = (b(2) - p(3) * a(2, 3) - p(1) * a(2, 1)) / a(2, 2)
            p(3) = (b(3) - p(2) * a(3, 2) - p(1) * a(3, 1)) / a(3, 3)
            compteur = compteur + 1
            DoEvents
        Wend
 
'Affichage des trois inconnues
For i = 1 To 3
    Cells(i + 1, 16).Value = p(i)
Next i
End Sub


Message édité par totem le 08-12-2006 à 23:17:55
Reply

Marsh Posté le 08-12-2006 à 23:14:25   

Reply

Sujets relatifs:

Leave a Replay

Make sure you enter the(*)required information where indicate.HTML code is not allowed