I have been trying for hours to create a function that will find the dot product of two independent columns. I have very limited knowledge in VBA and my professor is no help. This is what I have right now, which is heavily based on what I learned in class. Does anybody have suggestions of what could be wrong or an easier way to execute this?
Function Dot(y As Range, x As Range) As Variant
Dim A() As Double
Dim i As Integer, n As Integer, nr As Integer, nc As Integer 'where the matrix dimensions of y are (i, n)
Dim j As Integer, m As Integer, ns As Integer, nd As Integer 'where the matrix dimensions of x are (j, m)
nr = y.Rows.Count
nc = y.Columns.Count
ns = x.Rows.Count
nd = x.Columns.Count
If nr <> ns Then
MsgBox ("vectors are not of same length")
Exit Function
End If
ReDim A(1 To 1, 1 To nc, 1 To 1, 1 To nd) As Double
For n = 1 To nc
For m = 1 To nd
A(1, n, 1, m) = 0
For i = 1 To 1
For j = 1 To 1
A(1, n, 1, m) = A(1, n, 1, m) + (y(i, n) * x(j, m))
Next j
Next i
Next m
Next n
Dot = A
End Function
Function Dot(y As Range, x As Range) As Variant
Dim A() As Double
Dim i As Integer, n As Integer, nr As Integer, nc As Integer 'where the matrix dimensions of y are (i, n)
Dim j As Integer, m As Integer, ns As Integer, nd As Integer 'where the matrix dimensions of x are (j, m)
nr = y.Rows.Count
nc = y.Columns.Count
ns = x.Rows.Count
nd = x.Columns.Count
If nr <> ns Then
MsgBox ("vectors are not of same length")
Exit Function
End If
ReDim A(1 To 1, 1 To nc, 1 To 1, 1 To nd) As Double
For n = 1 To nc
For m = 1 To nd
A(1, n, 1, m) = 0
For i = 1 To 1
For j = 1 To 1
A(1, n, 1, m) = A(1, n, 1, m) + (y(i, n) * x(j, m))
Next j
Next i
Next m
Next n
Dot = A
End Function