Matrixmultiplikation: Unterschied zwischen den Versionen
Aus DGL Wiki
Flash (Diskussion | Beiträge) (Emres Code) |
(kein Unterschied)
|
Version vom 7. Januar 2009, 13:22 Uhr
Emre lieferte im Forum diesen kleinen Codeschnipsel für die Matrixmultiplikation ab:
Type TSMatrix = Array of Array of Single; //sMatrix := sMatrix * Matrix procedure pSMatrixMatrixProduct( var sMatrix: TSMatrix; const Matrix: TSMatrix ); var m, n, o : Integer; Res : TSMatrix; begin {Matrices can only be multiplicated, if the row count of the matrix#1 is the same as the column of the second matrix:} if High(sMatrix) <> (High(Matrix[0])) then Exit; {if a k*l matrix is multiplicated by a m*n matrix, the result matrix will have a k*n dimension:} SetLength( Res, Length(sMatrix), Length(Matrix[0]) ); for m := 0 to High(Res) do for n := 0 to High(Res[m]) do for o := 0 to High(Matrix) do incS( Res[m,n], sMatrix[m,o]*Matrix[o,n] ); sMatrix := Res; end;