/** * 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; }
@Test public void checkCount() { SturmSequence alg = new SturmSequence(10); alg.f = new double[]{0,1,1,-1,0,-1,-1,0,1,1}; alg.sequenceLength = alg.f.length; assertEquals(2,alg.countSignChanges()); alg.f = new double[]{1,1,1,-1,0,-1,-1,0,1,1,0,-1,-1,1}; alg.sequenceLength = alg.f.length; assertEquals(4,alg.countSignChanges()); }