Can anyone provide me with an algorithm to multiply 2 matrices (If possible it needs to work with vectors too) for vb.net?
Printable View
Can anyone provide me with an algorithm to multiply 2 matrices (If possible it needs to work with vectors too) for vb.net?
Productrowcolumn = Sum[ Arowx * Bxcolumn ] for all values of x.
Where Product is the matrix product of matrices A, B
Note that for matrices, multiplication is not commutative: A*B seldom equals B*A
If you do not grok the above formula, the following is the formula for The element in row 2 column 3 of the product of A and B, assuming A and B are 4X4 matrices.
Product23 = A21* B13 + A22* B23 + A23* B3 3 + A24* B43
Superscripts represent rows and sub scripts represent colums.
Note that rectangular matrices can be multiplied.
If A is a 4X5 (4 rows & 5 columns), while B is a 5X4 (5 rows & 4 columns), the above general formula would work. The product would be a 4X4 matrix. For the element in row 2 column 3, the formula would be the following.
Product23 = A21* B13 + A22* B23 + A23* B3 3 + A24* B43 + A25* B53
The above uses tensor notation. For vectors, ordinary notation is usually used.
Product = A1* B1 + A2* B21 + A3* B3
Where Product is the scalar product of two 3D vectors: A & B.
Tensor notation is preferred for matrices because there is an obvious pattern to correct formulae, making it easy to find typo's
I know that already. Can anyone post vbcode to do it? (I was taught a while ago, and was dependant on a calculator to do it)
Brian728s: Post code for this? How much do you know about VB syntax and programming?
I do not use VB Net, but it cannot be that much different from VB 6.0
How about something like the following?Perhaps you need a good book (try one of Sam's) or a course. The above should be easy once you know the matrix multiply algorithm. I think you need more help than you can find here.VB Code:
Dim A(0 To 10, 0 To 10) As Double Dim B(0 To 10, 0 To 10) As Double Dim Product(0 To 10, 0 To 10) As Double Dim J As Integer Dim K As Integer Dim X As Integer For J = 0 To 10 For K = 0 To 10 Product(J, K) = A(J, X) * B(X, K) For X = 1 To 10 Product(J, K) = Product(J, K) + A(J, X) * B(X, K) Next X Next K Next J