Professional Documents
Culture Documents
#include <cmath>
double f(double x) {
return x*x - 4;
}
do {
x2 = x1 - ((fx1 * (x1 - x0)) / (fx1 - fx0));
fx2 = f(x2);
x0 = x1;
fx0 = fx1;
x1 = x2;
fx1 = fx2;
iter++;
} while (fabs(fx2) > tol && iter < 100);
if (iter == 100) {
cout << "Tidak konvergen setelah 100 iterasi." << endl;
return NAN;
}
return x2;
}
int main() {
double x0, x1, tol;
return 0;
}