#include <stdio.h>
#include <math.h>
#include <stdlib.h>
double N(double,double);
int main()
{
double x0 = 4.6;
double e = 0.000001;
printf("最小正根=%f\n",N(x0,e));
system("pause");
return 0;
}
double F1(double x)//原函数
{
return x-tan(x);
}
double F2(double x)//原函数的一阶导数函数
{
return (1-(1/pow(cos(x),2)));
}
double N(double x0)
{
int i=0;
double x1;
while (fabs(x1 - x0) > 0.000001)
{
x1 = x0;
x0 = x1 - F1(x1) / F2(x1);
i++;
}
printf("迭代次数=%d\n",i);
return x0;
}