View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
Tom Ogilvy Tom Ogilvy is offline
external usenet poster
 
Posts: 27,285
Default Application.WorksheetFunction.MMult

It returns an array, not a double: in the case of {7,8,9}, an array with
one element.
(this is a US interpretaton of {7,8,9} which is a row array/vector)

Function Test(myVector) As Variant
Test = Application.MMult(myVector, _
Application.Transpose(myVector))

End Function
Sub Tester5()
Dim varr(1 To 1, 1 To 3) As Variant, varr1 As Variant, i As Long
varr(1, 1) = 7
varr(1, 2) = 8
varr(1, 3) = 9
Debug.Print TypeName(Test(varr)), LBound(varr), UBound(varr)
varr1 = Test(varr)
For i = LBound(varr1) To UBound(varr1)
Debug.Print i, varr1(i)
Next
End Sub

Results would be 194

if your vector were 7;8;9, then it would return a 3 x 3 array
(this is a US interpretation of 7;8;9 which is a column array/vector)

49, 56, 63
56, 64, 72
63, 72, 81

Sub Tester6()
Dim varr(1 To 3, 1 To 1) As Variant, varr1 As Variant
Dim j As Long, i As Long, sStr As String
varr(1, 1) = 7
varr(2, 1) = 8
varr(3, 1) = 9
Debug.Print TypeName(Test(varr)), LBound(varr), UBound(varr)
varr1 = Test(varr)
For i = LBound(varr1, 1) To UBound(varr1, 1)
For j = LBound(varr1, 2) To UBound(varr1, 2)
If j < UBound(varr1, 2) Then
sStr = sStr & varr1(i, j) & ", "
Else
sStr = sStr & varr1(i, j)
End If
Next
Debug.Print sStr
sStr = ""
Next
End Sub

--
Regards,
Tom Ogilvy

Gabriel wrote in message
m...
Hi,

I just want to write a quick function in VBA which performs the the
matrix multiplication of a vector with itself transposed.

In a worksheet the calcul would look like this
{=MMULT(myVector,TRANSPOSE(myVector))}. If myVector is for instance
7;8;9 then the result would simply be 49. However, when I call the
Test vba Function it just doesn't work:


Function Test(myVector) As Double

Test = Application.WorksheetFunction.MMult(MyVector, _
Application.WorksheetFunction.Transpose(MyVector))

End Function

Am I missing somethin here?
Thank you in advance
Gabriel