C语言编程问题:用牛顿法求4cosX=e^X的根,要求精度达到0.0001.取Xo=π/4,在线等,急!
展开全部
//输入x0=π/4 i=100控制循环次数 和精度一起控制 如果循环100次仍然没有达到精度也可退出循环 弄得头疼阿 还复习了哈牛顿迭代法 祝你过关
#include "stdio.h"
#include "math.h"
main()
{
int i;
double x0,x1,x2;
printf("input x0=");
scanf("%lf",&x0);
x1 = x0;
x2 = x1 + (4 * cos(x1) - exp(x1)) / (4 * sin(x1) + exp(x1));
for(i = 0 ; fabs(x2 - x1) > 0.0001 && i < 100 ; i++)
{
x1 = x2;
x2 = x1 + (4 * cos(x1) - exp(x1)) / (4 * sin(x1) + exp(x1));
}
printf("4cosX=e^X的根=%lf\n",x2);
}
#include "stdio.h"
#include "math.h"
main()
{
int i;
double x0,x1,x2;
printf("input x0=");
scanf("%lf",&x0);
x1 = x0;
x2 = x1 + (4 * cos(x1) - exp(x1)) / (4 * sin(x1) + exp(x1));
for(i = 0 ; fabs(x2 - x1) > 0.0001 && i < 100 ; i++)
{
x1 = x2;
x2 = x1 + (4 * cos(x1) - exp(x1)) / (4 * sin(x1) + exp(x1));
}
printf("4cosX=e^X的根=%lf\n",x2);
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询