public void add(double a, Matrix B) throws MatricksException { if (B.numRows() != this.numRows() && B.numCols() != this.numCols()) { throw new MatricksException("incompatible size for addition"); } MatrixCursor cursor = B.cursor(); while (cursor.next()) { final int row = cursor.row(); final int col = cursor.col(); double v = a * cursor.val() + this.get(row, col); this.set(row, col, v); } }