Matrixmultiplikation: Unterschied zwischen den Versionen
Aus DGL Wiki
Zeile 15: | Zeile 15: | ||
{Matrices can only be multiplicated, if the row count of the matrix#1 is the same | {Matrices can only be multiplicated, if the row count of the matrix#1 is the same | ||
as the column of the second matrix:} | as the column of the second matrix:} | ||
− | if High(sMatrix | + | if High(sMatrix) <> (High(Matrix[0])) then |
Exit; | Exit; | ||
{if a k*l matrix is multiplicated by a m*n matrix, | {if a k*l matrix is multiplicated by a m*n matrix, |
Version vom 8. April 2009, 09:54 Uhr
Zur Theorie der Matrixmultiplikation siehe den Matrix Artikel.
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;