Matrixmultiplikation: Unterschied zwischen den Versionen

Aus DGL Wiki
Wechseln zu: Navigation, Suche
K (Theorie verlinkt)
K (Der Ausdruck ''<pascal>(.*?)</pascal>'' wurde ersetzt mit ''<source lang="pascal">$1</source>''.)
Zeile 2: Zeile 2:
  
 
Emre lieferte im Forum diesen kleinen Codeschnipsel für die Matrixmultiplikation ab:
 
Emre lieferte im Forum diesen kleinen Codeschnipsel für die Matrixmultiplikation ab:
<pascal>
+
<source lang="pascal">
 
Type
 
Type
 
   TSMatrix = Array of Array of Single;
 
   TSMatrix = Array of Array of Single;
Zeile 26: Zeile 26:
 
   sMatrix := Res;
 
   sMatrix := Res;
 
end;  
 
end;  
</pascal>
+
</source>

Version vom 10. März 2009, 20:06 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;