4. 使用牛顿迭代法求方程的解:
x^3-2x-5=0
区间为[2,3]
这里的"^"表示乘方。 

package chapter4;

public class demo4 {
    public static void main(String[] args) {
        double x=2;
        for(int i=0;i<20;i++) {
            x=-f(x)/f1(x)+x;
        }
        System.out.println(x+"");
    }
    
    static double f(double x) {
        double ans;
        ans=Math.pow(x, 3)-2*x-5;
        return ans;
    }
    
    static double f1(double x) {
        double ans;
        ans=3*Math.pow(x, 2)-2;
        return ans;
    }
}

 

相关文章:

  • 2022-12-23
  • 2021-08-27
  • 2021-06-18
  • 2022-12-23
  • 2021-07-24
  • 2021-10-10
猜你喜欢
  • 2021-11-13
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案