C语言牛顿迭代法求方程根.pptVIP

  • 36
  • 0
  • 约小于1千字
  • 约 3页
  • 2019-12-02 发布于广东
  • 举报
例题 :编写用牛顿迭代法求方程根的函数。方程为 系数a,b,c,d由主函数输入。求x在1附近的一个实根。 求出根后,由主函数输出。牛顿迭代法的公式是: 设迭代到 时结束。 * #includestdio.h #includemath.h void main( ) { float solution(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(The solution is: x=%10.7f\n,solution(a,b,c,d)); } * float solution(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-5); return x; } * .

文档评论(0)

1亿VIP精品文档

相关文档