View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
[email protected] wjg@gmail.com is offline
external usenet poster
 
Posts: 4
Default Matrix Operations in VBA

Rowan and Tom
Thank you very much for your help. I have been exploring this group
and I am finding a variety of implimintations using arrays of doubles,
declared variant arrays, and variants - some with Option Base 1 and
some with 0. I have Exl 2003 and I am looking for a consistent
practice for performing series of matrix manipulations in memory. Here
is my latest try:

Option Explicit
Option Base 1
Private Sub CommandButton2_Click()
Dim vMtxA, vMtxRHS, vMtxAInv, vMtxSol, vMtxT
Dim iRow As Integer, iCol As Integer
vMtxA = Range("A4:D7")
vMtxRHS = Range("F4:F7")
vMtxAInv = Application.WorksheetFunction.MInverse(vMtxA)
ReDim vMtxSol(UBound(vMtxA, 1))
For iRow = 1 To UBound(vMtxA, 1)
vMtxSol(iRow) = 0
For iCol = 1 To UBound(vMtxA, 2)
vMtxSol(iRow) = vMtxSol(iRow) + vMtxAInv(iRow, iCol) _
* vMtxRHS(iCol, 1)
Next iCol
Next iRow
vMtxT = Application.WorksheetFunction.Transpose(vMtxSol)
End Sub

Following is what I see in the Watch Window:

vMtxRHS(1,1) 125, vMtxRHS(2,1) 100, vMtxRHS(3,1) 195, vMtxRHS(4,1)
147 - which is correct but why 2-dimensional?

vMtxSol(1) 19, vMtxSol(2) 7, vMtxSol(3) 12, vMtxSol(4) 15 - which is
correct

vMtxT(1,1) 19, vMtxT(2,1) 7, vMtxT(3,1) 12, vMtxT(4,1) 15 - which
is not the transpose

It seems like when a single column Range is assigned to a variant, the
varient defaults to 2-dimensions with one column.
When the variant vMtxSol is dimensioned using RdDim it has one
dimension as expected.
The transpose didn't appear to work: the column vector remains a column
vector.
I am trying other configurations, but if you have one that is robust
and tested it would be helpful to know your recommendation