/** * Determines the number of real roots there are in the polynomial within the specified bounds. Must call * {@link #initialize(Polynomial)} first. * * @param lower lower limit on the bound. * @param upper Upper limit on the bound * @return Number of real roots */ public int countRealRoots( double lower , double upper ) { // There are no roots for constant equations if( sequenceLength <= 1 ) return 0; computeFunctions(lower); int numLow = countSignChanges(); computeFunctions(upper); int numHigh = countSignChanges(); return numLow-numHigh; }
/** * Determines the number of real roots there are in the polynomial within the specified bounds. Must call * {@link #initialize(Polynomial)} first. * * @param lower lower limit on the bound. * @param upper Upper limit on the bound * @return Number of real roots */ public int countRealRoots( double lower , double upper ) { // There are no roots for constant equations if( sequenceLength <= 1 ) return 0; computeFunctions(lower); int numLow = countSignChanges(); computeFunctions(upper); int numHigh = countSignChanges(); return numLow-numHigh; }
private void compareSequences( Polynomial p, double value) { List<Double> expected = computeSturm(p,value); SturmSequence alg = new SturmSequence(p.size); alg.initialize(p); alg.computeFunctions(value); assertEquals(expected.size(),alg.sequenceLength); for( int j = 0; j < expected.size(); j++ ) { if( Double.isInfinite(expected.get(j)) ) { assertTrue(expected.get(j) == alg.f[j]); } else { assertEquals(expected.get(j),alg.f[j],Math.abs(alg.f[j])*1e-6); } } }
/** * Check sequence against a hand selected sequence */ @Test public void checkSequence() { Polynomial poly = Polynomial.wrap(-1,0,3,1,5,-3); SturmSequence alg = new SturmSequence(10); alg.initialize(poly); alg.computeFunctions(-3); List<Double> expected = computeSturm(poly,-3); assertEquals(expected.size(),alg.sequenceLength); for( int i = 0; i < expected.size(); i++ ) { assertEquals(expected.get(i),alg.f[i],1e-8); } }