/** * 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)); } } }
/** * 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); }