code: public void solve(double[] b, double[] x) {
          if (b.length != qr.nrows()) {
              throw new IllegalArgumentException(String.format("Row dimensions do not agree: A is %d x %d, but B is %d x 1", qr.nrows(), qr.nrows(), b.length));
          }
  
          if (x.length != qr.ncols()) {
              throw new IllegalArgumentException("A and x dimensions don't match.");
          }
  
          if (singular) {
              throw new RuntimeException("Matrix is rank deficient.");
          }
  
          double[] B = b.clone();
          solve(Matrix.newInstance(B));
          System.arraycopy(B, 0, x, 0, x.length);
      }
docs: Solve the least squares A*x = b.
  @param b   right hand side of linear system.
  @param x   the output solution vector that minimizes the L2 norm of A*x - b.
  @exception  RuntimeException if matrix is rank deficient.