我试图在一个子区间上输入一个 for 循环,该子区间在指定范围内形成另一个分区,以便计算给定多项式的根。我的问题是我的“if”和“if-else”没有被执行,即使条件应该确保它们的执行。我在程序的其他部分测试了我的“poly”函数,没有发现任何问题。这是我麻烦的for循环。
for (int i = L; i < R; i += resolution) {
double a = i, b = resolution+i;
{ if (poly(C, a)*poly(C, b) < 0) {
double mid = findRoot(C, a, b, tolerance);
System.out.println(mid);
if (Math.abs(poly(C, mid)) < threshold){
System.out.println("Root found at: "+mid);
numCount = 1;
}
} else if (poly(D, a)*poly(D, b) < 0) {
double mid = findRoot(D, a, b, tolerance);
if(Math.abs(poly(C, mid)) < threshold) {
System.out.println("Root found at: "+mid);
numCount = 2;
} else {
numCount = 3;
System.out.println("No roots were found in the specified range.");
} System.out.println("numCount is "+numCount); break;
}
}