c语言:用牛顿迭代法求方程在1.5附近的根:2x^3-4x^2+3x-6=0.

C语言:用牛顿迭代法求方程在1.5附近的根:2x^3 - 4x^2+3x-6=0.

牛顿迭代法:设f(x) =2x^3 - 4x^2+3x-6=0.,f1(x)为方程的导数,则f1(x) = 6x^2 - 8x+3,且f1(x)=(f(x0)-0)/(x0-x1),
推导得:x1 = x0 - f(x) / f1(x)

代码如下:

#include
#include
int main()
{
double x0,x1=1.5;
double f,f1;
do
{
x0 = x1;
f = 2*x0*x0*x0 - 4 * x0*x0 + 3 * x0 - 6;
f1 = 6 * x0*x0 - 8 * x0 + 3;
x1 = x0 - f / f1;
} while (fabs(x0 - x1) >= 1e-5);
printf("The root of equation is %f",x1);
return 0;
}

你可能感兴趣的:(C语言,-,4x^2+3,-,4x^2+3)