用牛顿迭代法求方程f(x)等于2x的3次方减去4x的平方加上3x减去7等于0 在x=2.5附近的实根,直到满足两个相邻两
1个回答

#include

#include

#define F(x) 2*x*x*x-4*x*x+3*x-7//The function

#define K(x) 6*x*x-8*x+3//The pitch

void main()

{

double x,xx,f,k;

x=2.5;

f=F(x);//Get the value

k=K(x);//Get the pitch value

xx=x-f/k;

while((fabs(x-xx))>(1*10e-6))//Check the answer

{

x=xx;

f=F(x);//Get the value

k=K(x);//Get the pitch value

xx=x-f/k;

}

printf("x=%2.8f,xx=%2.8fn",x,xx);

}

//该程序经过调试成功的