#include <math.h>
#include <iostream>
// f(x) = x + ln(x) - 1.56
double fun( double x )
{
return ( x + log( x ) - 1.56 );
}
double fun1( double x )//用于求导数
{
return ( 1 + 1/x );
}
using namespace std;
int main()
{
double x = 2.0, y1, y2, temp;
do
{
temp = x;
y1 = fun( x );
y2 = fun1( x );
x = temp - y1/y2;
}
while( fabs( x - temp ) >= 1e-4 ); //
判断是否满足要求
cout << "方程的解是: " << temp << endl;
return 0;
}
运行结果:
方程的解是 : 1.29866