و اينم برا ضرب اش
#Region "Multiply Matrices"
'''''''''''''''''''''''''''''''''''''''''''''''''' '''''''''''''
' Multiply two matrices, their dimensions should be compatible!
' Function returns the solution or errors due to
' dimensions incompatibility
'''''''''''''''''''''''''''''''''''''''''''''''''' '''''''''''''
Public Shared Function Multiply(ByVal Mat1(,) As Double, ByVal Mat2(,) As Double) As Double(,)
Dim l, i, j As Integer
Dim OptiString As String
Dim sol(,) As Double, MulAdd As Double
Dim Rows1, Cols1 As Integer
Dim Rows2, Cols2 As Integer
On Error GoTo Error_Handler
MulAdd = 0
Find_R_C(Mat1, Rows1, Cols1)
Find_R_C(Mat2, Rows2, Cols2)
If Cols1 <> Rows2 Then
GoTo Error_Dimension
End If
ReDim sol(Rows1, Cols2)
For i = 0 To Rows1
For j = 0 To Cols2
For l = 0 To Cols1
MulAdd = MulAdd + Mat1(i, l) * Mat2(l, j)
Next l
sol(i, j) = MulAdd
MulAdd = 0
Next j
Next i
Return sol
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
#End Region