I am trying to multiply arrays as quickly as I can. There will be very large arrays, multiplied a lot of times. I have the below code which uses a nested loop, is there any faster way of doing this? I have array a() and b(), and I want to make sum(1) = a(1)*b(1) + a(1)*b(2) + a(1)*b(3) etc..
Currently I am in Excel VBA but I will be converting to VBA.NET soon. How much faster should this be than running it in excel vba? Are there faster methods in .Net that I could use?
Sub Test()
' Just creating the arrays
Dim a() as Integer, b() as Integer, sum() as Integer, i as Integer, j as Integer
ReDim a(1 to 3)
ReDim b(1 to 3)
ReDim sum(1 to 3)
For i = 1 to 3
a(i) = 2 * i
b(i) = 3 * i
Next i
' This is my code I am interested in
For i = 1 to 3
For j = 1 to 3
sum(i) = sum(i) + a(i) * b(j)
Next j
Next i
sumseems to add up the rows of an outer product, and not matrix multiplication in the standard form. Standard matrix multiplication requires three loops with each element a sums(i,j) = SUM(a(i,k)*b(k,j),k=1..n)sum(i)initialized? You are using un-initialized variables..NETis 10× ofVBAwith math.