public void rsolve(final double[] b, final double[] x) {
    int i,j;
    double sum;
    if (sing) throw new IllegalArgumentException("attempting solve in a singular QR");
    for (i=n-1;i>=0;i--) {
      sum=b[i];
      for (j=i+1;j<n;j++) sum -= r[i][j]*x[j];
      x[i]=sum/r[i][i];
    }
  }