public Matrix submatrix(int i, int j, int k, int l) {
        if (i < 0 || i >= m || k < i || k >= m || j < 0 || j >= n || l < j || l >= n) {
            throw new IllegalArgumentException(String.format("Invalid submatrix range (%d:%d, %d:%d) of %d x %d", i, k, j, l, m, n));
        }

        Matrix sub = new Matrix(k - i + 1, l - j + 1);
        for (int jj = j; jj <= l; jj++) {
            for (int ii = i; ii <= k; ii++) {
                sub.set(ii - i, jj - j, get(ii, jj));
            }
        }

        return sub;
    }
@Test
    public void testSubmatrix() {
        Matrix sub = matrix.submatrix(0, 1, 2, 2);
        assertEquals(3, sub.nrow());
        assertEquals(2, sub.ncol());
        assertEquals(0.4f, sub.get(0,0), 1E-6f);
        assertEquals(0.8f, sub.get(2,1), 1E-6f);

        Matrix sub2 = sub.submatrix(0, 0, 1, 1);
        assertEquals(2, sub2.nrow());
        assertEquals(2, sub2.ncol());
        assertEquals(0.4f, sub.get(0,0), 1E-6f);
        assertEquals(0.3f, sub.get(1,1), 1E-6f);
    }