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
|
Public Shared Function Mult(ByVal Mat1(,) As Double, ByVal Mat2(,) As Double) As Double(,)
Dim Sum As Double = 0
Dim Rows1 As Integer, Cols1 As Integer
Dim Rows2 As Integer, Cols2 As Integer
On Error GoTo Error_Handler
Find_RC(Mat1, Rows1, Cols1)
Find_RC(Mat2, Rows2, Cols2)
If Cols1 <> Rows2 Then
GoTo Error_Dimension
End If
Dim Temp(Rows1, Cols2) As Double
For i As Integer = 0 To Rows1
For j As Integer = 0 To Cols2
For k As Integer = 0 To Cols1
Sum += Mat1(i, k) * Mat2(k, j)
Next k
Temp(i, j) = Sum
Sum = 0
Next j
Next i
Return Temp
Error_Dimension:
Err.Raise("5009", , "Dimensions of the two matrices not suitable for multiplication !")
Error_Handler:
If Err.Number = 5009 Then
Err.Raise("5009", , "Dimensions of the two matrices not suitable for multiplication !")
Else
Err.Raise("5022", , "One or both of the matrices are null, this operation cannot be done !!")
End If
End Function |
Partager