编写一个程序,在此程序中,使用和弦算法找到方程f(x)= 0的近似解,同时构造了该算法的应用说明。
public class MetodHord1 {
public static void main(String[] args) {
double x0 = 2;
double x1 = 10;
double e = 0.001;
double x = method_chord(x0, x1, e);
System.out.println(x);
}
public static double method_chord (double x_prev, double x_curr, double e) {
double x_next = 0;
double tmp;
do{
tmp = x_next;
x_next = x_curr - f(x_curr) * (x_prev - x_curr) / (f(x_prev) - f(x_curr));
x_prev = x_curr;
x_curr = tmp;
} while (Math.abs(x_next - x_curr) > e);
return x_next;
}
public static double f (double x){
return Math.pow(x, 3) - 10 * x - 13;
}