![图片[1]-牛顿迭代法求根](http://8cltw.oss-cn-hongkong.aliyuncs.com/wp-content/uploads/2024/05/20240509223333289-1024x561.png)
#include <stdio.h>
#include <math.h>
float solut(float a, float b, float c, float d)
{
float x = 1, x0, f, f1;
do//开始迭代
{
x0 = x;
f = ((a * x0 + b) * x0 + c) * x0 + d;
f1 = (3 * a * x0 + 2 * b) * x0 + c;
x = x0 - f / f1;
}
while (fabs(x - x0) >= 1e-5);
return x;
}
int main()
{
float a, b, c, d;
printf("\n输入方程的系数a、b、c、d:\n");
scanf("%f,%f,%f,%f", &a, &b, &c, &d);
printf("\n方程是:%5.2fx^3+%5.2fx^2+%5.2fx+%5.2f=0", a, b, c, d);
printf("\nX=%10.7f\n", solut(a, b, c, d));
return 0;
}
© 版权声明
文章版权归作者所有,未经允许请勿转载。
THE END
暂无评论内容