用牛顿迭代法求方程的根。方程为ax3+bx2+cx+d=0 c语言

2016-06-18 07:49:26  分类: c程序设计第四版谭浩强课后答案  参与:

 用牛顿迭代法求根。方程为ax3+bx2+cx+d=0  系数a,b,c,d的值依次为1,2,3,4,  由主函数输入。求x在1附近的一个实根。求出根后由主函数输出。

【c源程序】
#include <stdio.h>
#include <math.h>
int main()
{float solut(float a,float b,float c,float d);
 float a,b,c,d;
 printf("input a,b,c,d:");
 scanf("%f,%f,%f,%f",&a,&b,&c,&d);
 printf("x=%10.7f\n",solut(a,b,c,d));
 return 0;
}

float solut(float a,float b,float c,float d)
{float x=1,x0,f,f1;
 do
   {x0=x;
    f=((a*x0+b)*x0+c)*x0+d;
    f1=(3*a*x0+2*b)*x0+c;
    x=x0-f/f1;
   }
 while(fabs(x-x0)>=1e-3);
 return(x);
}


来源:c程序设计第四版谭浩强课后答案

本文链接:http://www.wb98.com/c/post/tanhaoqiang_7.12.html

本站文章搜索:

<< 上一篇下一篇 >>

搜索

网站分类

Tags列表

赞助商链接