用牛顿迭代法求方程f(x)=x^6-x-1=0在区间【1,2】内的实根,要求|f(x(k))|

问题描述:

用牛顿迭代法求方程f(x)=x^6-x-1=0在区间【1,2】内的实根,要求|f(x(k))|

#include
#include
#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