Matrice multiplication
Matrice multiplication
Rate Matrice multiplication
(2(2 Vote))
Dim a(2, 3) As Double
Dim b(3, 2) As Double
Dim c(2, 2) As Double
a(1, 1) = 1
a(1, 2) = 3
a(2, 1) = 5
a(2, 2) = 2
b(1, 1) = 3
b(1, 2) = 4
b(2, 1) = 1
b(2, 2) = 1
Call MatrixMult(a, b, 2, 2, 2, 2, c)
Print c(1, 1)
Print c(1, 2)
Print c(2, 1)
Print c(2, 2)
End Sub
Public Function MatrixMult(aMatrix1() As Double, aMatrix2() As Double, _
iWidth1 As Integer, iHeight1 As Integer, iWidth2 As Integer, iHeight2 As Integer, _
aResult() As Double)
' aMatrix1 and aMatrix2 are the ones being multiplied
'Width's and heights are given
'output in aresult
Dim x1 As Integer, x2 As Integer, x3 As Integer
Dim aRowtotal As Double
If iWidth1 <> iHeight2 Then MsgBox "can't do that": Exit Function
For x1 = 1 To iHeight1
For x2 = 1 To iWidth2
aRowtotal = 0
For x3 = 1 To iWidth1
aRowtotal = aRowtotal + aMatrix1(x1, x3) * aMatrix2(x3, x2)
Next
aResult(x2, x1) = aRowtotal
Next
Next
End Function
Matrice multiplication Comments
No comments yet — be the first to post one!
Post a Comment