【发布时间】:2010-11-04 14:15:04
【问题描述】:
以下代码搜索多项式函数的一个零点。它使用递归技术:
private static double funktion(int[] koef, double x){
return koef[0] * Math.pow(x,4) + koef[1] * Math.pow(x,3) +
koef[2] * Math.pow(x,2) + koef[3]*x + koef[4];
}
private static double nullstelle(double a, double b, int[] koef){
double middle = (a + b)/2;
double result = middle;
if(Math.abs(a-b) > 0.00001){
double sin = funktion(koef, middle);
if(sin == 0){
result = middle;
}else if(Math.signum(funktion(koef, a)) ==
Math.signum(funktion(koef, middle))){
result = nullstelle(middle, b, koef);
}else{
result = nullstelle(a, middle, koef);
}
}
return result;
}
我想知道如何返回所有零分。我的想法是使用数组,但我不知道该怎么做。有什么想法吗?
我不允许使用除数组以外的任何东西(例如,不允许使用哈希表或集合)
【问题讨论】:
-
数组是否需要排序?
-
好的。我在下面提供了对您有价值的步骤。