RationalFunction { public RationalFunction drop(final int n) { Polynomial cn = m_pn, cd = m_pd; int p = cd.getDegree() + 1; int q = p; if (cn.getDegree() + 1 - n > q) { q = cn.getDegree() + 1 - n; } if (q == 0) { return new RationalFunction(); } double[] phi = new double[q]; double[] ntmp = new double[q]; for (int i = 0; i < q; ++i) { phi[i] = get(i + n); } ntmp[0] = phi[0] * cd.get(0); for (int i = 1; i < q; ++i) { double s = 0; int imax = i < q ? i : q - 1; for (int j = 0; j <= imax; ++j) { int k = i - j; if (k < p) { s += cd.get(k) * phi[j]; } } if (Math.abs(s) < EPSILON) { s = 0; } ntmp[i] = s; } int qc = q; while ((qc > 0) && (ntmp[qc - 1] == 0)) { --qc; } if (qc == 0) return new RationalFunction(); if (qc != q) { double[] ntmp2 = new double[qc]; for (int i = 0; i < qc; ++i) { ntmp2[i] = ntmp[i]; } ntmp = ntmp2; } return new RationalFunction(Polynomial.of(ntmp), cd); } RationalFunction();  RationalFunction(final Polynomial pn, final Polynomial pd); double[] coefficients(final int n); RationalFunction divide(final RationalFunction r2); RationalFunction drop(final int n); Complex evaluateAt(final Complex c); double evaluateAt(final double x); double get(final int k); Polynomial getDenominator(); Polynomial getNumerator(); boolean isFinite(); RationalFunction minus(final RationalFunction r2); RationalFunction plus(final RationalFunction r2); Complex[] poles(); Complex[] poles(final IRootsSolver searcher); void prepare(int degree); Complex[] roots(); Complex[] roots(final IRootsSolver searcher); RationalFunction times(final RationalFunction r2); @Override String toString(); static final double EPSILON; }
@Test public void testDrop() { Polynomial n=Polynomial.valueOf(1,-.2,-.3), d=Polynomial.valueOf(1,-1.8,1); RationalFunction fn=new RationalFunction(n, d); RationalFunction fn2=fn.drop(10); for (int i=0; i<50; ++i){ assertTrue(Math.abs(fn.get(i+10)-fn2.get(i))<1e-9); } }