public static double determinant(Matrix matrix) {
        double sum = 0.0;
        int columns = matrix.getColumnDimension();
        int rows = matrix.getRowDimension();
        if (columns == 1) {
            return matrix.get(0, 0);
        }
        for (int i = 0; i < columns; ++i) {
            Matrix smaller = new Matrix(rows - 1, columns - 1);
            for (int a = 1; a < rows; ++a) {
                for (int b = 0; b < columns; ++b) {
                    if (b < i) {
                        smaller.set(a - 1, b, matrix.get(a, b));
                    } else if (b > i) {
                        smaller.set(a - 1, b - 1, matrix.get(a, b));
                    }
                }
            }
            sum += changeSign(i) * matrix.get(0, i) * (determinant(smaller));
        }
        return sum;
    }