class 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;
        }
    }

}