Hi

I've search the forums and I didn't find any code for multiplying matrix. So here the code to do so (and to make the transposee)

Ps.: errors are catch at a higher level

How it work:

Calling them with the two matrix, and it returns the result. Both calling matrix must be with 2 dimensions or else it fell.

The transposee only switch (i,j) position of the calling matrix

VB Code:
  1. ' effectue la matrice transposée
  2.  
  3. Private Function transposeMatrix(theMatrix() As Double) As Double()
  4. Dim i As Integer
  5. Dim j As Integer
  6. Dim matrixResult() As Double
  7. ' on redimensionne la matrix résultante au format précis
  8. ReDim matrixResult(UBound(theMatrix, 2), UBound(theMatrix, 1)) As Double
  9. For i = 0 To UBound(theMatrix, 1)
  10.    For j = 0 To UBound(theMatrix, 2)
  11.       matrixResult(j, i) = theMatrix(i, j)
  12.    Next j
  13. Next i
  14. transposeMatrix = matrixResult
  15. End Function
  16.  
  17. Private Function multiplyMatrix(firstMatrix() As Double, _
  18.                                 secondMatrix() As Double) As Double()
  19. Dim i As Integer
  20. Dim j As Integer
  21. Dim k As Integer
  22. Dim leTotal As Double
  23. Dim matrixResult() As Double
  24. ' on vérifie que les 2 matrices peuvent bien être multiplié
  25. If (UBound(firstMatrix, 2) <> UBound(secondMatrix, 1)) Then Exit Function
  26. ' on redimensionne la matrix résultante au format précis
  27. ReDim matrixResult(UBound(firstMatrix, 1), UBound(secondMatrix, 2)) As Double
  28.  
  29. For i = 0 To UBound(firstMatrix, 1)
  30.    For j = 0 To UBound(secondMatrix, 2)
  31.       leTotal = 0
  32.       For k = 0 To UBound(firstMatrix, 2) ' égal à UBound(Secondmatrix,1)
  33.          leTotal = leTotal + firstMatrix(i, k) * secondMatrix(k, j)
  34.       Next k
  35.       matrixResult(i, j) = leTotal
  36.    Next j
  37. Next i
  38. multiplyMatrix = matrixResult
  39. End Function

@+