示例#1
0
 /**
  * Set a block in this matrix equal to the given matrix
  *
  * @param i the top row of the block
  * @param j the left most column of the block
  * @param matrix the values to set the block with
  */
 public void set(int i, int j, Matrix matrix) {
   for (int row = i; row < matrix.m() + i; row++) {
     for (int column = j; column < matrix.n() + j; column++) {
       set(row, column, matrix.get(row - i, column - j));
     }
   }
 }
示例#2
0
 /**
  * Subtract from this matrix in place
  *
  * @param matrix the matrix to subtract
  */
 public void minusEquals(Matrix matrix) {
   for (int i = 0; i < m(); i++) {
     for (int j = 0; j < n(); j++) {
       set(i, j, get(i, j) - matrix.get(i, j));
     }
   }
 }
示例#3
0
 /**
  * Subtract this matrix with another matrix
  *
  * @param matrix the other matrix
  * @return the resulting matrix
  */
 public Matrix minus(Matrix matrix) {
   double[][] result = new double[m()][n()];
   for (int i = 0; i < result.length; i++) {
     for (int j = 0; j < result[i].length; j++) {
       result[i][j] = get(i, j) - matrix.get(i, j);
     }
   }
   return new RectangularMatrix(result);
 }
示例#4
0
 /**
  * Multiply this matrix with another matrix
  *
  * @param matrix the other matrix
  * @return the resulting matrix
  */
 public Matrix times(Matrix matrix) {
   double[][] result = new double[m()][matrix.n()];
   for (int row = 0; row < result.length; row++) {
     for (int column = 0; column < result[0].length; column++) {
       for (int i = 0; i < n(); i++) {
         result[row][column] += get(row, i) * matrix.get(i, column);
       }
     }
   }
   return new RectangularMatrix(result);
 }