VBA-E Mutiplication matricielle
Bonjour,
J'ai écrit un petit programme qui génère 2 matrices aléatoires et leurs produits.
Pour les matrices aléatoires ça marche mais pour le produit ça marche pas.
Probablement à cause de la formule de la multiplication.
Voici mon code:
Code:
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
| Dim N, M As Integer
N = Range("C3").Value
M = Range("C4").Value
Range("C3").NumberFormat = "0"
Range("C4").NumberFormat = "0"
Range("A8").Select
'Matrice A
Dim I As Integer
For I = 0 To CInt(Range("C3").Value)
For J = 0 To CInt(Range("C4").Value)
ActiveCell.Offset(I, J).Value = Rnd() * 100
Next J
Next I
'Matrice B
Dim K, L As Integer
For K = 0 To CInt(Range("D3").Value)
For L = 0 To CInt(Range("D4").Value)
ActiveCell.Offset(I + K + 2, L).Value = Rnd() * 100
Next L
Next K
'Matrice AXB
For J = 0 To CInt(Range("C3").Value)
For L = 0 To CInt(Range("D4").Value)
ActiveCell.Offset(I + K + 2, L).Value = ActiveCell.Offset(I, J).Value * ActiveCell.Offset(I + K + 2, L).Value
Next L
Next J
GoTo Error:
If J > K Then
Error:
MsgBox ("Les dimensions des deux matrices sont incompatible")
Exit Sub
End If |
Merci d'avance,
marco