.已知f(x)=cos(x)-x,使用牛顿迭代法求解方程f(x)=0的近似解,要求精确到10-6。
#include<stdio.h>
#include <math.h>
double Newton(double x0,double e);
int main()
{
double x0=3.14159/4;
double e=1e-6;
cout<<Newton(x0,e)<<endl;
system("pause");
}
double Newton(double x0,double e)
{
double x1;
do
{
x1=x0;
x0=x1-(cos(x1)-x1)/(-sin(x1)-1);
}
while(fabs(x0-x1)>e);
return x0;
}
您好,我是有问必答小助手,您的问题已经有小伙伴帮您解答,感谢您对有问必答的支持与关注!