Application.WorksheetFunction.MMult
Just to add. If you got a single answer of 49, you were most likely
selecting 1 cell and Array entering your equation. You need to select a 3*3
area and then Array enter your equation. I believe your vba function would
work if you did not make the function return a double. (it's an array).
Here is your equation that returns a 3*3 array. As the others mentioned,
it depends on if you are passing a horizontal or vertical array to the
function. If you want, you can test for that in your function.
Function Test(myVector) As Variant
With Application.WorksheetFunction
' If you want the Dot Product, include the next line
' myVector = .Transpose(myVector)
Test = .MMult(myVector, .Transpose(myVector))
End With
End Function
Sub TestIt()
Dim Answer
[A1] = 7
[A2] = 8
[A3] = 9
Answer = Test([A1:A3].Value)
End Sub
--
Dana DeLouis
Using Windows XP & Office XP
= = = = = = = = = = = = = = = = =
"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
|