用牛顿迭代法求下面方程在1.5附近的根:2x3-4x2+3x-6=0
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
double f(double x)
{
return 2 * x*x*x - 4 * x*x + 3 * x - 6;
}
double f1(double x)
{
return 6 * x*x - 8 * x + 3;
}
int main()
{
double x1;
double x = 1.5;
x1 = x - f(x) / f1(x);
while (fabs(x1 - x) > 0.00001)
{
x = x1;
x1 = x - f(x) / f1(x);
}
printf("%lf", x1);
system("pause");
return 0;
}
答案
用牛顿迭代法求下面方程在1.5附近的根:2x3-4x2+3x-6=0