c语言二分法切割法牛顿法求根算法

c语言实现的二分法,切割法,牛顿法求根算法

//二分法
double fun(double m,double n)
{
     double r;int i=0;

     if (quest(m)*quest(n)>0)
            printf ("There are no roots in this area\n");

   while (fabs(n-m)>esp)
     {
            r=(m+n)/2;
            if (quest(r)*quest(n)<=0)
                   m=r;
            else
                   n=r;

           i++;

            printf("第%d次运算结果:\t%f\n",i,r);
     }

     printf("运算次数为 i=%d\n",i);
       return r;
}

//牛顿法
double niudunfa(double x)
{ 
     int i=0;
     double x1=x;
     do{
            if (f1(x)<esp) break;
            x=x1;
            x1=x-f(x)/f1(x);
            i++;
            printf("第%d次运算结果:\t%f\n",i,x1);
     }
     while(fabs(f(x1)-f(x))>esp);
     printf("运算次数为 i=%d\n",i);
     return (x1);
}

//切割法

double  qiegefa(double x0,double x1)
{
     double x;

     int i=0;
     while(fabs(x1-x0)>esp)
     {
            x=x1-f(x1)*(x1-x0)/(f(x1)-f(x0));
            x0=x1;
            x1=x;
            i++;
            printf("第%d次运算结果:\t%f\n",i,x1);
     }
     printf("运算次数为 i=%d\n",i);
         return (x1);
}

实例代码下载地址:http://download.csdn.net/detail/qq_24082497/9473238

你可能感兴趣的:(算法,C语言,二分法,牛顿法,切割法)