编写程序,用牛顿迭代法求方程f(x)= x^3+4x^2-8=0

2025-01-07 20:16:42
推荐回答(1个)
回答1:

#include
#include

int main()
{
double x1 = 1, x2;
do {
x2 = x1;
x1 = x2 - (x1*x1*x1 + 4*x1*x1 - 8) / (2*x1*x1 + 8*x1);
} while(fabs(x1-x2) > 1e-4);
printf("%f", x1);
}