code: public void gaussianElimination(int[][] matrix) {
      assert(matrix != null && matrix.length > 0 && matrix[0].length > 0
             && matrix.length < matrix[0].length);
      int height = matrix.length;
      int width = matrix[0].length;
      for (int i = 0; i < height; i++) {
        boolean pivotFound = false;
        // scan the column for a nonzero pivot and swap it to the diagonal
        for (int j = i; j < height; j++) {
          if (matrix[i][j] != 0) {
            int[] tmp = matrix[i];
            matrix[i] = matrix[j];
            matrix[j] = tmp;
            pivotFound = true;
            break;
          }
        }
        if (!pivotFound) {
          continue;
        }
        int pivot = matrix[i][i];
        for (int j = i; j < width; j++) {
          matrix[i][j] = divide(matrix[i][j], pivot);
        }
        for (int j = i + 1; j < height; j++) {
          int lead = matrix[j][i];
          for (int k = i; k < width; k++) {
            matrix[j][k] = add(matrix[j][k], multiply(lead, matrix[i][k]));
          }
        }
      }
      for (int i = height - 1; i >=0; i--) {
        for (int j = 0; j < i; j++) {
          int lead = matrix[j][i];
          for (int k = i; k < width; k++) {
            matrix[j][k] = add(matrix[j][k], multiply(lead, matrix[i][k]));
          }
        }
      }
    }
docs: Perform Gaussian elimination on the given matrix. This matrix has to be a
  fat matrix (number of rows > number of columns).