Matrixmultiplikation

Für die Klasse Matrix kann nun eine Multiplikation von Matrizen von EoField Objekten definiert werden:

/* a[nxp] * n[pxm] = c[nxm] */
    public static Matrix multiply(Matrix left, Matrix right) {
   int n = left.getRows();
   int m = right.getColumns();
   int p = left.getColumns();

   Matrix result = new Matrix(n, m);
   for (int i = 0; i < n; i++) {
       for (int j = 0; j < m; j++) {
      // c[i][j] = a[i][0]*b[0][j] + a[i][1] * b[1][j] ...
      EoField tmp = (((EoField) left.getValue(i, 0)).multiply((EoField) right.getValue(0, j)));
      for (int k = 1; k < p; k++) {
          tmp = tmp.add(((EoField) left.getValue(i, k)).multiply((EoField) right.getValue(k, j)));
      }
      result.setValue(i, j, tmp);
       }
   }
   return result;
    }

-- ChristopherHuhn - 12 Dec 2003
Topic revision: r1 - 2003-12-12, ChristopherHuhn - This page was cached on 2022-01-24 - 12:35.

This site is powered by FoswikiCopyright © by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding GSI Wiki? Send feedback | Legal notice | Privacy Policy (german)