c语言编程-牛顿迭代法

c语言编程-牛顿迭代法
c语言编程-牛顿迭代法_第1张图片

#include 
#include 
double root(double (*f)(double),double (*f1)(double), double x,double eps);
double fx(double x)
{ 
return 2*x*x*x-4*x*x+3*x-6; 
}
double fp(double x)
{
return 6*x*x-8*x+3;
}
int main()
{
double x=1.5,y,eps=1e-08;
scanf("%lf",&eps);
y = root(fx,fp,x,eps);
printf("%lf\n",y);
return 0;
}
double root(double (*f)(double x),double (*f1)(double x), double x,double eps)
{
double x0,x1;
x0=x;
while(1)
{
x1= x0 - (*f)(x0)/ (*f1)(x0);
if (fabs(x1-x0)<eps) break;
x0=x1;
};
return x1;
}

你可能感兴趣的:(c语言编程-牛顿迭代法)