Lab 2
Lab 2
SUBMITTED TO:
Md.Mostafijur Rahman
Lecturer
Department of CSE
Dhaka International University
SUBMITTED BY:
Name: Ali Azaz Rafe
Batch: 76th
Roll No : 49
Registration Code : CS-D-76-127609-CT
cout << "Maximum iterations reached. Approximate root: " << x2 << endl;
return x2;
}
int main() {
double x0 = 1.0; // Initial guess 1
double x1 = 2.0; // Initial guess 2
double tol = 1e-6; // Tolerance
int max_iter = 100; // Maximum iterations
// Halley's iteration
double denominator = 2 * df_x * df_x - f_x * d2f_x;
if (denominator == 0) {
cout << "Denominator is zero, stopping iteration." << endl;
break;
}
x = x_new;
}
int main() {
double initialGuess = 1.0; // Initial guess
double tolerance = 1e-7; // Tolerance for convergence
int maxIterations = 100; // Maximum number of iterations
cout << "Root found: " << fixed << setprecision(7) << root << endl;
return 0;
}
Result output :