当前位置:编程学习 > C/C++ >>

用牛顿迭代法求方程f(x)=x^6-x-1=0在区间【1,2】内的实根,要求|f(x(k))|<10^-8 用C语言编写此编程

答案:#include<stdio.h> #include<math.h> #define eps 1e-8 void main() { double a=1,b=2; double t,t0,f0,f00,m,n; t0=(a+b)/2; m=pow(t0,5); n=pow(t0,4); f0=6*m-1; f00=30*n; t=t0-f0/f00; while(fabs(t-t0)>eps) { t0=t; m=pow(t0,5); n=pow(t0,4); f0=6*m-1; f00=30*n; t=t0-f0/f00; printf("t0=%12.10lf,t=%12.10lf\n",t0,t); } printf("用Newton切线法得:%12.10lf\n",t); } 结果为: t0=1.2065843621,t=0.9809945654 t0=0.9809945654,t=0.8207881793 t0=0.8207881793,t=0.7300742137 t0=0.7300742137,t=0.7013898132 t0=0.7013898132,t=0.6988457773 t0=0.6988457773,t=0.6988271198 t0=0.6988271198,t=0.6988271188 用Newton切线法得:0.6988271188 Press any key to continue
其他:#define _CRT_SECURE_NO_WARNINGS
#include "stdio.h"
#include "math.h"
#define e0 1e-8

void main()
 {
 double x0,x1;
   x0=0;
 x1=1;
 do
    {
    x0=x1;
     x1=x0-(x^6-x-1)/(6*x^5-1);
    }
 while(fabs(x1-x0)>=e0);
 printf("方程的根是%f\n",x1);
  } //牛顿法的迭代序列:x(n+1)=x(n)-f(x(n))/f'(x(n))。
//f(x)=x^6-x-1;
//f'(x)=6*x^5-1;

#include<stdio.h>
#include <math.h>  
void main()
{  
 double x,x0,f,f1;  
 x0=1.5;
 while(1)
 {
  f=pow(x0,6)-x-1;
  f1=6*pow(x0,5)-1;
  x=x0-f/f1;
  if(fabs(x-x0)<1e-8) break;
  x0=x;
 }
 printf("x=%f\n",x);    //x=1.134724138
}

上一个:一道有点难度的C语言题目 帮帮小弟
下一个:C语言题目

CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,