Matrix multiplication of more than 73 X 73 entities in VBA
Dear Tom Ogilvy,
I multiplied 2x2 matrix with 2x2 matrix and the mymmult function worked
perfect.
BUT, i multiplied 13 x 15 matrix with 15 x 20 matrix.
formula written in the cell A1 of sheet 3 is given below. then
corresponding cells are selcted, pressed F2 followed with Ctrl + Shift
+ Enter
=MMULT(Sheet1!A1:O13,Sheet2!A1:T15) ------- Gives the result
=mymmult(Sheet1!A1:O13,Sheet2!A1:T15) -------- Gives an error #REF!
I also cross-checked by multiplying the matrices (13 x 15 with 15 x 20)
in the same sheet rather in sheet 1 and 2. Still the same error # REF!
exists.
Please help me in this aspect.
Thanks,
Thulasiram.
Tom Ogilvy wrote:
Yes it should.
--
Regards,
Tom Ogilvy
"Alan Beban" <unavailable wrote in message
...
Should the 3rd line be
If rngA.Columns.Count < rngB.Rows.Count Then ?
Alan Beban
Tom Ogilvy wrote:
Here would be the basic approach. You can add more error checking:
Function MyMMULT(rngA As Range, rngB As Range)
Dim ArrC() As Double
If rngA.Rows.Count < rngB.Columns.Count Then
MyMMULT = CVErr(xlErrRef)
Exit Function
End If
ReDim ArrC(1 To rngA.Rows.Count, 1 To rngB.Columns.Count)
For i = 1 To rngA.Rows.Count
For j = 1 To rngB.Columns.Count
For k = 1 To rngA.Columns.Count
ArrC(i, j) = ArrC(i, j) + rngA(i, k) * rngB(k, j)
Next k
Next j
Next i
MyMMULT = ArrC
End Function
|