Matrix Operations in VBA
there are no built in Matrix/array handling functions in VBA. What you do
have is access to Excel worksheet functions such as you have shown and
Rowand has somewhat duplicated. Rowand might seem to imply that vMtxA must
be a range, but it can be an array as well (as you originally showed).
Sub abcd()
Dim vMtxA As Variant, vMtxB As Variant, vMtxC() As Variant
vMtxA = Range("B4:E7")
vMtxB = Application.MInverse(vMtxA)
Debug.Print LBound(vMtxB, 1), UBound(vMtxB, 1)
Debug.Print LBound(vMtxB, 2), UBound(vMtxB, 2)
For i = LBound(vMtxB, 1) To UBound(vMtxB, 1)
sStr = ""
For j = LBound(vMtxB, 2) To UBound(vMtxB, 2)
sStr = sStr & Format(vMtxB(i, j), "#,000") & ","
Next
Debug.Print sStr
Next
End Sub
works fine.
Array/matrix multiplication would need to be done element by element.
Assignment of arrays/matrices to variables requires a variant (or in xl2000
and later a variant array is also supported).
--
Regards,
Tom Ogilvy
" wrote in message
ups.com...
I would like to take the inverse of a matrix within my VBA code as part
of a sequence of operations. Something like the following:
Dim vMtxA As Variant, vMtxB As Variant, vMtxC() As Variant
vMtxA = Range("B4:E7")
vMtxB = Application.MInverse(vMtxA)
OR
ReDim vMtxC(4,4)
vMtxC = Application.MInverse(vMtxA)
I have not been able to find a way to do this. I would then multiply
the inverse by a RHS vector to get a solution vector that would be used
in subsequent calculations using MMult, etc. Also I have not figgured
out how to add two variant arrays??
vMtxD = vMtxA + vMtxB
|