Matrix multiplication: Difference between revisions

Content added Content deleted
Line 669: Line 669:
===Using Objects===
===Using Objects===
<lang AutoHotkey>Multiply_Matrix(A,B){
<lang AutoHotkey>Multiply_Matrix(A,B){
if (A[1].MaxIndex() <> B.MaxIndex())
if (A[1].Count() <> B.Count())
return
return ["Dimension Error"]
RCols := A[1].MaxIndex()>B[1].MaxIndex()?A[1].MaxIndex():B[1].MaxIndex()
R := [], RRows := A.Count(), RCols:= b[1].Count()
RRows := A.MaxIndex()>B.MaxIndex()?A.MaxIndex():B.MaxIndex(), R := []
Loop, % RRows {
Loop, % RRows {
RRow:=A_Index
RRow:=A_Index
loop, % RCols {
loop, % RCols {
RCol:=A_Index, v := 0
RCol:=A_Index, v := 0
loop % A[1].MaxIndex()
loop % A[1].Count()
col := A_Index, v += A[RRow, col] * B[col,RCol]
col := A_Index, v += A[RRow, col] * B[col, RCol]
R[RRow,RCol] := v
R[RRow,RCol] := v
}
}