VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



Matrice multiplication

by Waty Thierry (60 Submissions)
Category: Math/Dates
Compatability: Visual Basic 4.0 (32-bit)
Difficulty: Unknown Difficulty
Originally Published: Tue 13th April 1999
Date Added: Mon 8th February 2021
Rating: (1 Votes)

Matrice multiplication

Rate Matrice multiplication



   
   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




Download this snippet    Add to My Saved Code

Matrice multiplication Comments

No comments have been posted about Matrice multiplication. Why not be the first to post a comment about Matrice multiplication.

Post your comment

Subject:
Message:
0/1000 characters