用牛顿迭代法求方程f(x)=x^6-x-1=0在区间【1,2】内的实根,要求|f(x(k))|<10^-8 用C语言编写此编程
3个回答
展开全部
#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
#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
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
2011-05-20
展开全部
//牛顿法的迭代序列: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
}
//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
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
#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);
}
#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);
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询