You are on page 1of 1

#include<iostream>

#include<cmath>

using namespace std;

double f(double x) {

return x*pow(2.718, x)-1;


}

double df(double x) {

return pow(2.718, x)*(x+1);


}

int main() {
double y, eps;
int n;
cout << "Enter an initial approximation: ";
cin >> y;
cout << "Enter the maximum number of iterations: ";
cin >> n;
cout << "Enter the error tolerance: ";
cin >> eps;

for (int i = 0; i < n; i++) {


double x_new = y - f(y) / df(y);
if (fabs(x_new - y) < eps) {
cout << "A simple root is: " << x_new << endl;
return 0;
}
y = x_new;
}

cout << "No simple root found." << endl;


return 0;
}

You might also like