LeastSquaresDivision { public boolean divide(Polynomial num, Polynomial denom) { try { err_ = 0; DataBlock N = new DataBlock(num); DataBlock D = new DataBlock(denom); int n = N.getLength(), d = D.getLength(); if (d > n) { return false; } int q = n - d + 1; coeff = new double[q]; Matrix m = new Matrix(n, q); DataBlockIterator columns = m.columns(); DataBlock column = columns.getData(); int c = 0; do { column.range(c, c + d).copy(D); ++c; } while (columns.next()); Householder qr = new Householder(false); qr.decompose(m); DataBlock E = new DataBlock(d - 1); qr.leastSquares(N, new DataBlock(coeff), E); this.err_ = E.nrm2() / d; return true; } catch (MatrixException err) { return false; } }  boolean divide(Polynomial num, Polynomial denom); Polynomial getQuotient(); double getError(); boolean isExact(); static final double EPS; }
@Test public void testDivision() { int q=10, d=20; DataBlock Q=new DataBlock(q), D=new DataBlock(d); Q.randomize(0); D.randomize(1); Polynomial pq=Polynomial.copyOf(Q.getData()); Polynomial pd=Polynomial.copyOf(D.getData()); Polynomial pn=pd.times(pq); LeastSquaresDivision div=new LeastSquaresDivision(); div.divide(pn, pd); }