1 #include<stdio.h>
 2 #include<math.h>
 3 
 4 float lmd=2;
 5 
 6 float fa(float x)
 7 {
 8     return x-lmd*(x*x*x-3*x-1)/(3*x*x-3);
 9 }
10 
11 main()
12 {
13     float x0,x1,x2,eps;
14     int count=0;
15     printf("请输入迭代初值:\n");
16     scanf("%f",&x1);
17     printf("请输入精度:\n");
18     scanf("%f",&eps);
19     do
20     {
21         lmd/=2;
22         x2=fa(x1);
23     }while(fabs(fa(x2))>=fabs(fa(x1)));
24     do
25     {
26         x0=x1;
27         x1=fa(x0);
28         count++;
29     }while(fabs(x1-x0)>eps);
30     printf("x*=%f\n",x1);
31     printf("迭代次数:%d\n",count);
32 }
牛顿下山法

相关文章:

  • 2021-12-19
  • 2022-01-30
  • 2021-12-29
  • 2022-02-08
  • 2021-06-13
  • 2021-12-30
  • 2021-07-09
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-07-21
  • 2022-12-23
  • 2021-12-05
  • 2022-01-14
  • 2021-06-29
相关资源
相似解决方案