Пример #1
0
 /* (non-Javadoc)
  * @see rationals.algebra.SemiRing#plus(rationals.algebra.SemiRing)
  */
 public SemiRing plus(SemiRing s2) {
   if (s2 == null) throw new IllegalArgumentException("Null argument");
   Matrix o = (Matrix) s2; // maybe ClassCastException
   if (col != o.col || line != o.line)
     throw new IllegalArgumentException(
         "Incompatible matrices dimensions : cannot add non square matrices");
   int l = line;
   int c = col;
   Matrix res = Matrix.zero(l, c, matrix[0][0]);
   for (int i = 0; i < l; i++)
     for (int j = 0; j < c; j++) res.matrix[i][j] = matrix[i][j].plus(o.matrix[i][j]);
   return res;
 }
Пример #2
0
 /* (non-Javadoc)
  * @see rationals.algebra.SemiRing#mult(rationals.algebra.SemiRing)
  */
 public SemiRing mult(SemiRing s2) {
   if (s2 == null) throw new IllegalArgumentException("Null argument");
   Matrix o = (Matrix) s2; // maybe ClassCastException
   if (col != o.line) throw new IllegalArgumentException("Incompatible matrices dimensions");
   int l = line; // lines
   int c = o.col; // cols
   int m = col;
   Matrix res = Matrix.zero(l, c, matrix[0][0]);
   for (int i = 0; i < l; i++) {
     for (int j = 0; j < c; j++)
       for (int k = 0; k < m; k++) {
         if (k == 0) res.matrix[i][j] = matrix[i][k].mult(o.matrix[k][j]);
         else res.matrix[i][j] = res.matrix[i][j].plus(matrix[i][k].mult(o.matrix[k][j]));
       }
   }
   return res;
 }