fork download
  1. #include <iostream>
  2. #include <cmath>
  3. #include <iomanip>
  4.  
  5. using namespace std;
  6.  
  7. double f(double x) {
  8. return pow(x, 3) - x - 3;
  9. }
  10.  
  11. int main() {
  12. double x1, x2, x3, f1, f2;
  13. const double tolerance = 1e-6;
  14. const int max_iterations = 100;
  15. int iteration = 1;
  16.  
  17. cout << "x1 এর মান প্রবেশ করুন: ";
  18. cin >> x1;
  19. cout << "x2 এর মান প্রবেশ করুন: ";
  20. cin >> x2;
  21.  
  22. cout << fixed << setprecision(6);
  23. cout << "\nIteration\tx1\t\tx2\t\tx3\t\tf(x1)\t\tf(x2)\n";
  24.  
  25. while (iteration <= max_iterations) {
  26. f1 = f(x1);
  27. f2 = f(x2);
  28.  
  29. if (fabs(f2 - f1) < 1e-12) {
  30. cout << "বিভাজকের মান খুব ছোট। শূন্য দ্বারা বিভাজনের ঝুঁকি।\n";
  31. break;
  32. }
  33.  
  34. x3 = (f2 * x1 - f1 * x2) / (f2 - f1);
  35.  
  36. cout << iteration << "\t\t" << x1 << "\t" << x2 << "\t" << x3 << "\t" << f1 << "\t" << f2 << "\n";
  37.  
  38. if (fabs((x3 - x2) / x3) < tolerance) {
  39. cout << "\nআনুমানিক মূল = " << x3 << endl;
  40. break;
  41. }
  42.  
  43. x1 = x2;
  44. x2 = x3;
  45. iteration++;
  46. }
  47.  
  48. if (iteration > max_iterations) {
  49. cout << "সর্বাধিক পুনরাবৃত্তির মধ্যে পদ্ধতিটি সন্নিবেশিত হয়নি।\n";
  50. }
  51.  
  52. return 0;
  53. }
  54.  
Success #stdin #stdout 0.01s 5284KB
stdin
Enter the value of x1: 10
Enter the value of x2: 8
stdout
x1 এর মান প্রবেশ করুন: x2 এর মান প্রবেশ করুন: 
Iteration	x1		x2		x3		f(x1)		f(x2)
বিভাজকের মান খুব ছোট। শূন্য দ্বারা বিভাজনের ঝুঁকি।